diff --git a/doc/Template.html b/doc/Template.html index 1de8157..a319108 100644 --- a/doc/Template.html +++ b/doc/Template.html @@ -1,2 +1,2 @@ -9.6 Template
Module reference
9.1 Cache
9.2 Decode
9.3 File
9.4 Pagetree
9.5 Render
9.6 Template
9.7 Tag
9.8 Top
9.9 World
On this page:
->html
select
select*
select-from-metas
select-from-doc
6.0.1.11

9.6 Template

 (require pollen/template) package: pollen

Convenience functions for templates. These are automatically imported into the eval environment when rendering with a template (see render).

This module also provides everything from sugar/coerce/value.

procedure

(->html xexpr    
  [#:tag html-tag    
  #:attrs html-attrs    
  #:splice splice-html?])  string?
  xexpr : xexpr?
  html-tag : (or/c #f txexpr-tag?) = #f
  html-attrs : (or/c #f txexpr-attrs?) = #f
  splice-html? : boolean? = #f
Convert xexpr to an HTML string. Similar to xexpr->string, but consistent with the HTML spec, text that appears within script or style blocks will not be escaped.

Examples:

> (define tx '(root (script "3 > 2") "Why is 3 > 2?"))
> (xexpr->string tx)

"<root><script>3 &gt; 2</script>Why is 3 &gt; 2?</root>"

> (->html tx)

"<root><script>3 > 2</script>Why is 3 &gt; 2?</root>"

The optional keyword arguments html-tag and html-attrs let you set the outer tag and attributes for the generated HTML. If xexpr already has an outer tag or attributes, they will be replaced.

Examples:

> (define tx '(root ((id "huff")) "Bunk beds"))
> (->html tx)

"<root id=\"huff\">Bunk beds</root>"

> (->html tx #:tag 'div)

"<div id=\"huff\">Bunk beds</div>"

> (->html tx #:attrs '((id "doback")))

"<root id=\"doback\">Bunk beds</root>"

> (->html tx #:tag 'div #:attrs '((id "doback")))

"<div id=\"doback\">Bunk beds</div>"

Whereas if xexpr has no tag or attributes, they will be added. If you supply attributes without a tag, you’ll get an error.

Examples:

> (define x "Drum kit")
> (->html x)

"Drum kit"

> (->html x #:tag 'div)

"<div>Drum kit</div>"

> (->html x #:tag 'div #:attrs '((id "doback")))

"<div id=\"doback\">Drum kit</div>"

> (->html x #:attrs '((id "doback")))

->html: can't use attribute list '((id doback)) without a

#:tag argument

If the generated HTML has an outer tag, the splice-html? option will strip it off. Otherwise this option has no effect.

Examples:

> (define tx '(root (p "Chicken nuggets")))
> (->html tx)

"<root><p>Chicken nuggets</p></root>"

> (->html tx #:splice #t)

"<p>Chicken nuggets</p>"

> (define x "Fancy sauce")
> (->html x)

"Fancy sauce"

; This next one won't do anything
> (->html x #:splice #t)

"Fancy sauce"

; Adds the outer tag, but then #:splice removes it
> (->html x #:tag 'div #:attrs '((id "doback")) #:splice #t)

"Fancy sauce"

Be careful not to pass existing HTML strings into this function, because the angle brackets will be escaped. Fine if that’s what you want, but you probably don’t.

Examples:

> (define tx '(p "You did" (em "what?")))
> (->html tx)

"<p>You did<em>what?</em></p>"

> (->html (->html tx))

"&lt;p&gt;You did&lt;em&gt;what?&lt;/em&gt;&lt;/p&gt;"

procedure

(select key value-source)  (or/c #f txexpr-element?)

  key : symbolish?
  value-source : (or/c hash? txexpr? pagenode? pathish?)

procedure

(select* key value-source)  (or/c #f (listof txexpr-element?))

  key : symbolish?
  value-source : (or/c hash? txexpr? pagenode? pathish?)
Find matches for key in value-source, first by looking in its metas (using select-from-metas) and then by looking in its doc (using select-from-doc). With select, you get the first result; with select*, you get them all. In both cases, you get #f if there are no matches.

procedure

(select-from-metas key meta-source)  (or/c #f txexpr-element?)

  key : symbolish?
  meta-source : (or/c hash? pagenodeish? pathish?)
Look up the value of key in meta-source. The meta-source argument can be either a set of metas (i.e., a hash) or a pagenode?, from which metas are pulled. If no value exists for key, you get #f.

Examples:

> (module ice-cream pollen/markup
  '(div (question "Flavor?")
    (answer "Chocolate chip") (answer "Maple walnut"))
    '(meta ((template "sub.xml.pt")))
    '(meta ((target "print"))))
; Import doc & metas from 'ice-cream submodule
> (require 'ice-cream)
> (select-from-metas 'template  metas)

"sub.xml.pt"

> ('target . select-from-metas . metas)

"print"

> (select-from-metas 'nonexistent-key metas)

#f

procedure

(select-from-doc key doc-source)  (or/c #f txexpr-element?)

  key : symbolish?
  doc-source : (or/c txexpr? pagenodeish? pathish?)
Look up the value of key in doc-source. The doc-source argument can be either be a doc (i.e., a txexpr) or a pagenode?, from which doc is pulled. If no value exists for key, you get #f.

Examples:

> (module gelato pollen/markup
  '(div (question "Flavor?")
    (answer "Nocciola") (answer "Pistachio"))
    '(meta ((template "sub.xml.pt")))
    '(meta ((target "print"))))
; Import doc & metas 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

 
\ No newline at end of file +9.6 Template
Module reference
9.1 Cache
9.2 Decode
9.3 File
9.4 Pagetree
9.5 Render
9.6 Template
9.7 Tag
9.8 Top
9.9 World
On this page:
->html
select
select*
select-from-metas
select-from-doc
6.0.1.11

9.6 Template

 (require pollen/template) package: pollen

Convenience functions for templates. These are automatically imported into the eval environment when rendering with a template (see render).

This module also provides everything from sugar/coerce/value.

procedure

(->html xexpr    
  [#:tag html-tag    
  #:attrs html-attrs    
  #:splice splice-html?])  string?
  xexpr : xexpr?
  html-tag : (or/c #f txexpr-tag?) = #f
  html-attrs : (or/c #f txexpr-attrs?) = #f
  splice-html? : boolean? = #f
Convert xexpr to an HTML string. Similar to xexpr->string, but consistent with the HTML spec, text that appears within script or style blocks will not be escaped.

Examples:

> (define tx '(root (script "3 > 2") "Why is 3 > 2?"))
> (xexpr->string tx)

"<root><script>3 &gt; 2</script>Why is 3 &gt; 2?</root>"

> (->html tx)

"<root><script>3 > 2</script>Why is 3 &gt; 2?</root>"

The optional keyword arguments html-tag and html-attrs let you set the outer tag and attributes for the generated HTML. If xexpr already has an outer tag or attributes, they will be replaced.

Examples:

> (define tx '(root ((id "huff")) "Bunk beds"))
> (->html tx)

"<root id=\"huff\">Bunk beds</root>"

> (->html tx #:tag 'div)

"<div id=\"huff\">Bunk beds</div>"

> (->html tx #:attrs '((id "doback")))

"<root id=\"doback\">Bunk beds</root>"

> (->html tx #:tag 'div #:attrs '((id "doback")))

"<div id=\"doback\">Bunk beds</div>"

Whereas if xexpr has no tag or attributes, they will be added. If you supply attributes without a tag, you’ll get an error.

Examples:

> (define x "Drum kit")
> (->html x)

"Drum kit"

> (->html x #:tag 'div)

"<div>Drum kit</div>"

> (->html x #:tag 'div #:attrs '((id "doback")))

"<div id=\"doback\">Drum kit</div>"

> (->html x #:attrs '((id "doback")))

->html: can't use attribute list '((id doback)) without a

#:tag argument

If the generated HTML has an outer tag, the splice-html? option will strip it off. Otherwise this option has no effect.

Examples:

> (define tx '(root (p "Chicken nuggets")))
> (->html tx)

"<root><p>Chicken nuggets</p></root>"

> (->html tx #:splice #t)

"<p>Chicken nuggets</p>"

> (define x "Fancy sauce")
> (->html x)

"Fancy sauce"

; This next one won't do anything
> (->html x #:splice #t)

"Fancy sauce"

; Adds the outer tag, but then #:splice removes it
> (->html x #:tag 'div #:attrs '((id "doback")) #:splice #t)

"Fancy sauce"

Be careful not to pass existing HTML strings into this function, because the angle brackets will be escaped. Fine if that’s what you want, but you probably don’t.

Examples:

> (define tx '(p "You did" (em "what?")))
> (->html tx)

"<p>You did<em>what?</em></p>"

> (->html (->html tx))

"&lt;p&gt;You did&lt;em&gt;what?&lt;/em&gt;&lt;/p&gt;"

procedure

(select key value-source)  (or/c #f txexpr-element?)

  key : symbolish?
  value-source : (or/c hash? txexpr? pagenode? pathish?)

procedure

(select* key value-source)  (or/c #f (listof txexpr-element?))

  key : symbolish?
  value-source : (or/c hash? txexpr? pagenode? pathish?)
Find matches for key in value-source, first by looking in its metas (using select-from-metas) and then by looking in its doc (using select-from-doc). With select, you get the first result; with select*, you get them all. In both cases, you get #f if there are no matches.

procedure

(select-from-metas key meta-source)  (or/c #f txexpr-element?)

  key : symbolish?
  meta-source : (or/c hash? pagenodeish? pathish?)
Look up the value of key in meta-source. The meta-source argument can be either a set of metas (i.e., a hash) or a pagenode?, from which metas are pulled. If no value exists for key, you get #f.

Examples:

> (module ice-cream pollen/markup
  '(div (question "Flavor?")
    (answer "Chocolate chip") (answer "Maple walnut"))
    '(meta ((template "sub.xml.pt")))
    '(meta ((target "print"))))

main-base.rkt:33:43: except-out: identifier to remove

`reader-here-path' not included in nested provide spec

  at: (all-defined-out)

  in: (except-out (all-defined-out) reader-here-path

reader-mode)

; Import doc & metas from 'ice-cream submodule
> (require 'ice-cream)

require: unknown module

  module name: #<resolved-module-path:'ice-cream>

> (select-from-metas 'template  metas)

metas: undefined;

 cannot reference undefined identifier

> ('target . select-from-metas . metas)

metas: undefined;

 cannot reference undefined identifier

> (select-from-metas 'nonexistent-key metas)

metas: undefined;

 cannot reference undefined identifier

procedure

(select-from-doc key doc-source)  (or/c #f txexpr-element?)

  key : symbolish?
  doc-source : (or/c txexpr? pagenodeish? pathish?)
Look up the value of key in doc-source. The doc-source argument can be either be a doc (i.e., a txexpr) or a pagenode?, from which doc is pulled. If no value exists for key, you get #f.

Examples:

> (module gelato pollen/markup
  '(div (question "Flavor?")
    (answer "Nocciola") (answer "Pistachio"))
    '(meta ((template "sub.xml.pt")))
    '(meta ((target "print"))))

main-base.rkt:33:43: except-out: identifier to remove

`reader-here-path' not included in nested provide spec

  at: (all-defined-out)

  in: (except-out (all-defined-out) reader-here-path

reader-mode)

; Import doc & metas from 'gelato submodule
> (require 'gelato)

require: unknown module

  module name: #<resolved-module-path:'gelato>

> (select-from-doc 'question  doc)

doc: undefined;

 cannot reference undefined identifier

> ('answer . select-from-doc . doc)

doc: undefined;

 cannot reference undefined identifier

> (select-from-doc 'nonexistent-key doc)

doc: undefined;

 cannot reference undefined identifier

 
\ No newline at end of file diff --git a/doc/World.html b/doc/World.html index 54e42b0..e4383aa 100644 --- a/doc/World.html +++ b/doc/World.html @@ -1,5 +1,5 @@ -9.9 World
Module reference
9.1 Cache
9.2 Decode
9.3 File
9.4 Pagetree
9.5 Render
9.6 Template
9.7 Tag
9.8 Top
9.9 World
On this page:
world:  default-port
world:  current-server-port
world:  main-pollen-export
world:  meta-pollen-export
world:  project-require
world:  check-project-requires-in-render?
world:  server-extras-dir
world:  current-server-extras-path
world:  preproc-source-ext
world:  markup-source-ext
world:  markdown-source-ext
world:  null-source-ext
world:  pagetree-source-ext
world:  template-source-ext
world:  scribble-source-ext
world:  decodable-extensions
world:  mode-auto
world:  mode-preproc
world:  mode-markup
world:  mode-markdown
world:  mode-pagetree
world:  default-pagetree
world:  pagetree-root-node
world:  command-marker
world:  default-template-prefix
world:  fallback-template
world:  template-meta-key
world:  newline
world:  linebreak-separator
world:  paragraph-separator
world:  dashboard-css
world:  paths-excluded-from-dashboard
6.0.1.11

9.9 World

 (require pollen/world) package: pollen

A set of global values and parameters that are used throughout the Pollen system. If you don’t like the defaults I’ve picked, change them.

All identifiers are exported with the prefix world:, and are so documented below.

A parameter that sets the HTTP port for the project server. Initialized to world:default-port, which defaults to 8080.

The two exports from a compiled Pollen source file. Initialized to 'doc and 'metas, respectively.

File implicitly required into every Pollen source file from its directory. Initialized to "project-require.rkt".

A parameter that determines whether the world:project-require file is checked for changes on every pass through render. (Can be faster to turn this off if you don’t need it.) Initialized to #t.

Name of directory where server support files live. Initialized to "server-extras".

A parameter that reports the path to the directory of support files for the project server. Initialized to #f, but set to a proper value when the server runs.

File extensions for Pollen source files, initialized to the following values:

world:preproc-source-ext = pp +9.9 World

6.0.1.11

9.9 World

 (require pollen/world) package: pollen

A set of global values and parameters that are used throughout the Pollen system. If you don’t like the defaults I’ve picked, change them.

All identifiers are exported with the prefix world:, and are so documented below.

A parameter that sets the HTTP port for the project server. Initialized to world:default-port, which defaults to 8080.

The two exports from a compiled Pollen source file. Initialized to 'doc and 'metas, respectively.

File implicitly required into every Pollen source file from its directory. Initialized to "project-require.rkt".

A parameter that determines whether the world:project-require file is checked for changes on every pass through render. (Can be faster to turn this off if you don’t need it.) Initialized to #t.

Name of directory where server support files live. Initialized to "server-extras".

A parameter that reports the path to the directory of support files for the project server. Initialized to #f, but set to a proper value when the server runs.

File extensions for Pollen source files, initialized to the following values:

world:preproc-source-ext = pp
world:markup-source-ext = pm
world:markdown-source-ext = pmd
world:null-source-ext = p @@ -9,4 +9,4 @@
world:mode-preproc = pre
world:mode-markup = markup
world:mode-markdown = markdown -
world:mode-pagetree = ptree

Pagetree that Pollen dashboard loads by default in each directory. Initialized to "index.ptree".

Name of the root node in a decoded pagetree. It’s ignored by the code, so its only role is to clue you in that you’re looking at something that came out of the pagetree decoder. Initialized to 'pagetree-root.

The magic character that indicates a Pollen command, function, or variable. Initialized to #\◊.

Prefix of the default template. Initialized to "template".

Name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Initialized to "fallback.html.pt".

Meta key used to store a template name for that particular source file. Initialized to 'template.

Default separators used in decoding. The first two are initialized to "\n"; the third to "\n\n".

CSS file used for the dashboard. Initialized to "poldash.css".

Paths not shown in the Pollen dashboard.

 
\ No newline at end of file +
world:mode-pagetree = ptree

Pagetree that Pollen dashboard loads by default in each directory. Initialized to "index.ptree".

Name of the root node in a decoded pagetree. It’s ignored by the code, so its only role is to clue you in that you’re looking at something that came out of the pagetree decoder. Initialized to 'pagetree-root.

The magic character that indicates a Pollen command, function, or variable. Initialized to #\◊.

Prefix of the default template. Initialized to "template".

Used to generate the name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Prefix is combined with the output suffix of the source file. Initialized to "fallback".

Meta key used to store a template name for that particular source file. Initialized to 'template.

Default separators used in decoding. The first two are initialized to "\n"; the third to "\n\n".

CSS file used for the dashboard. Initialized to "poldash.css".

Paths not shown in the Pollen dashboard.

 
\ No newline at end of file diff --git a/doc/doc-index.html b/doc/doc-index.html index 143eaef..451ad56 100644 --- a/doc/doc-index.html +++ b/doc/doc-index.html @@ -1,2 +1,2 @@ -Index

Index

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

 

“Now you have two problems”
#%top
->html
->markup-source-path
->null-source-path
->output-path
->pagenode
->preproc-source-path
->scribble-source-path
->template-source-path
A special data structure for HTML
Acknowledgments
Adding commands
Any command is valid
Backstory
Block
block-txexpr?
Cache
cache-ref
cached-require
children
Command syntax using ◊
Creating a source file
Creating valid HTML output
current-cache
current-pagetree
Custom exports
Decode
decode
def/c
Defining variables with commands
detect-linebreaks
detect-paragraphs
Development environment
Enter Racket
File
File formats
First tutorial
First tutorial complete
Further reading
get-template-for
has-markup-source?
has-null-source?
has-preproc-source?
has-scribble-source?
has-template-source?
has/is-markup-source?
has/is-null-source?
has/is-preproc-source?
has/is-scribble-source?
has/is-template-source?
in-pagetree?
Inserting a comment
Inserting the value of a variable
Inserting values from variables
Inserting variables within CSS
Installation
Intermission
Invoking other functions
Invoking tag functions
License & source code
make-cache
make-tag-function
Making sure raco pollen works
Markdown (.pmd extension)
Markdown mode
Markup (.pm extension)
Markup mode
markup-source?
Module reference
Naming, saving, and rendering a source file
Navigation
next
next*
Null (.p extension)
null-source?
One language, multiple dialects
pagenode?
pagenodeish?
Pagetree
Pagetree (.ptree extension)
pagetree->list
pagetree-source?
pagetree?
Pagetrees
parent
path->pagenode
pollen
Pollen as a preprocessor
Pollen command syntax
pollen/cache
pollen/decode
pollen/file
pollen/markdown
pollen/markup
pollen/pagetree
pollen/pre
pollen/ptree
pollen/render
pollen/tag
pollen/template
pollen/top
pollen/world
Pollen: the book is a program
preproc-source?
Preprocessor (.pp extension)
Prerequisites
previous
previous*
project-block-tags
PS for Scribble users
Putting in the text of the poem
Quick tour
Racket basics (if you’re not familiar)
raco pollen
raco pollen clone
raco pollen help
raco pollen render
raco pollen start
register-block-tag
Render
render
render-batch
render-pagetree
render-to-file
render-to-file-if-needed
reset-cache
Rethinking the solution for digital books
Running a source file
Saving & naming your source file
Scribble (.scrbl extension)
scribble-source?
select
select*
select-from-doc
select-from-metas
Setting the #lang line
Setting up a preprocessor source file
siblings
smart-dashes
smart-quotes
Source files in the dashboard
Source formats
Standard exports
Starting a new file in DrRacket
Starting the project server with raco pollen
Tag
Template
template-source?
Templated source files
Templates
The better idea: a programming model
The big picture
The book is a program
The command name
The end of the beginning
The golden rule
The lozenge glyph (◊)
The preprocessor
The project server
The project-require.rkt file
The Racket arguments
The relationship of Racket & Pollen
The text argument
The two command modes: text mode & Racket mode
Top
Typography
Using raco pollen
Using the dashboard
Using the project server
Utilities
Utility formats
validate-pagetree
Web development and its discontents
What is Pollen?
whitespace/nbsp?
whitespace?
Working with the preprocessor
World
world:check-project-requires-in-render?
world:command-marker
world:current-server-extras-path
world:current-server-port
world:dashboard-css
world:decodable-extensions
world:default-pagetree
world:default-port
world:default-template-prefix
world:fallback-template
world:linebreak-separator
world:main-pollen-export
world:markdown-source-ext
world:markup-source-ext
world:meta-pollen-export
world:mode-auto
world:mode-markdown
world:mode-markup
world:mode-pagetree
world:mode-preproc
world:newline
world:null-source-ext
world:pagetree-root-node
world:pagetree-source-ext
world:paragraph-separator
world:paths-excluded-from-dashboard
world:preproc-source-ext
world:project-require
world:scribble-source-ext
world:server-extras-dir
world:template-meta-key
world:template-source-ext
wrap-hanging-quotes
◊ command overview

 
\ No newline at end of file +Index

Index

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

 

“Now you have two problems”
#%top
->html
->markup-source-path
->null-source-path
->output-path
->pagenode
->preproc-source-path
->scribble-source-path
->template-source-path
A special data structure for HTML
Acknowledgments
Adding commands
Any command is valid
Backstory
Block
block-txexpr?
Cache
cache-ref
cached-require
children
Command syntax using ◊
Creating a source file
Creating valid HTML output
current-cache
current-pagetree
Custom exports
Decode
decode
def/c
Defining variables with commands
detect-linebreaks
detect-paragraphs
Development environment
Enter Racket
File
File formats
First tutorial
First tutorial complete
Further reading
get-template-for
has-markup-source?
has-null-source?
has-preproc-source?
has-scribble-source?
has-template-source?
has/is-markup-source?
has/is-null-source?
has/is-preproc-source?
has/is-scribble-source?
has/is-template-source?
in-pagetree?
Inserting a comment
Inserting the value of a variable
Inserting values from variables
Inserting variables within CSS
Installation
Intermission
Invoking other functions
Invoking tag functions
License & source code
make-cache
make-tag-function
Making sure raco pollen works
Markdown (.pmd extension)
Markdown mode
Markup (.pm extension)
Markup mode
markup-source?
Module reference
Naming, saving, and rendering a source file
Navigation
next
next*
Null (.p extension)
null-source?
One language, multiple dialects
pagenode?
pagenodeish?
Pagetree
Pagetree (.ptree extension)
pagetree->list
pagetree-source?
pagetree?
Pagetrees
parent
path->pagenode
pollen
Pollen as a preprocessor
Pollen command syntax
pollen/cache
pollen/decode
pollen/file
pollen/markdown
pollen/markup
pollen/pagetree
pollen/pre
pollen/ptree
pollen/render
pollen/tag
pollen/template
pollen/top
pollen/world
Pollen: the book is a program
preproc-source?
Preprocessor (.pp extension)
Prerequisites
previous
previous*
project-block-tags
PS for Scribble users
Putting in the text of the poem
Quick tour
Racket basics (if you’re not familiar)
raco pollen
raco pollen clone
raco pollen help
raco pollen render
raco pollen start
register-block-tag
Render
render
render-batch
render-pagetree
render-to-file
render-to-file-if-needed
reset-cache
Rethinking the solution for digital books
Running a source file
Saving & naming your source file
Scribble (.scrbl extension)
scribble-source?
select
select*
select-from-doc
select-from-metas
Setting the #lang line
Setting up a preprocessor source file
siblings
smart-dashes
smart-quotes
Source files in the dashboard
Source formats
Standard exports
Starting a new file in DrRacket
Starting the project server with raco pollen
Tag
Template
template-source?
Templated source files
Templates
The better idea: a programming model
The big picture
The book is a program
The command name
The end of the beginning
The golden rule
The lozenge glyph (◊)
The preprocessor
The project server
The project-require.rkt file
The Racket arguments
The relationship of Racket & Pollen
The text argument
The two command modes: text mode & Racket mode
Top
Typography
Using raco pollen
Using the dashboard
Using the project server
Utilities
Utility formats
validate-pagetree
Web development and its discontents
What is Pollen?
whitespace/nbsp?
whitespace?
Working with the preprocessor
World
world:check-project-requires-in-render?
world:command-marker
world:current-server-extras-path
world:current-server-port
world:dashboard-css
world:decodable-extensions
world:default-pagetree
world:default-port
world:default-template-prefix
world:fallback-template-prefix
world:linebreak-separator
world:main-pollen-export
world:markdown-source-ext
world:markup-source-ext
world:meta-pollen-export
world:mode-auto
world:mode-markdown
world:mode-markup
world:mode-pagetree
world:mode-preproc
world:newline
world:null-source-ext
world:pagetree-root-node
world:pagetree-source-ext
world:paragraph-separator
world:paths-excluded-from-dashboard
world:preproc-source-ext
world:project-require
world:scribble-source-ext
world:server-extras-dir
world:template-meta-key
world:template-source-ext
wrap-hanging-quotes
◊ command overview

 
\ No newline at end of file diff --git a/render.rkt b/render.rkt index d786f2f..a8d53c9 100644 --- a/render.rkt +++ b/render.rkt @@ -36,7 +36,7 @@ (() #:rest (listof (or/c #f complete-path?)) . ->* . boolean?) (define key (make-mod-dates-key rest-paths)) (or (not (key . in? . modification-date-hash)) ; no stored mod date - (not (equal? (map path->mod-date-value key) (get modification-date-hash key))))) ; data has changed + (not (equal? (map path->mod-date-value key) (get modification-date-hash key))))) ; data has changed (define/contract+provide (render-batch . xs) @@ -47,15 +47,15 @@ ;; Using reset-modification-dates is sort of like session control. (reset-modification-dates) (for-each (λ(x) ((if (pagetree-source? x) - render-pagetree - render-from-source-or-output-path) x)) xs)) + render-pagetree + render-from-source-or-output-path) x)) xs)) (define/contract+provide (render-pagetree pagetree-or-path) ((or/c pagetree? pathish?) . -> . void?) (define pagetree (if (pagetree? pagetree-or-path) - pagetree-or-path - (cached-require pagetree-or-path world:main-pollen-export))) + pagetree-or-path + (cached-require pagetree-or-path world:main-pollen-export))) (parameterize ([current-directory (world:current-project-root)]) (for-each render-from-source-or-output-path (map ->complete-path (pagetree->list pagetree))))) @@ -75,8 +75,8 @@ (complete-path? . -> . (values complete-path? complete-path?)) ;; file-proc returns two values, but ormap only wants one (define file-proc (ormap (λ(test file-proc) (and (test source-or-output-path) file-proc)) - (list has/is-null-source? has/is-preproc-source? has/is-markup-source? has/is-scribble-source? has/is-markdown-source? has/is-template-source?) - (list ->null-source+output-paths ->preproc-source+output-paths ->markup-source+output-paths ->scribble-source+output-paths ->markdown-source+output-paths ->template-source+output-paths))) + (list has/is-null-source? has/is-preproc-source? has/is-markup-source? has/is-scribble-source? has/is-markdown-source? has/is-template-source?) + (list ->null-source+output-paths ->preproc-source+output-paths ->markup-source+output-paths ->scribble-source+output-paths ->markdown-source+output-paths ->template-source+output-paths))) (file-proc source-or-output-path)) @@ -95,9 +95,9 @@ (define/contract (render-needed? source-path template-path output-path) (complete-path? (or/c #f complete-path?) complete-path? . -> . boolean?) (or (not (file-exists? output-path)) - (modification-date-expired? source-path template-path) - (and (not (null-source? source-path)) (file-needed-rerequire? source-path)) - (and (world:check-project-requires-in-render?) (project-requires-changed? source-path)))) + (modification-date-expired? source-path template-path) + (and (not (null-source? source-path)) (file-needed-rerequire? source-path)) + (and (world:check-project-requires-in-render?) (project-requires-changed? source-path)))) (define/contract+provide (render-to-file-if-needed source-path [template-path #f] [maybe-output-path #f] #:force [force #f]) @@ -119,8 +119,8 @@ (define render-proc (cond [(ormap (λ(test render-proc) (and (test source-path) render-proc)) - (list has/is-null-source? has/is-preproc-source? has/is-markup-source? has/is-scribble-source? has/is-markdown-source? has/is-template-source?) - (list render-null-source render-preproc-source render-markup-or-markdown-source render-scribble-source render-markup-or-markdown-source render-preproc-source))] + (list has/is-null-source? has/is-preproc-source? has/is-markup-source? has/is-scribble-source? has/is-markdown-source? has/is-template-source?) + (list render-null-source render-preproc-source render-markup-or-markdown-source render-scribble-source render-markup-or-markdown-source render-preproc-source))] [else (error (format "render: no rendering function found for ~a" source-path))])) (message (format "render: ~a" (file-name-from-path source-path))) @@ -183,17 +183,18 @@ (complete-path? . -> . (or/c #f complete-path?)) (match-define-values (source-dir _ _) (split-path source-path)) (and (templated-source? source-path) ; doesn't make sense if it's not a templated source format - (or ; Build the possible paths and use the first one that either exists, or has existing source (template, preproc, or null) - (ormap (λ(p) (if (ormap file-exists? (list p (->template-source-path p) (->preproc-source-path p) (->null-source-path p))) p #f)) + (let ([output-path (->output-path source-path)]) + (or ; Build the possible paths and use the first one that either exists, or has existing source (template, preproc, or null) + (ormap (λ(p) (if (ormap file-exists? (list p (->template-source-path p) (->preproc-source-path p) (->null-source-path p))) p #f)) (filter (λ(x) (->boolean x)) ; if any of the possibilities below are invalid, they return #f - (list - (parameterize ([current-directory (world:current-project-root)]) - (let ([source-metas (cached-require source-path 'metas)]) - (and ((->symbol world:template-meta-key) . in? . source-metas) - (build-path source-dir (select-from-metas (->string world:template-meta-key) source-metas))))) ; path based on metas - (and (filename-extension (->output-path source-path)) (build-path (world:current-project-root) - (add-ext world:default-template-prefix (get-ext (->output-path source-path)))))))) ; path to default template - (build-path (world:current-server-extras-path) world:fallback-template)))) ; fallback template + (list + (parameterize ([current-directory (world:current-project-root)]) + (let ([source-metas (cached-require source-path 'metas)]) + (and ((->symbol world:template-meta-key) . in? . source-metas) + (build-path source-dir (select-from-metas (->string world:template-meta-key) source-metas))))) ; path based on metas + (and (filename-extension output-path) (build-path (world:current-project-root) + (add-ext world:default-template-prefix (get-ext output-path))))))) ; path to default template + (and (filename-extension output-path) (build-path (world:current-server-extras-path) (add-ext world:fallback-template-prefix (get-ext output-path)))))))) ; fallback template (define/contract (file-needed-rerequire? source-path) @@ -228,27 +229,27 @@ (current-eval-namespace-cache (cons cache-ns (cons module-name cached-modules))))) (define initial-modules-to-cache '(web-server/templates - xml - racket/port - racket/file - racket/rerequire - racket/contract - racket/list - racket/match - racket/syntax - pollen/cache - pollen/debug - pollen/decode - pollen/file - pollen/main - pollen/reader-base - pollen/pagetree - pollen/tag - pollen/template - pollen/world - pollen/project - sugar - txexpr)) + xml + racket/port + racket/file + racket/rerequire + racket/contract + racket/list + racket/match + racket/syntax + pollen/cache + pollen/debug + pollen/decode + pollen/file + pollen/main + pollen/reader-base + pollen/pagetree + pollen/tag + pollen/template + pollen/world + pollen/project + sugar + txexpr)) (for-each add-module-to-current-eval-cache initial-modules-to-cache) diff --git a/scribblings/world.scrbl b/scribblings/world.scrbl index 5b5ae21..e8666b3 100644 --- a/scribblings/world.scrbl +++ b/scribblings/world.scrbl @@ -90,8 +90,8 @@ The magic character that indicates a Pollen command, function, or variable. Init @defthing[world:default-template-prefix string?] Prefix of the default template. Initialized to @racket["template"]. -@defthing[world:fallback-template string?] -Name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Initialized to @racket["fallback.html.pt"]. +@defthing[world:fallback-template-prefix string?] +Used to generate the name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Prefix is combined with the output suffix of the source file. Initialized to @racket["fallback"]. @defthing[world:template-meta-key symbol?] Meta key used to store a template name for that particular source file. Initialized to @racket['template]. diff --git a/server-extras/fallback.txt b/server-extras/fallback.txt new file mode 100644 index 0000000..e0160a1 --- /dev/null +++ b/server-extras/fallback.txt @@ -0,0 +1 @@ +◊doc \ No newline at end of file diff --git a/world.rkt b/world.rkt index 40e8274..254dd94 100644 --- a/world.rkt +++ b/world.rkt @@ -28,7 +28,7 @@ (define template-command-marker #\∂) (define default-template-prefix "template") -(define fallback-template "fallback.html") +(define fallback-template-prefix "fallback") (define template-meta-key "template") (define main-pollen-export 'doc) ; don't forget to change fallback template too