Overview
| Comment: | Reorganize Pollen and cache stuff in scribble docs |
|---|---|
| Timelines: | family | ancestors | descendants | both | doc-expansion |
| Files: | files | file ages | folders |
| SHA3-256: |
dc332affec65437f3bd4e3b07bc3f712 |
| User & Date: | joel on 2020-02-14 22:25:43.731 |
| Other Links: | branch diff | manifest | tags |
Context
|
2020-02-14
| ||
| 22:46 | Clean up HTML Snippets scribble doc check-in: e2a5ab96 user: joel tags: doc-expansion | |
| 22:25 | Reorganize Pollen and cache stuff in scribble docs check-in: dc332aff user: joel tags: doc-expansion | |
|
2020-02-12
| ||
| 21:13 | Use friendlier repo URL in code docs check-in: 63876c18 user: joel tags: doc-expansion | |
Changes
Added code-docs/cache.scrbl version [aa0f66e5].
Modified code-docs/crystalize.scrbl
from [146fa5fb]
to [af1f96a5].
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#lang scribble/manual
@; SPDX-License-Identifier: BlueOak-1.0.0
@; This file is licensed under the Blue Oak Model License 1.0.0.
@(require "scribble-helpers.rkt")
@(require (for-label "../pollen.rkt"
"../dust.rkt"
"../crystalize.rkt"
racket/base
racket/contract
racket/string
| < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#lang scribble/manual
@; SPDX-License-Identifier: BlueOak-1.0.0
@; This file is licensed under the Blue Oak Model License 1.0.0.
@(require "scribble-helpers.rkt")
@(require (for-label "../pollen.rkt"
"../dust.rkt"
"../crystalize.rkt"
racket/base
racket/contract
racket/string
txexpr
pollen/pagetree))
@title{@filepath{crystalize.rkt}}
@defmodule["crystalize.rkt" #:packages ()]
“Crystalizing” is an extra layer in between docs and templates that destructures the doc and stores
it in various pieces in a SQLite cache. Individual articles save chunks of rendered HTML to the
cache when their individual pages are rendered. When pulling together listings of articles in
different contexts that need to be filtered and sorted, a SQL query is much faster than trolling
through the Pollen cache for matching docs and regenerating the HTML.
@defproc[(parse-and-cache-article! [pagenode pagenode?] [doc txexpr?]) non-empty-string?]
Returns a string containing the HTML of @racket[_doc]. @margin-note{This is one function that breaks
my convention of using a prefix of @tt{html$-} for functions that return a single string of HTML.}
Privately, it does a lot of other work. The article is analyzed, additional metadata is constructed,
and it is saved to the SQLite cache. If the article specifies a @racket['series] meta, information
about that series is fetched and used in the rendering of the article. If there are @racket[note]s
in the doc, they are parsed and saved individually to the SQLite cache. If any of the notes use the
@code{#:disposition} attribute, information about the disposition is parsed out and used in the
rendering of the article.
|
Modified code-docs/dust.scrbl
from [dfcfb9ab]
to [c0b36b73].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#lang scribble/manual
@; SPDX-License-Identifier: BlueOak-1.0.0
@; This file is licensed under the Blue Oak Model License 1.0.0.
@(require "scribble-helpers.rkt"
scribble/example)
@(require (for-label "../pollen.rkt"
"../dust.rkt"
racket/base
racket/contract
txexpr
sugar/coerce
pollen/tag
pollen/setup
pollen/pagetree
pollen/core))
@(define dust-eval (make-base-eval))
@(dust-eval '(require "dust.rkt" txexpr))
| > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#lang scribble/manual
@; SPDX-License-Identifier: BlueOak-1.0.0
@; This file is licensed under the Blue Oak Model License 1.0.0.
@(require "scribble-helpers.rkt"
scribble/example)
@(require (for-label "../pollen.rkt"
"../dust.rkt"
"../cache.rkt"
racket/base
racket/contract
txexpr
sugar/coerce
pollen/tag
pollen/setup
pollen/pagetree
pollen/core))
@(define dust-eval (make-base-eval))
@(dust-eval '(require "dust.rkt" txexpr))
@title{Dust}
@defmodule["dust.rkt" #:packages ()]
This is where I put constants and helper functions that are needed pretty much everywhere in the
project. In a simpler project these would go in @seclink["pollen-rkt"]{@filepath{pollen.rkt}} but
here I have other modules sitting “behind” that one in the @tt{require} chain.
|
| ︙ | ︙ | |||
140 141 142 143 144 145 146 147 148 149 150 151 152 |
(first-words txs-punc-and-split-elems 5)
(first-words txs-dashes 5)
(first-words txs-parens-commas 5)
(first-words txs-short 5)
]
@section{Article parsers and helpers}
@defproc[(default-title [body-txprs (listof txexpr?)]) string?]
Given a list of tagged X-expressions (the elements of an article’s doc, e.g.), returns a string
containing a suitable title for the document. (Uses @racket[first-words].)
| > > > > > > > > | | | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
(first-words txs-punc-and-split-elems 5)
(first-words txs-dashes 5)
(first-words txs-parens-commas 5)
(first-words txs-short 5)
]
@section{Article parsers and helpers}
@defparam[listing-context ctxt (or/c 'blog 'feed 'print "") #:value ""]
A parameter specifying the current context where any listings of articles would appear. Its purpose
is to allow articles to exclude themselves from certain special collections (e.g., the blog, the RSS
feed, print editions). Any article whose @code{conceal} meta matches the current context will not be
included in any listings returned by the listing functions in
@seclink["cache-rkt"]{@filepath{cache.rkt}}.
@defproc[(default-title [body-txprs (listof txexpr?)]) string?]
Given a list of tagged X-expressions (the elements of an article’s doc, e.g.), returns a string
containing a suitable title for the document. (Uses @racket[first-words].)
Titles are not required for articles, but there are contexts where you need something that serves as
a title if one is not present, and that’s what this function supplies.
@examples[#:eval dust-eval
(define doc
'(root (p "If I had been astonished at first catching a glimpse of so outlandish an "
"individual as Queequeg circulating among the polite society of a civilized "
"town, that astonishment soon departed upon taking my first daylight "
"stroll through the streets of New Bedford…")))
|
| ︙ | ︙ |
Modified code-docs/main.scrbl
from [74d70439]
to [33fc9294].
| ︙ | ︙ | |||
30 31 32 33 34 35 36 37 | @local-table-of-contents[] @include-section["tour.scrbl"] @include-section["overview.scrbl"] @include-section["pollen.scrbl"] @; pollen.rkt @include-section["dust.scrbl"] @; dust.rkt @include-section["snippets-html.scrbl"] @; you get the idea @include-section["crystalize.scrbl"] | > | 30 31 32 33 34 35 36 37 38 | @local-table-of-contents[] @include-section["tour.scrbl"] @include-section["overview.scrbl"] @include-section["pollen.scrbl"] @; pollen.rkt @include-section["dust.scrbl"] @; dust.rkt @include-section["snippets-html.scrbl"] @; you get the idea @include-section["cache.scrbl"] @include-section["crystalize.scrbl"] |
Modified code-docs/pollen.scrbl
from [c9accf05]
to [ecc33834].
| ︙ | ︙ | |||
12 13 14 15 16 17 18 |
racket/string
txexpr
pollen/tag
pollen/setup
pollen/core
sugar/coerce))
| | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
racket/string
txexpr
pollen/tag
pollen/setup
pollen/core
sugar/coerce))
@title[#:tag "pollen-rkt"]{Pollen}
@defmodule["pollen.rkt" #:packages ()]
The file @filepath{pollen.rkt} is implicitly @code{require}d in every template and every @code{#lang
pollen} file in the project. It defines the markup for all Pollen documents, and also re-provides
everything provided by @filepath{cache.rkt} and @filepath{crystalize.rkt}.
The @code{setup} module towards the top of the file is used as described in
@racketmodname[pollen/setup].
@section{Markup reference}
These are the tags that can be used in any of @italic{The Local Yarn}’s Pollen documents (articles,
etc).
@defproc[(title [element xexpr?] ...) txexpr?]
|
| ︙ | ︙ | |||
293 294 295 296 297 298 299 |
#lang pollen
◊for/s[x '(7 8 9)]{Now once for number ◊x}
◊;Above line is shorthand for this one:
◊for/splice[[(x (in-list '(7 8 9)))]]{Now once for number ◊x}
}|
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
#lang pollen
◊for/s[x '(7 8 9)]{Now once for number ◊x}
◊;Above line is shorthand for this one:
◊for/splice[[(x (in-list '(7 8 9)))]]{Now once for number ◊x}
}|
@section{Defining new tags}
I use a couple of macros to define tag functions that automatically branch into other functions
depending on the current output target format. This allows me to put the format-specific tag
functions in separate files that have separate places in the dependency chain. So if only the HTML
tag functions have changed and not those for PDF, the @filepath{makefile} can ensure only the HTML files are
rebuilt.
@defproc[#:kind "syntax"
(poly-branch-tag (tag-id symbol?))
(-> txexpr?)]
Defines a new function @racket[_tag-id] which will automatically pass all of its arguments to a
function whose name is the value returned by @racket[current-poly-target], followed by a hyphen,
followed by @racket[_tag]. So whenever the current output format is @racket['html], the function
defined by @racket[(poly-branch-tag _p)] will branch to a function named @racket[html-p]; when the
current format is @racket['pdf], it will branch to @racket[pdf-p], and so forth.
You @emph{must} define these branch functions separately, and you must define one for @emph{every}
output format included in the definition of @racket[poly-targets] in this file’s @racket[setup]
submodule. If you do not, you will get “unbound identifier” errors at expansion time.
The convention in this project is to define and provide these branch functions in separate files:
see, e.g., @filepath{tags-html.rkt}.
Functions defined with this macro @emph{do not} accept keyword arguments. If you need keyword
arguments, see @racket[poly-branch-kwargs-tag].
@margin-note{The thought behind having two macros so similar is that, by cutting out handling for keyword
arguments, @racket[poly-branch-tag] could produce simpler and faster code. I have not verified if
this intuition is meaningful or correct.}
@defproc[#:kind "syntax"
(poly-branch-kwargs-tag (tag-id symbol?))
(-> txexpr?)]
Works just like @racket[poly-branch-tag], but uses Pollen’s @racket[define-tag-function] so that
keyword arguments will automatically be parsed as X-expression attributes.
Additionally, the branch functions called from the new function must accept exactly two arguments:
a list of attributes and a list of elements.
|