14.2 Core
(require pollen/core) | package: pollen |
These functions are automatically imported into every Pollen source file (meaning, as if they had been included in your "pollen.rkt").
14.2.1 Syntactic forms
syntax
(define-meta name value)
You can retrieve a meta value — even in the same document where you define it — with (select-from-metas name metas).
For an introduction to metas, see Inserting metas.
syntax
(@ arg ...)
> (module splicer pollen/markup '(div "one" (@ "two" "three") "four"))
> (require 'splicer)
> doc '(root (div "one" "two" "three" "four"))
syntax
(when/splice condition pollen-args)
◊when/splice[condition]{The text to insert.} |
The inserted text can contain its own nested Pollen commands.
when/splice can be more convenient than when, because when will only use the last argument between the curly braces. when/splice, by contrast, treats everything between the curly braces as a block.
14.2.2 Data helpers
Functions for retrieving data out of Pollen source files. These are not the only options – you can, of course, use any of the usual Racket functions.
If doc-source is a relative path or pagenode, it is treated as being relative to current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
If setup:main-export has been overridden with a project-specific value, then that is retrieved instead.
If meta-source is a relative path or pagenode, it is treated as being relative to current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
If setup:meta-export has been overridden with a project-specific value, then that is retrieved instead.
procedure
key : symbolish? value-source : (or/c hash? txexpr? pagenode? pathish?)
procedure
key : symbolish? value-source : (or/c hash? txexpr? pagenode? pathish?)
With select, you get the first result; with select*, you get them all.
In both cases, you get #f if there are no matches.
Note that if value-source is a relative path or pagenode, it is treated as being relative to current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
> (module nut-butters pollen/markup '(div (question "Flavor?") (answer "Cashew") (answer "Almond")))
; Import doc from 'nut-butters submodule > (require 'nut-butters)
> (select 'question doc) "Flavor?"
> (select 'answer doc) "Cashew"
> (select* 'answer doc) '("Cashew" "Almond")
> (select 'nonexistent-key doc) #f
> (select* 'nonexistent-key doc) #f
procedure
(select-from-doc key doc-source) → (or/c #f (listof xexpr?))
key : symbolish? doc-source : (or/c txexpr? pagenodeish? pathish?)
Note that if doc-source is a relative path or pagenode, it is treated as being relative to current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
> (module gelato pollen/markup '(div (question "Flavor?") (answer "Nocciola") (answer "Pistachio")))
; Import doc from 'gelato submodule > (require 'gelato)
> (select-from-doc 'question doc) '("Flavor?")
> ('answer . select-from-doc . doc) '("Nocciola" "Pistachio")
> (select-from-doc 'nonexistent-key doc) #f
procedure
(select-from-metas key meta-source) → (or/c #f xexpr?)
key : symbolish? meta-source : (or/c hash? pagenodeish? pathish?)
Note that if meta-source is a relative path or pagenode, it is treated as being relative to current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
> (define metas (hash 'template "sub.xml.pp" 'target "print"))
> (select-from-metas 'template metas) "sub.xml.pp"
> ('target . select-from-metas . metas) "print"
> (select-from-metas 'nonexistent-key metas) #f