renamings within pollen/setup

pull/110/head
Matthew Butterick 8 years ago
parent 2985c09815
commit 775a58dfc2

@ -1,7 +1,7 @@
#lang info
(define collection 'multi)
(define version "0.9.912.84279")
(define version "0.9.913.41357")
(define deps '("base" "txexpr" "sugar" ("markdown" #:version "0.18") "htdp"
"at-exp-lib" "html-lib" "rackjure" "web-server-lib" "scribble-text-lib" "rackunit-lib"
"gui-lib"))

@ -8,7 +8,7 @@
;; The cache is a hash with paths as keys.
;; The cache values are also hashes, with key/value pairs for that path.
(define+provide (reset-cache [starting-dir (setup:current-project-root)])
(define+provide (reset-cache [starting-dir (current-project-root)])
(unless (and (path-string? starting-dir) (directory-exists? starting-dir))
(raise-argument-error 'reset-cache "path-string to existing directory" starting-dir))

@ -86,7 +86,7 @@
(define (convert+validate-path pagenode-or-path caller)
(let ([path (get-source (if (pagenode? pagenode-or-path)
(build-path (setup:current-project-root) (symbol->string pagenode-or-path))
(build-path (current-project-root) (symbol->string pagenode-or-path))
pagenode-or-path))])
(unless path
(error (format "~a no source found for '~a' in directory ~a" caller path (current-directory))))

@ -1,8 +1,8 @@
#lang racket/base
(require "private/main-base.rkt")
(define+provide-module-begin-in-mode setup:default-mode-preproc) ; because default mode in submodule is preproc
(define+provide-module-begin-in-mode default-mode-preproc) ; because default mode in submodule is preproc
(module reader racket/base
(require pollen/private/reader-base)
(define+provide-reader-in-mode setup:default-mode-auto)) ; because default mode in file is auto
(define+provide-reader-in-mode default-mode-auto)) ; because default mode in file is auto

@ -1,8 +1,8 @@
#lang racket/base
(require "private/main-base.rkt")
(define+provide-module-begin-in-mode setup:default-mode-markdown)
(define+provide-module-begin-in-mode default-mode-markdown)
(module reader racket/base
(require pollen/private/reader-base)
(define+provide-reader-in-mode setup:default-mode-markdown))
(define+provide-reader-in-mode default-mode-markdown))

@ -1,8 +1,8 @@
#lang racket/base
(require "private/main-base.rkt")
(define+provide-module-begin-in-mode setup:default-mode-markup)
(define+provide-module-begin-in-mode default-mode-markup)
(module reader racket/base
(require pollen/private/reader-base)
(define+provide-reader-in-mode setup:default-mode-markup))
(define+provide-reader-in-mode default-mode-markup))

@ -8,7 +8,7 @@ a) adapts the at-exp metalang from 6.2
b) incorporates the scribble/reader from 6.2
so that everything will work correctly in 6.0.
Note that pollen/mode uses setup:default-command-char, NOT (setup:command-char),
Note that pollen/mode uses default-command-char, NOT (setup:command-char),
because doing so would create a loading loop if pollen/mode were used in "pollen.rkt"
(which is a likely place to use it)
Intractable problem, unavoiable limitation.
@ -59,7 +59,7 @@ Intractable problem, unavoiable limitation.
(λ args
(parameterize ([current-readtable (make-at-readtable #:datum-readtable 'dynamic
#:command-readtable 'dynamic
#:command-char (dynamic-require 'pollen/setup 'setup:default-command-char))])
#:command-char (dynamic-require 'pollen/setup 'default-command-char))])
(apply p args))))
(define-values (at-read at-read-syntax at-get-info)

@ -93,7 +93,7 @@
;; certain files (leading dot) will be ignored by `directory-list` anyhow.
;; we will, however, ignore Pollen's cache files, because those shouldn't be project-manipulated.
(define (not-pollen-cache? path)
(not (member (->string path) setup:default-cache-names)))
(not (member (->string path) default-cache-names)))
(unless (directory-exists? dir)
(error 'directory->pagetree (format "directory ~v doesn't exist" dir)))
@ -241,7 +241,7 @@
(check-false (next 'three test-pagetree)))
(define/contract+provide (path->pagenode path [starting-path (setup:current-project-root)])
(define/contract+provide (path->pagenode path [starting-path (current-project-root)])
((coerce/path?) (coerce/path?) . ->* . coerce/symbol?)
(define starting-dir
(if (directory-exists? starting-path)

@ -1,8 +1,8 @@
#lang racket/base
(require "private/main-base.rkt")
(define+provide-module-begin-in-mode setup:default-mode-preproc)
(define+provide-module-begin-in-mode default-mode-preproc)
(module reader racket/base
(require pollen/private/reader-base)
(define+provide-reader-in-mode setup:default-mode-preproc))
(define+provide-reader-in-mode default-mode-preproc))

@ -12,8 +12,8 @@
;; can't use relative paths for cache keys because source files include `here-path` which is absolute.
;; problem is that cache could appear valid on another filesystem (based on relative pathnames & mod dates)
;; but would actually be invalid (because the `here-path` names are wrong).
(define poly-flag (and (has-inner-poly-ext? source-path) (setup:current-poly-target)))
(define pollen-env (getenv setup:default-env-name))
(define poly-flag (and (has-inner-poly-ext? source-path) (current-poly-target)))
(define pollen-env (getenv default-env-name))
(define path+mod-time-pairs
(map (λ(ps) (and ps (let ([cp (->complete-path ps)])
(cons (path->string cp) (with-handlers ([exn:fail? (λ _ 0)])

@ -61,7 +61,7 @@ publish [dir] [dest] copy project in dir to dest without source files
(warning: overwrites existing dest dir)
setup preload cache
reset reset cache
version print the version" (setup:current-server-port))))
version print the version" (current-server-port))))
(define (handle-version)
@ -79,7 +79,7 @@ version print the version" (setup:current-server-port))))
(define (handle-render)
(define render-target-wanted (make-parameter (setup:current-poly-target)))
(define render-target-wanted (make-parameter (current-poly-target)))
(define parsed-args (command-line #:program "raco pollen render"
#:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'render' from the front
#:once-each
@ -90,13 +90,13 @@ version print the version" (setup:current-server-port))))
(define path-args (if (empty? parsed-args)
(list (current-directory))
parsed-args))
(parameterize ([current-directory (setup:current-project-root)]
[setup:current-poly-target (render-target-wanted)])
(parameterize ([current-directory (current-project-root)]
[current-poly-target (render-target-wanted)])
(define first-arg (car path-args))
(if (directory-exists? first-arg)
(let ([dir first-arg]) ; now we know it's a dir
(parameterize ([current-directory dir]
[setup:current-project-root dir])
[current-project-root dir])
(define preprocs (filter preproc-source? (directory-list dir)))
(define static-pagetrees (filter pagetree-source? (directory-list dir)))
;; if there are no static pagetrees, use make-project-pagetree
@ -119,8 +119,8 @@ version print the version" (setup:current-server-port))))
(define (handle-start directory-maybe [port #f])
(when (not (directory-exists? directory-maybe))
(error (format "~a is not a directory" directory-maybe)))
(parameterize ([setup:current-project-root directory-maybe]
[setup:current-server-port (or port setup:default-project-server-port)])
(parameterize ([current-project-root directory-maybe]
[current-server-port (or port default-project-server-port)])
(displayln "Starting project server ...")
((dynamic-require 'pollen/private/project-server 'start-server))))
@ -156,7 +156,7 @@ version print the version" (setup:current-server-port))))
(when (directory-exists? target-dir)
(delete-directory/files target-dir))
(copy-directory/files source-dir target-dir)
(parameterize ([setup:current-project-root (current-directory)])
(parameterize ([current-project-root (current-directory)])
(for-each delete-it (find-files pollen-related-file? target-dir)))
(displayln (format "completed to ~a" target-dir)))

@ -272,7 +272,7 @@
[(or (markup-source? x) (preproc-source? x) (null-source? x) (markdown-source? x))
(define output-path (unescape-ext (remove-ext x)))
(if (has-poly-ext? output-path)
(add-ext (remove-ext output-path) (or (setup:current-poly-target) (car (setup:poly-targets))))
(add-ext (remove-ext output-path) (or (current-poly-target) (car (setup:poly-targets))))
output-path)]
[(scribble-source? x) (add-ext (remove-ext x) 'html)]
[else x]))
@ -280,7 +280,7 @@
(define+provide (project-files-with-ext ext)
;(coerce/symbol? . -> . complete-paths?)
(map ->complete-path (filter (λ(i) (has-ext? i (->symbol ext))) (directory-list (setup:current-project-root)))))
(map ->complete-path (filter (λ(i) (has-ext? i (->symbol ext))) (directory-list (current-project-root)))))
(define (racket-source? x)
@ -298,7 +298,7 @@
(define+provide (cache-file? path)
(ormap (λ(cache-name) (ends-with? (path->string path) cache-name)) setup:default-cache-names))
(ormap (λ(cache-name) (ends-with? (path->string path) cache-name)) default-cache-names))
(define+provide (pollen-related-file? file)

@ -18,9 +18,9 @@
[META-MOD (format-symbol "~a" (setup:meta-export))]
[ROOT (format-id #'(EXPR (... ...)) "~a" (setup:main-root-node))]
[NEWLINE (datum->syntax #'(EXPR (... ...)) (setup:newline))]
[MODE-PAGETREE (datum->syntax #'(EXPR (... ...)) setup:default-mode-pagetree)]
[MODE-MARKUP (datum->syntax #'(EXPR (... ...)) setup:default-mode-markup)]
[MODE-MARKDOWN (datum->syntax #'(EXPR (... ...)) setup:default-mode-markdown)]
[MODE-PAGETREE (datum->syntax #'(EXPR (... ...)) default-mode-pagetree)]
[MODE-MARKUP (datum->syntax #'(EXPR (... ...)) default-mode-markup)]
[MODE-MARKDOWN (datum->syntax #'(EXPR (... ...)) default-mode-markdown)]
[SPLICING_TAG (datum->syntax #'(EXPR (... ...)) (setup:splicing-tag))]
[DOC (format-id #'(EXPR (... ...)) "~a" (setup:main-export))]
[DOC-RAW (generate-temporary 'pollen-)]); prevents conflicts with other imported Pollen sources

@ -53,7 +53,7 @@
(procedure? . -> . procedure?)
(λ(req . string-args)
(logger req)
(define path (apply build-path (setup:current-project-root) (flatten string-args)))
(define path (apply build-path (current-project-root) (flatten string-args)))
(response/xexpr+doctype (route-proc path))))
@ -78,7 +78,7 @@
(pathish? . -> . xexpr?)
(define path (->complete-path p))
(define img (bitmap/file path))
(define relative-path (->string (find-relative-path (setup:current-project-root) path)))
(define relative-path (->string (find-relative-path (current-project-root) path)))
(define img-url (format "/~a" relative-path))
`(div
(p "filename =" ,(->string relative-path))
@ -93,7 +93,7 @@
(define (handle-zip-path p)
(pathish? . -> . xexpr?)
(define path (->path p))
(define relative-path (->string (find-relative-path (setup:current-project-root) path)))
(define relative-path (->string (find-relative-path (current-project-root) path)))
(define ziplist (zip-directory-entries (read-zip-directory path)))
`(div
(p "filename =" ,(->string relative-path))
@ -134,7 +134,7 @@
(define (dashboard dashboard-ptree)
(define dashboard-dir (get-enclosing-dir dashboard-ptree))
(define (in-project-root?)
(directories-equal? dashboard-dir (setup:current-project-root)))
(directories-equal? dashboard-dir (current-project-root)))
(define parent-dir (and (not (in-project-root?)) (get-enclosing-dir dashboard-dir)))
(define empty-cell (cons #f #f))
(define (make-link-cell href+text)
@ -145,9 +145,9 @@
text)))))
(define (make-parent-row)
(define title (string-append "Project root" (if (equal? (setup:current-project-root) dashboard-dir) (format " = ~a" dashboard-dir) "")))
(define dirs (cons title (if (not (equal? (setup:current-project-root) dashboard-dir))
(explode-path (find-relative-path (setup:current-project-root) dashboard-dir))
(define title (string-append "Project root" (if (equal? (current-project-root) dashboard-dir) (format " = ~a" dashboard-dir) "")))
(define dirs (cons title (if (not (equal? (current-project-root) dashboard-dir))
(explode-path (find-relative-path (current-project-root) dashboard-dir))
null)))
(define dirlinks (cons "/" (map (λ(ps) (format "/~a/" (apply build-path ps)))
(for/list ([i (in-range (length (cdr dirs)))])
@ -256,7 +256,7 @@
(define/contract (req->path req)
(request? . -> . path?)
(define base (setup:current-project-root))
(define base (current-project-root))
(define file (url->path (request-uri req)))
(if (eq? (system-path-convention-type) 'windows)
(build-path base file) ; because url->path returns a relative path for 'windows

@ -21,18 +21,18 @@
[else route-default]))
(message (format "Welcome to Pollen ~a" pollen:version) (format "(Racket ~a)" (version)))
(message (format "Project root is ~a" (setup:current-project-root)))
(message (format "Project root is ~a" (current-project-root)))
(define server-name (format "http://localhost:~a" (setup:current-server-port)))
(define server-name (format "http://localhost:~a" (current-server-port)))
(message (format "Project server is ~a" server-name) "(Ctrl-C to exit)")
(message (format "Project dashboard is ~a/~a" server-name (setup:main-pagetree)))
(message "Ready to rock")
(parameterize ([error-print-width 1000])
(serve/servlet pollen-servlet
#:port (setup:current-server-port)
#:port (current-server-port)
#:listen-ip #f
#:servlet-regexp #rx"" ; respond to top level
#:command-line? #t
#:file-not-found-responder route-404
#:extra-files-paths (list (setup:current-server-extras-path) (setup:current-project-root)))))
#:extra-files-paths (list (current-server-extras-path) (current-project-root)))))

@ -7,7 +7,7 @@
(define+provide/contract (get-directory-require-files source-arg)
(pathish? . -> . (or/c #f (λ(xs) (and (list? xs) (andmap complete-path? xs)))))
(define source-path (->path source-arg))
(define require-filenames (list setup:default-directory-require))
(define require-filenames (list default-directory-require))
(define identity (λ(x) x))
(define possible-requires (filter identity (map (λ(f) (find-upward-from source-path f)) require-filenames)))
(and (pair? possible-requires) possible-requires))

@ -11,7 +11,7 @@
(define (make-custom-read-syntax reader-mode)
(λ (path-string p)
(define read-inner (make-at-reader
#:command-char (if (or (eq? reader-mode setup:default-mode-template)
#:command-char (if (or (eq? reader-mode default-mode-template)
(and (string? path-string)
(regexp-match (pregexp (format "\\.~a$" (setup:template-source-ext))) path-string)))
(setup:template-command-char)
@ -23,14 +23,14 @@
[(symbol? path-string) (symbol->string path-string)]
[(equal? path-string "unsaved editor") path-string]
[else (path->string path-string)]))
(define parser-mode (if (eq? reader-mode setup:default-mode-auto)
(define parser-mode (if (eq? reader-mode default-mode-auto)
(let* ([file-ext-pattern (pregexp "\\w+$")]
[here-ext (string->symbol (car (regexp-match file-ext-pattern reader-here-path)))]
[auto-computed-mode (cond
[(eq? here-ext (setup:pagetree-source-ext)) setup:default-mode-pagetree]
[(eq? here-ext (setup:markup-source-ext)) setup:default-mode-markup]
[(eq? here-ext (setup:markdown-source-ext)) setup:default-mode-markdown]
[else setup:default-mode-preproc])])
[(eq? here-ext (setup:pagetree-source-ext)) default-mode-pagetree]
[(eq? here-ext (setup:markup-source-ext)) default-mode-markup]
[(eq? here-ext (setup:markdown-source-ext)) default-mode-markdown]
[else default-mode-preproc])])
auto-computed-mode)
reader-mode))
(define post-parser-syntax

@ -12,8 +12,8 @@
;; otherwise if a Pollen source imports others, they will all print their docs in sequence.
;; so only print if the current here-path is the top path, which is stored in the `show-enabled` parameter.
(when (and (show-enabled) (equal? here-path (show-enabled)))
(if (or (eq? parser-mode setup:default-mode-preproc)
(eq? parser-mode setup:default-mode-template))
(if (or (eq? parser-mode default-mode-preproc)
(eq? parser-mode default-mode-template))
(display doc)
;; OK to use dynamic-require because runtime-config itself is dynamic-required
(print (with-handlers ([exn:fail? (λ(exn) ((error '|pollen markup error| ((dynamic-require 'racket/string 'string-join) (cdr ((dynamic-require 'racket/string 'string-split) (exn-message exn) ": ")) ": "))))])

@ -1 +1 @@
1454221479
1454264957

@ -3,9 +3,8 @@
(define-runtime-path info-file "../../info.rkt")
(module+ main
(define str (file->string info-file))
(define newstr
(regexp-replace #rx"\\(define version .*?\\)" str (format "(define version ~v)" pollen:version)))
(display-to-file newstr info-file #:exists 'replace)
(display-to-file newstr info-file #:exists 'replace))

@ -1,8 +1,8 @@
#lang racket/base
(require "private/main-base.rkt")
(define+provide-module-begin-in-mode setup:default-mode-pagetree)
(define+provide-module-begin-in-mode default-mode-pagetree)
(module reader racket/base
(require pollen/private/reader-base)
(define+provide-reader-in-mode setup:default-mode-pagetree))
(define+provide-reader-in-mode default-mode-pagetree))

@ -63,7 +63,7 @@
(define pagetree (if (pagetree? pagetree-or-path)
pagetree-or-path
(cached-doc pagetree-or-path)))
(parameterize ([current-directory (setup:current-project-root)])
(parameterize ([current-directory (current-project-root)])
(for-each render-from-source-or-output-path (map ->complete-path (pagetree->list pagetree)))))
@ -118,9 +118,9 @@
(define output-path (or maybe-output-path (->output-path source-path)))
(define template-path (or maybe-template-path (get-template-for source-path output-path)))
(message (format "rendering: /~a as /~a" (find-relative-path (setup:current-project-root) source-path)
(find-relative-path (setup:current-project-root) output-path)))
(define render-result (parameterize ([setup:current-poly-target (->symbol (get-ext output-path))])
(message (format "rendering: /~a as /~a" (find-relative-path (current-project-root) source-path)
(find-relative-path (current-project-root) output-path)))
(define render-result (parameterize ([current-poly-target (->symbol (get-ext output-path))])
(apply render-proc (list source-path template-path output-path))))
;; wait till last possible moment to store mod dates, because render-proc may also trigger its own subrenders
;; e.g., of a template.
@ -179,7 +179,7 @@
(require (for-syntax racket/base))
(require pollen/private/include-template pollen/cache pollen/private/debug pollen/pagetree pollen/core)
,(require-directory-require-files source-path)
(parameterize ([current-pagetree (make-project-pagetree ,(setup:current-project-root))])
(parameterize ([current-pagetree (make-project-pagetree ,(current-project-root))])
(let ([,(setup:main-export source-path) (cached-doc ,(path->string source-path))]
[,(setup:meta-export source-path) (cached-metas ,(path->string source-path))]
[,(setup:splicing-tag source-path) (λ xs xs)]) ; splice behavior is different in textual context
@ -213,7 +213,7 @@
(define output-path-ext (get-ext output-path))
(define (get-template-from-metas)
(with-handlers ([exn:fail:contract? (λ _ #f)]) ; in case source-path doesn't work with cached-require
(parameterize ([current-directory (setup:current-project-root)])
(parameterize ([current-directory (current-project-root)])
(let* ([source-metas (cached-metas source-path)]
[template-name-or-names (select-from-metas (setup:template-meta-key source-path) source-metas)] ; #f or atom or list
[template-name (cond
@ -231,7 +231,7 @@
(define (get-fallback-template)
(and output-path-ext
(build-path (setup:current-server-extras-path)
(build-path (current-server-extras-path)
(add-ext (setup:fallback-template-prefix source-path) output-path-ext))))
(or (file-exists-or-has-source? (get-template-from-metas))
@ -243,20 +243,20 @@
(module-test-external
(require pollen/setup sugar/file sugar/coerce)
(define fallback.html (build-path (setup:current-server-extras-path)
(define fallback.html (build-path (current-server-extras-path)
(add-ext (setup:fallback-template-prefix) 'html)))
(check-equal? (get-template-for (->complete-path "foo.poly.pm")) fallback.html)
(check-equal? (get-template-for (->complete-path "foo.html.pm")) fallback.html)
(define fallback.svg (build-path (setup:current-server-extras-path)
(define fallback.svg (build-path (current-server-extras-path)
(add-ext (setup:fallback-template-prefix) 'svg)))
(parameterize ([setup:current-poly-target 'svg])
(parameterize ([current-poly-target 'svg])
(check-equal? (get-template-for (->complete-path "foo.poly.pm")) fallback.svg)
(check-equal? (get-template-for (->complete-path "foo.html.pm")) fallback.html))
(define fallback.missing (build-path (setup:current-server-extras-path)
(define fallback.missing (build-path (current-server-extras-path)
(add-ext (setup:fallback-template-prefix) 'missing)))
(parameterize ([setup:current-poly-target 'missing])
(parameterize ([current-poly-target 'missing])
(check-false (get-template-for (->complete-path "foo.poly.pm")))
(check-equal? (get-template-for (->complete-path "foo.html.pm")) fallback.html)))

@ -9,7 +9,7 @@
@defmodule[pollen/cache]
The slowest part of a Pollen @racket[render] is compiling a source file. Because Pollen allows source files to be edited and previewed dynamically, these files get recompiled a lot. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in @code[(format "~a" setup:default-main-export)] and @code[(format "~a" setup:default-meta-export)] — in a cache so they can be reused.
The slowest part of a Pollen @racket[render] is compiling a source file. Because Pollen allows source files to be edited and previewed dynamically, these files get recompiled a lot. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in @code[(format "~a" default-main-export)] and @code[(format "~a" default-meta-export)] — in a cache so they can be reused.
In each directory of your project, Pollen creates a subdirectory called @filepath{pollen-cache}. The files are stored on disk so they can be reused between sessions. If you delete files within a cache directory (or the whole thing), don't worry — everything will get regenerated. (However, you should not read or write to any @filepath{pollen-cache} directory, as the implementation details are subject to change.)
@ -68,7 +68,7 @@ hash-eq?]
)]
Try to retrieve the requested value out of the cache. If it's not there, or out of date, @racket[dynamic-require] is used to update it from the source.
Despite their names, these functions actually rely on @racket[setup:main-export] and @racket[setup:meta-export] (which default to @id[setup:default-main-export] and @id[setup:default-meta-export]). Thus, if you override those names, everything will still work as expected.
Despite their names, these functions actually rely on @racket[setup:main-export] and @racket[setup:meta-export] (which default to @id[default-main-export] and @id[default-meta-export]). Thus, if you override those names, everything will still work as expected.
If you want the speed benefit of the cache, you should @bold{always} use @racket[cached-doc] and @racket[cached-metas] to get data from Pollen source files. That doesn't mean you can't also use functions like @racket[require], @racket[local-require], and @racket[dynamic-require]. They'll just be slower.

@ -29,7 +29,7 @@ Here's how you type it:
@bold{Ubuntu}: ctrl + shift + U, then 25CA
Still, if you don't want to use the lozenge as your command character, you can set Pollen's @racket[setup:default-command-char] value to whatever character you want (see also @seclink["setup-overrides"]).
Still, if you don't want to use the lozenge as your command character, you can set Pollen's @racket[default-command-char] value to whatever character you want (see also @seclink["setup-overrides"]).
@margin-note{Scribble uses the @"@" sign as a delimiter. It's not a bad choice if you only work with Racket files. But as you use Pollen to work on other kinds of text-based files that commonly contain @"@" signs — HTML pages especially — it gets cumbersome. So I changed it.}

@ -55,7 +55,7 @@ Functions for retrieving data out of Pollen source files. These are not the only
(or/c txexpr? string?)]
Retrieve the @racket[doc] export from @racket[_doc-source], which can be either a path, path string, or pagenode that can be resolved into a source path. If @racket[_doc-source] cannot be resolved, raise an error.
If @racket[_doc-source] is a relative path or pagenode, it is treated as being relative to @racket[setup:current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
If @racket[_doc-source] is a relative path or pagenode, it is treated as being relative to @racket[current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
If @racket[setup:main-export] has been overridden with a project-specific value, then that is retrieved instead.
@ -66,7 +66,7 @@ If @racket[setup:main-export] has been overridden with a project-specific value,
hash?]
Retrieve the @racket[metas] export from @racket[_meta-source], which can be either a path, path string, or pagenode that can be resolved into a source path. If @racket[_meta-source] cannot be resolved, raise an error.
If @racket[_meta-source] is a relative path or pagenode, it is treated as being relative to @racket[setup:current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
If @racket[_meta-source] is a relative path or pagenode, it is treated as being relative to @racket[current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
If @racket[setup:meta-export] has been overridden with a project-specific value, then that is retrieved instead.
@ -92,7 +92,7 @@ With @racket[select], you get the first result; with @racket[select*], you get t
In both cases, you get @racket[#f] if there are no matches.
Note that if @racket[_value-source] is a relative path or pagenode, it is treated as being relative to @racket[setup:current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
Note that if @racket[_value-source] is a relative path or pagenode, it is treated as being relative to @racket[current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
@examples[#:eval my-eval
(module nut-butters pollen/markup
@ -115,7 +115,7 @@ Note that if @racket[_value-source] is a relative path or pagenode, it is treate
(or/c #f (listof xexpr?))]
Look up the value of @racket[_key] in @racket[_doc-source]. The @racket[_doc-source] argument can be either 1) a tagged X-expression representing a @racket[doc] or 2) a pagenode or source path that identifies a source file that provides @racket[doc]. If no value exists for @racket[_key], you get @racket[#f].
Note that if @racket[_doc-source] is a relative path or pagenode, it is treated as being relative to @racket[setup:current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
Note that if @racket[_doc-source] is a relative path or pagenode, it is treated as being relative to @racket[current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
@examples[#:eval my-eval
(module gelato pollen/markup
@ -137,7 +137,7 @@ Note that if @racket[_doc-source] is a relative path or pagenode, it is treated
(or/c #f xexpr?)]
Look up the value of @racket[_key] in @racket[_meta-source]. The @racket[_meta-source] argument can be either 1) a hashtable representing @racket[metas] or 2) a pagenode or source path that identifies a source file that provides @racket[metas]. If no value exists for @racket[_key], you get @racket[#f].
Note that if @racket[_meta-source] is a relative path or pagenode, it is treated as being relative to @racket[setup:current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
Note that if @racket[_meta-source] is a relative path or pagenode, it is treated as being relative to @racket[current-project-root]. If that's not what you want, you'll need to convert it explicitly to a complete-path (e.g., with @racket[path->complete-path] or @racket[->complete-path]).
@examples[#:eval my-eval
(define metas (hash 'template "sub.xml.pp" 'target "print"))

@ -257,7 +257,7 @@ To change how this test works, use a @racket[setup] submodule as described in @s
(module setup racket/base
(provide (all-defined-out))
(require pollen/setup)
(define block-tags (cons 'bloq setup:default-block-tags)))]
(define block-tags (cons 'bloq default-block-tags)))]
After that change, the result will be:
@ -265,14 +265,14 @@ After that change, the result will be:
The default block tags are:
@racketidfont{@(string-join (map symbol->string setup:default-block-tags) " ")}
@racketidfont{@(string-join (map symbol->string default-block-tags) " ")}
@defproc[
(merge-newlines
[elements (listof xexpr?)])
(listof xexpr?)]
Within @racket[_elements], merge sequential newline characters into a single element. The newline string is controlled by @racket[setup:newline], and defaults to @val[setup:default-newline].
Within @racket[_elements], merge sequential newline characters into a single element. The newline string is controlled by @racket[setup:newline], and defaults to @val[default-newline].
@examples[#:eval my-eval
(merge-newlines '(p "\n" "\n" "foo" "\n" "\n\n" "bar"
@ -286,7 +286,7 @@ Within @racket[_elements], merge sequential newline characters into a single ele
(listof xexpr?)]
Within @racket[_elements], convert occurrences of the linebreak separator to @racket[_linebreaker], but only if the separator does not occur between blocks (see @racket[block-txexpr?]). Why? Because block-level elements automatically display on a new line, so adding @racket[_linebreaker] would be superfluous. In that case, the linebreak separator just disappears.
The linebreak separator is controlled by @racket[setup:linebreak-separator], and defaults to @val[setup:default-linebreak-separator].
The linebreak separator is controlled by @racket[setup:linebreak-separator], and defaults to @val[default-linebreak-separator].
The @racket[_linebreaker] argument can either be an X-expression, or a function that takes two X-expressions and returns one. This function will receive the previous and next elements, to make contextual substitution possible.
@ -308,7 +308,7 @@ Find paragraphs within @racket[_elements] and wrap them with @racket[_paragraph-
What counts as a paragraph? Any @racket[_elements] that are either a) explicitly set apart with a paragraph separator, or b) adjacent to a @racket[block-txexpr?] (in which case the paragraph-ness is implied).
The paragraph separator is controlled by @racket[setup:paragraph-separator], and defaults to @val[setup:default-paragraph-separator].
The paragraph separator is controlled by @racket[setup:paragraph-separator], and defaults to @val[default-paragraph-separator].
@examples[#:eval my-eval
(decode-paragraphs '("Explicit para" "\n\n" "Explicit para"))

@ -15,17 +15,17 @@ Pollen handles six kinds of source files:
@itemlist[
@item{@bold{Preprocessor}, with file extension @ext[setup:default-preproc-source-ext]}
@item{@bold{Preprocessor}, with file extension @ext[default-preproc-source-ext]}
@item{@bold{Markup}, with file extension @ext[setup:default-markup-source-ext]}
@item{@bold{Markup}, with file extension @ext[default-markup-source-ext]}
@item{@bold{Markdown}, with file extension @ext[setup:default-markdown-source-ext]}
@item{@bold{Markdown}, with file extension @ext[default-markdown-source-ext]}
@item{@bold{Null}, with file extension @ext[setup:default-null-source-ext]}
@item{@bold{Null}, with file extension @ext[default-null-source-ext]}
@item{@bold{Scribble}, with file extension @ext[setup:default-scribble-source-ext]}
@item{@bold{Scribble}, with file extension @ext[default-scribble-source-ext]}
@item{@bold{Pagetree}, with file extension @ext[setup:default-pagetree-source-ext]. This is the only source type that does not produce an output file.}
@item{@bold{Pagetree}, with file extension @ext[default-pagetree-source-ext]. This is the only source type that does not produce an output file.}
]
@ -170,7 +170,7 @@ In all cases, if there is no corresponding source, return @racket[#f].
path?]
Convert a source path @racket[_p] into its corresponding output path. This function simply generates a path for a file — it does not ask whether the file exists.
If @racket[_p] has a @seclink["The_poly_output_type"]{@id[setup:default-poly-source-ext] output type}, then @racket[->output-path] uses @racket[setup:current-poly-target] as the output-path extension.
If @racket[_p] has a @seclink["The_poly_output_type"]{@id[default-poly-source-ext] output type}, then @racket[->output-path] uses @racket[current-poly-target] as the output-path extension.
Otherwise, there are no type-specific variants for this function because the output path of a Pollen source file is @seclink["Saving___naming_your_source_file"]{determined by its name}.

@ -46,7 +46,7 @@ The second export, @racket[metas], is a hashtable of keyvalue pairs with extr
Pollen source files also make the @racket[metas] hashtable available through a submodule, also called @racket[metas]. So rather than importing a source file with @racket[(require "source.html.pm")], you would @racket[(require (submod "source.html.pm" metas))]. Accessing the metas this way avoids fully compiling the source file, and thus will usually be faster.
The names @racket[doc] and @racket[metas] can be changed for a project by overriding @racket[setup:default-main-export] and @racket[setup:default-meta-export].
The names @racket[doc] and @racket[metas] can be changed for a project by overriding @racket[default-main-export] and @racket[default-meta-export].
@margin-note{The Pollen rendering system relies on these two identifiers, but otherwise doesn't care how they're generated. Meaning, the code inside your Pollen source file could be @tt{#lang racket} or @tt{#lang whatever}. As long as you manually @racket[provide] those two identifiers and follow the usual file-naming convention, your source file will be usable.}
@ -65,9 +65,9 @@ If a file called @filepath{pollen.rkt} exists in the same directory with a sourc
@bold{How is this different from Racket?} In Racket, you must explicitly import files using @racket[require].
@subsection{Preprocessor (@(format ".~a" setup:default-preproc-source-ext) extension)}
@subsection{Preprocessor (@(format ".~a" default-preproc-source-ext) extension)}
Invoke the preprocessor dialect by using @code{#lang pollen/pre} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" setup:default-preproc-source-ext)}. These forms are equivalent:
Invoke the preprocessor dialect by using @code{#lang pollen/pre} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" default-preproc-source-ext)}. These forms are equivalent:
@racketmod[#:file "sample.css.pp" pollen
@ -90,9 +90,9 @@ The output of the preprocessor dialect, provided by @racket['doc], is plain text
@subsection{Markdown (@(format ".~a" setup:default-markdown-source-ext) extension)}
@subsection{Markdown (@(format ".~a" default-markdown-source-ext) extension)}
Invoke the Markdown dialect by using @code{#lang pollen/markdown} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" setup:default-markdown-source-ext)}. These forms are equivalent:
Invoke the Markdown dialect by using @code{#lang pollen/markdown} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" default-markdown-source-ext)}. These forms are equivalent:
@racketmod[#:file "sample.txt.pmd" pollen
@ -106,9 +106,9 @@ _...source...
The output of the Markdown dialect, provided by @racket[doc], is a tagged X-expression.
@subsection{Markup (@(format ".~a" setup:default-markup-source-ext) extension)}
@subsection{Markup (@(format ".~a" default-markup-source-ext) extension)}
Invoke the Pollen markup dialect by using @code{#lang pollen/markup} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" setup:default-markup-source-ext)}. These forms are equivalent:
Invoke the Pollen markup dialect by using @code{#lang pollen/markup} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" default-markup-source-ext)}. These forms are equivalent:
@racketmod[#:file "about.html.pm" pollen
@ -121,10 +121,10 @@ _...source...
The output of the Pollen markup dialect, provided by @racket[doc], is a tagged X-expression.
@subsection{Pagetree (@(format ".~a" setup:default-pagetree-source-ext) extension)}
@subsection{Pagetree (@(format ".~a" default-pagetree-source-ext) extension)}
Invoke the pagetree dialect by using @code{#lang pollen/ptree} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" setup:default-pagetree-source-ext)}. These forms are equivalent:
Invoke the pagetree dialect by using @code{#lang pollen/ptree} as the first line of your source file, or by using @code{#lang pollen} with a file extension of @code{@(format ".~a" default-pagetree-source-ext)}. These forms are equivalent:
@racketmod[#:file "main.ptree" pollen
@ -148,12 +148,12 @@ These aren't source formats because they don't contain a @tt{#lang pollen} line.
@subsection{Scribble (@(format ".~a" setup:default-scribble-source-ext) extension)}
@subsection{Scribble (@(format ".~a" default-scribble-source-ext) extension)}
Scribble files are recognized by the project server and can be compiled and previewed in single-page mode.
@subsection{Null (@(format ".~a" setup:default-null-source-ext) extension)}
@subsection{Null (@(format ".~a" default-null-source-ext) extension)}
Files with the null extension are simply rendered as a copy of the file without the extension, so @filepath{index.html.p} becomes @filepath{index.html}.
@ -165,7 +165,7 @@ This can be useful you're managing your project with git. Most likely you'll wan
Pollen relies extensively on the convention of naming source files by adding a source extension to an output-file name. So the Pollen markup source for @filepath{index.html} would be @filepath{index.html.pm}.
This convention occasionally flummoxes other programs that assume a file can only have one extension. If you run into such a situation, you can @italic{escape} the output-file extension using the @racket[setup:default-extension-escape-char], which defaults to the underscore @litchar{_}.
This convention occasionally flummoxes other programs that assume a file can only have one extension. If you run into such a situation, you can @italic{escape} the output-file extension using the @racket[default-extension-escape-char], which defaults to the underscore @litchar{_}.
So instead of @filepath{index.html.pm}, your source-file name would be @filepath{index_html.pm}. When this source file is rendered, it will automatically be converted into @filepath{index.html} (meaning, the escaped extension will be converted into a normal file extension).

@ -63,10 +63,10 @@
(define-syntax (defoverridable stx)
(syntax-case stx ()
[(_ name predicate? desc ...)
(with-syntax ([setup:default-name (format-id stx "setup:default-~a" #'name)]
(with-syntax ([default-name (format-id stx "default-~a" #'name)]
[setup:name (format-id stx "setup:~a" #'name)])
#'(deftogether ((defproc (setup:name) predicate?)
(defthing setup:default-name predicate?)
(defthing default-name predicate?)
)
desc ...))]))

@ -24,7 +24,7 @@ Pagetrees surface throughout the Pollen system. They're primarily used for navig
@section{Making pagetrees with a source file}
A pagetree source file either starts with @code{#lang pollen} and uses the @racketfont{@(format ".~a" setup:default-pagetree-source-ext)} extension, or starts with @code{#lang pollen/ptree} and then can have any file extension.
A pagetree source file either starts with @code{#lang pollen} and uses the @racketfont{@(format ".~a" default-pagetree-source-ext)} extension, or starts with @code{#lang pollen/ptree} and then can have any file extension.
Unlike other Pollen source files, since the pagetree source is not rendered into an output format, the rest of the filename is up to you.
@ -422,7 +422,7 @@ Return the pagenode immediately after @racket[_p]. For @racket[next*], return al
[pagetree-source pathish?])
pagetree?
]
Get a pagetree from a @ext[setup:default-pagetree-source-ext] source file, namely @racket[_pagetree-source].
Get a pagetree from a @ext[default-pagetree-source-ext] source file, namely @racket[_pagetree-source].
@defproc[
@ -456,7 +456,7 @@ Report whether @racket[_pagenode] is in @racket[_pagetree].
@defproc[
(path->pagenode
[p pathish?]
[starting-path pathish? (setup:current-project-root)])
[starting-path pathish? (current-project-root)])
pagenode?
]
Convert path @racket[_p] to a pagenode — meaning, make it relative to @racket[_starting-path], run it through @racket[->output-path], and convert it to a symbol. Does not tell you whether the resulting pagenode actually exists in the current pagetree (for that, use @racket[in-pagetree?]).

@ -47,7 +47,7 @@ Displays a list of available commands.
@section{@exec{raco pollen start}}
Start the project server from the current directory using the default port, which is the value of the parameter @racket[setup:current-server-port] (by default, port @(format "~a" setup:default-project-server-port)).
Start the project server from the current directory using the default port, which is the value of the parameter @racket[current-server-port] (by default, port @(format "~a" default-project-server-port)).
This command can be invoked with two optional arguments.
@ -56,7 +56,7 @@ This command can be invoked with two optional arguments.
@terminal{
> raco pollen start ~/path/to/project/}
@racket[raco pollen start _path _port] will start the project server in @racket[_path] using @racket[_port] rather than @racket[setup:current-server-port]. This is useful if you want to have multiple project servers running simultaneously.
@racket[raco pollen start _path _port] will start the project server in @racket[_path] using @racket[_port] rather than @racket[current-server-port]. This is useful if you want to have multiple project servers running simultaneously.
@terminal{
> raco pollen start ~/path/to/project/

@ -75,7 +75,7 @@ Note that @racket[_pt-or-pt-source] is used strictly as a list of files to rende
Find a template file for @racket[_source-path], with the following priority:
@itemlist[#:style 'ordered
@item{If the @racket[metas] for @racket[_source-path] have a key for @code[(format "~a" setup:default-template-meta-key)], then use the value of this key, e.g. —
@item{If the @racket[metas] for @racket[_source-path] have a key for @code[(format "~a" default-template-meta-key)], then use the value of this key, e.g. —
@code{◊(define-meta template "my-template.html")}
@ -88,7 +88,7 @@ If your project has @seclink["fourth-tutorial"]{multiple output targets}, you ca
}
@item{If this key doesn't exist, or refers to a nonexistent file, look for a default template with the name @code[(format "~a.[output extension]" setup:default-template-prefix)]. Meaning, if @racket[_source-path] is @code[(format "intro.html.~a" setup:default-markup-source-ext)], the output path would be @code["intro.html"], so the default template would be @code[(format "~a.html" setup:default-template-prefix)]. Look for this default template in the same directory as the source file, and then search upwards within successive parent directories. (Corollary: a default template in the project root will apply to all files in the project unless overridden within a subdirectory.)}
@item{If this key doesn't exist, or refers to a nonexistent file, look for a default template with the name @code[(format "~a.[output extension]" default-template-prefix)]. Meaning, if @racket[_source-path] is @code[(format "intro.html.~a" default-markup-source-ext)], the output path would be @code["intro.html"], so the default template would be @code[(format "~a.html" default-template-prefix)]. Look for this default template in the same directory as the source file, and then search upwards within successive parent directories. (Corollary: a default template in the project root will apply to all files in the project unless overridden within a subdirectory.)}
@item{If this file doesn't exist, use the fallback template as a last resort. (See @secref["Templates"
#:tag-prefixes '("tutorial-2")

@ -47,12 +47,12 @@ For instance, suppose you wanted the main export of every Pollen source file to
Of course, you can restore the defaults simply by removing these defined values from @racket["pollen.rkt"].
Every @racket[(setup:_name)] function will resolve the current value of that variable: it will return the value from the @racket[setup] submodule (if @racket[_name] was defined there), otherwise it will return the default value (which is directly available from @racket[setup:default-]@racket[_name]). For instance, @racket[setup:default-command-char] will always be @litchar{◊}, but in the example above, @racket[(setup:command-char)] would return @litchar{🎸}.
Every @racket[(setup:_name)] function will resolve the current value of that variable: it will return the value from the @racket[setup] submodule (if @racket[_name] was defined there), otherwise it will return the default value (which is directly available from @racket[default-]@racket[_name]). For instance, @racket[default-command-char] will always be @litchar{◊}, but in the example above, @racket[(setup:command-char)] would return @litchar{🎸}.
@section{Values}
@defoverridable[project-server-port integer?]{
Determines the default HTTP port for the project server. Initialized to @val[setup:default-project-server-port].}
Determines the default HTTP port for the project server. Initialized to @val[default-project-server-port].}
@defoverridable[main-export symbol?]{The main X-expression exported from a compiled Pollen source file. Initialized to @racket[doc].}
@ -72,13 +72,13 @@ Determines the default HTTP port for the project server. Initialized to @val[set
)]
File extensions for Pollen source files, initialized to the following values:
@racket[setup:default-preproc-source-ext] = @code[(format "'~a" setup:default-preproc-source-ext)]
@(linebreak)@racket[setup:default-markup-source-ext] = @code[(format "'~a" setup:default-markup-source-ext)]
@(linebreak)@racket[setup:default-markdown-source-ext] = @code[(format "'~a" setup:default-markdown-source-ext)]
@(linebreak)@racket[setup:default-null-source-ext] = @code[(format "'~a" setup:default-null-source-ext)]
@(linebreak)@racket[setup:default-pagetree-source-ext] = @code[(format "'~a" setup:default-pagetree-source-ext)]
@(linebreak)@racket[setup:default-template-source-ext] = @code[(format "'~a" setup:default-template-source-ext)]
@(linebreak)@racket[setup:default-scribble-source-ext] = @code[(format "'~a" setup:default-scribble-source-ext)]
@racket[default-preproc-source-ext] = @code[(format "'~a" default-preproc-source-ext)]
@(linebreak)@racket[default-markup-source-ext] = @code[(format "'~a" default-markup-source-ext)]
@(linebreak)@racket[default-markdown-source-ext] = @code[(format "'~a" default-markdown-source-ext)]
@(linebreak)@racket[default-null-source-ext] = @code[(format "'~a" default-null-source-ext)]
@(linebreak)@racket[default-pagetree-source-ext] = @code[(format "'~a" default-pagetree-source-ext)]
@(linebreak)@racket[default-template-source-ext] = @code[(format "'~a" default-template-source-ext)]
@(linebreak)@racket[default-scribble-source-ext] = @code[(format "'~a" default-scribble-source-ext)]
@defoverridable[main-pagetree string?]{Pagetree that Pollen dashboard loads by default in each directory. Initialized to @filepath{index.ptree}.}
@ -89,7 +89,7 @@ File extensions for Pollen source files, initialized to the following values:
@defoverridable[block-tags (listof symbol?)]{Tags that are treated as blocks by @racket[block-txexpr?]. Initialized to the @link["https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements"]{block-level elements in HTML5}, namely:
@racketidfont{@(string-join (map symbol->string (cdr setup:default-block-tags)) " ")}
@racketidfont{@(string-join (map symbol->string (cdr default-block-tags)) " ")}
... plus @racket[setup:main-root-node].}
@ -117,7 +117,7 @@ Default separators used in decoding. The first two are initialized to @racket["\
@defoverridable[unpublished-path? (path? . -> . boolean?)]{Predicate that determines whether a path is omitted from @secref{raco_pollen_publish} operations. If the predicate is @racket[#t], then the path is omitted. The default, therefore, is @racket[#f].}
@defoverridable[splicing-tag symbol?]{Key used to signal that an X-expression should be spliced into its containing X-expression. Default is @val[setup:default-splicing-tag].}
@defoverridable[splicing-tag symbol?]{Key used to signal that an X-expression should be spliced into its containing X-expression. Default is @val[default-splicing-tag].}
@defoverridable[poly-source-ext symbol?]{Extension that indicates a source file can target multiple output types. Default is @racket['poly].}
@ -130,15 +130,15 @@ Default separators used in decoding. The first two are initialized to @racket["\
I mean @italic{parameters} in the Racket sense, i.e. values that can be fed to @racket[parameterize].
@defparam[setup:current-server-port port integer?]{
A parameter that sets the HTTP port for the project server. Initialized to @racket[setup:default-project-server-port].}
@defparam[current-server-port port integer?]{
A parameter that sets the HTTP port for the project server. Initialized to @racket[default-project-server-port].}
@defparam[setup:current-project-root port path?]{
@defparam[current-project-root port path?]{
A parameter that holds the root directory of the current project (e.g., the directory where you launched @code{raco pollen start}).}
@defparam[setup:current-server-extras-path dir path?]{
@defparam[current-server-extras-path dir path?]{
A parameter that reports the path to the directory of support files for the project server. Initialized to @racket[#f], but set to a proper value when the server runs.}
@defparam[setup:current-poly-target target symbol?]{
@defparam[current-poly-target target symbol?]{
A parameter that reports the current rendering target for @racket[poly] source files. Initialized to @racket['html].}

@ -234,7 +234,7 @@ Though port @tt{8080} is the default, you can start the project server on any po
> raco pollen start /path/to/tutorial 8088
}
@margin-note{You can also change the default port by altering @racket[setup:default-project-server-port], or parameterizing it with @racket[setup:current-server-port].}
@margin-note{You can also change the default port by altering @racket[default-project-server-port], or parameterizing it with @racket[current-server-port].}
Note that when you pass a port argument, you also have to pass a path argument. (Without it, you'll get an error, as illustrated below.) If you want the project server to start in the current directory, you can use the usual @litchar{.} shorthand:

@ -221,7 +221,7 @@ But plain text doesn't have @racket[h2] or @racket[strong]. So how about this: w
``So how do we make our tags mean one thing for HTML and a different thing for plain text?'' We make @italic{branching tag functions} that do different things depending on what the current rendering target for poly sources is.
That value, in fact, is stored in a Pollen @seclink["parameterize" #:doc '(lib "scribblings/guide/guide.scrbl")]{parameter} called @racket[(setup:current-poly-target)]. What we're going to do is rewrite our tag functions to behave differently based on the value of this parameter. Update your @filepath{pollen.rkt} as follows:
That value, in fact, is stored in a Pollen @seclink["parameterize" #:doc '(lib "scribblings/guide/guide.scrbl")]{parameter} called @racket[(current-poly-target)]. What we're going to do is rewrite our tag functions to behave differently based on the value of this parameter. Update your @filepath{pollen.rkt} as follows:
@fileblock["pollen.rkt" @codeblock|{
#lang racket/base
@ -236,12 +236,12 @@ That value, in fact, is stored in a Pollen @seclink["parameterize" #:doc '(lib "
(date->string (current-date)))
(define (heading . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(txt) (map string-upcase xs)]
[else `(h2 ,@xs)]))
(define (emph . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(txt) `("**" ,@xs "**")]
[else `(strong ,@xs)]))
}|]
@ -280,13 +280,13 @@ Let's see how fast we can add support for LaTeX output. Here's the updated @file
(date->string (current-date)))
(define (heading . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(ltx) (apply string-append `("{\\huge " ,@xs "}"))]
[(txt) (map string-upcase xs)]
[else `(h2 ,@xs)]))
(define (emph . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(ltx) (apply string-append `("{\\bf " ,@xs "}"))]
[(txt) `("**" ,@xs "**")]
[else `(strong ,@xs)]))
@ -343,13 +343,13 @@ First, we update @filepath{pollen.rkt}:
(date->string (current-date)))
(define (heading . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(ltx pdf) (apply string-append `("{\\huge " ,@xs "}"))]
[(txt) (map string-upcase xs)]
[else `(h2 ,@xs)]))
(define (emph . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(ltx pdf) (apply string-append `("{\\bf " ,@xs "}"))]
[(txt) `("**" ,@xs "**")]
[else `(strong ,@xs)]))

@ -336,7 +336,7 @@ But within a template, we need to tell Pollen how we want to convert the X-expre
Third, we need to include the content from our source file. By convention, every Pollen source file makes its output available through an exported variable named @code{doc}. A source file in preprocessor mode puts its text result in @code{doc}. And a source file in authoring mode puts its X-expression result in @code{doc}. So we put the variable @code{doc} inside the @code{body} tag.
@margin-note{You can change the name to something other than @code{doc} by changing @racket[setup:default-main-export].}
@margin-note{You can change the name to something other than @code{doc} by changing @racket[default-main-export].}
@codeblock[#:keep-lang-line? #f]{
#lang pollen

@ -2,12 +2,15 @@
(require (for-syntax racket/base racket/syntax))
(require racket/runtime-path)
(provide (prefix-out setup: (combine-out (all-defined-out))))
(define-syntax-rule (define+provide id expr ...)
(begin
(provide id)
(define id expr ...)))
(define current-project-root (make-parameter (current-directory)))
(define+provide current-project-root (make-parameter (current-directory)))
(define default-directory-require "pollen.rkt")
(define default-env-name "POLLEN")
(define+provide default-directory-require "pollen.rkt")
(define+provide default-env-name "POLLEN")
(define (get-path-to-override [file-or-dir (current-directory)])
(define file-with-config-submodule default-directory-require)
@ -33,6 +36,7 @@
[world-submodule (format-id stx "~a" world-submodule-name)]
[name-fail-thunked (format-id stx "fail-thunk-~a" #'name)] )
#'(begin
(provide (prefix-out setup: name-thunked) default-name)
(define default-name default-value)
(define name-fail-thunked (λ _ default-name))
;; can take a dir argument that sets start point for (get-path-to-override) search.
@ -49,16 +53,16 @@
(define-settable scribble-source-ext 'scrbl)
;; these are deliberately not settable because they're just internal signalers, no effect on external interface
(define default-mode-auto 'auto)
(define default-mode-preproc 'pre)
(define default-mode-markup 'markup)
(define default-mode-markdown 'markdown)
(define default-mode-pagetree 'ptree)
(define default-mode-template 'template)
(define+provide default-mode-auto 'auto)
(define+provide default-mode-preproc 'pre)
(define+provide default-mode-markup 'markup)
(define+provide default-mode-markdown 'markdown)
(define+provide default-mode-pagetree 'ptree)
(define+provide default-mode-template 'template)
(define-settable cache-filename "pollen.cache")
(define-settable cache-dir-name "pollen-cache")
(define default-cache-names (list (cache-filename) (cache-dir-name)))
(define+provide default-cache-names (list (cache-filename) (cache-dir-name)))
(define-settable decodable-extensions (list (markup-source-ext) (pagetree-source-ext)))
@ -90,12 +94,12 @@
(define-settable project-server-port 8080)
(define current-server-port (make-parameter (project-server-port)))
(define+provide current-server-port (make-parameter (project-server-port)))
(define-settable dashboard-css "poldash.css")
(define-runtime-path server-extras-dir "private/server-extras")
(define current-server-extras-path (make-parameter server-extras-dir))
(define+provide current-server-extras-path (make-parameter server-extras-dir))
(define-settable publish-directory-name "publish")
@ -113,4 +117,4 @@
(define-settable poly-source-ext 'poly) ; extension that signals source can be used for multiple output targets
(define-settable poly-targets '(html)) ; current target applied to multi-output source files
(define current-poly-target (make-parameter (car (poly-targets))))
(define+provide current-poly-target (make-parameter (car (poly-targets))))

@ -8,11 +8,11 @@
(define compile-cache-active #f))
(define (heading . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(txt) (map string-upcase xs)]
[else `(h2 ,@xs)]))
(define (emph . xs)
(case (setup:current-poly-target)
(case (current-poly-target)
[(txt) `("**" ,@xs "**")]
[else `(strong ,@xs)]))

@ -21,7 +21,7 @@
(define racket-path (find-exe))
;; parameterize needed to pick up override file
(parameterize ([current-directory override-dir]
[setup:current-project-root override-dir])
[current-project-root override-dir])
(when racket-path
(define (run path)
(define cmd-string (format "'~a' ~a" racket-path path))

@ -6,5 +6,5 @@
(define-runtime-path test-source "data/pollen-mode/test-pollen-mode.foo")
(parameterize ([current-directory test-dir]
[setup:current-project-root test-dir])
[current-project-root test-dir])
(check-equal? ((dynamic-require test-source 'proc)) "fooXbarXzam"))

@ -6,9 +6,9 @@
(define-runtime-path poly-source "data/poly/test.poly.pm")
(parameterize ([current-directory poly-dir]
[setup:current-project-root poly-dir]
[current-project-root poly-dir]
[current-output-port (open-output-string)])
(parameterize ([setup:current-poly-target 'txt])
(parameterize ([current-poly-target 'txt])
(check-equal? (render poly-source) "TITLE is **big**"))
(parameterize ([setup:current-poly-target 'html])
(parameterize ([current-poly-target 'html])
(check-equal? (render poly-source) (format "~v" '(root (h2 "title") " is " (strong "big"))))))

@ -20,7 +20,7 @@
;; test makes sure that quick tour files work
(parameterize ([current-output-port (open-output-string)]
[current-directory quick-tour-dir]
[setup:current-project-root quick-tour-dir])
[current-project-root quick-tour-dir])
(check-not-exn (λ _ (render-to-file-if-needed hello.txt.pp)))
(check-not-exn (λ _ (render-to-file-if-needed margin.html.pp)))
(check-not-exn (λ _ (render-to-file-if-needed downtown.html.pmd)))

@ -16,7 +16,7 @@
;; test makes sure that file render changes after pollen.rkt changes
(parameterize ([current-output-port (open-output-string)]
[current-directory rerequire-dir]
[setup:current-project-root rerequire-dir])
[current-project-root rerequire-dir])
(display-to-file @string-append{#lang racket/base
(provide id)

@ -8,7 +8,7 @@
(define-runtime-path three-source "data/subtemplate/subdir/subsubdir/three.txt.pm")
(parameterize ([current-directory subtemplate-dir]
[setup:current-project-root subtemplate-dir]
[current-project-root subtemplate-dir]
[current-output-port (open-output-string)])
(check-equal? (render one-source) "one in main template")
(check-equal? (render two-source) "two in main template")

Loading…
Cancel
Save