Comments (4)
Hi!
I have a list of hashes called
hash_list
.
Note that the code that you wrote has missing parens, and is not a list of hashes. The list of hashes probably should be:
'(#hasheq((video . "path/to/example_0000.mp4"))
#hasheq((video . "path/to/example_0001.mp4")))
Here's my attempt:
There are two possible mistakes here.
-
Notice that in the output, you have
(video [[src ("path/to/example_0000.mp4")]])
. This doesn't make sense, because the attributesrc
should be associated with a string value, not a list of strings.The fix could be done by changing
video-env
to consume exactly one argument instead of making it consume variadic arguments. That is, you would need to make a definition like this instead:(define (video-env text) `(video [[src ,text]]))
(Notice the absence of dot. Also, people usually use
-
instead of_
in names) -
Notice that in the output, you have
((video ...) (video ...))
. This again doesn't make sense, because the body of the document should not be a list of elements. There are several ways to fix this. One possibility is:(apply @ (map .......))
So, your final code might look like this:
;; test.html.pm
#lang pollen
◊(define hash-list
'(#hasheq((video . "path/to/example_0000.mp4"))
#hasheq((video . "path/to/example_0001.mp4"))))
◊(define (video-env text)
`(video [[src ,text]]))
◊(define (root . xs)
(apply @ (map (λ (hash) (video-env (hash-ref hash 'video))) hash-list)))
which produces test.html
after raco pollen render test.html.pm
<html>
<head><meta charset="UTF-8"/></head>
<body>
<video src="path/to/example_0000.mp4"></video>
<video src="path/to/example_0001.mp4"></video>
</body>
</html>
from pollen-users.
@sorawee That did the trick! Thank you so much for pointing out both errors and putting me on the right path. I'm beaming 😄
I dropped some parens in the hash lists when I wrote the question. Whoops!
from pollen-users.
FWIW:
- you can avoid using hash tables if you only have one value per record (and just use a flat list).
- you can avoid defining a tag function if you just want the behavior of
default-tag-function
. - you can avoid using the splicing tag
@
explicitly and instead usefor/splice
(which gathers the results of the iteration under a@
automatically)
So if you wished, you could simplify this example like so:
;; test2.html.pm
#lang pollen
◊(define videos
'("path/to/example_0000.mp4"
"path/to/example_0001.mp4"))
◊(for/splice ([v videos])
(video #:src v))
from pollen-users.
@mbutterick My hash table comes from parsing a .json
with multiple values per record, which isn't obvious from my oversimplified example. Sorry about that. But your points on default-tag-function
and for/splice
are taken! And thanks for giving an example, I appreciate it.
from pollen-users.
Related Issues (20)
- render index.ptree with subdirectories changes directory (though not project root) HOT 8
- Is parallel mode known to crash a lot? HOT 1
- decode-elements with decode-paragraphs inserts spurious <p> when nesting lists? HOT 2
- multiple text arguments? HOT 5
- serialising txexprs? HOT 2
- Beautiful Racket Racket docs HOT 1
- Classic tangle/weave support a la org/babel-mode HOT 2
- Add source tag to default block-tags HOT 3
- Importing text from other sources HOT 2
- One source file → multiple outputs of same type? HOT 6
- Metadata on pagenodes (?) / how to render link traversal HOT 5
- Filling templates multiple times, à la mail-merge -- maybe a non-use case? HOT 3
- Inserting html comment with pollen command HOT 4
- splitf-txexpr: how to use the resulting txexpr HOT 2
- Windows: Set Pollen environment variable HOT 2
- execute shell command via preprocessor?
- Mildy Dynamic Websites
- opinions sought: costs & benefits of switching to self-hosted Git server? HOT 17
- Could not find MANIFEST for package source HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pollen-users.