|(require pollen-component)||package: pollen-component|
Component-based development for Pollen.
Code of Conduct
Write emails to [email protected].
Pollen projects are generally structured like the following:
The separation of structure ("pollen.rkt"), appearance ("styles.css.pp"), behavior ("scripts.js.pp") and content ("index.html.pm") is a good idea that stood the test of time. So much so, that it is not particular of Pollen projects, but the standard in document-preparation systems like the web and LaTeX. Its main advantage is consistency: generated documents use the same fonts, colors, sizes and so on throughout the pages because those are specified in a single place.
The problems with this model begin when changing from questions like “what are all the styles in effect on this document?” to questions like “what constitutes a link on this document?” To answer this, it is necessary to open at least three files—"pollen.rkt", "styles.css.pp" and "scripts.js.pp"—and search for the snippets relevant to links. One sees only the pieces and has to imagine the full picture. Also, as the project grows, it becomes harder to understand the far-reached effects the parts have on one another.
Recently, modern web development tools including React and Polymer popularized one solution to these issues: components. Components bring together the definitions of structure, appearance and behavior for distinguishable parts of the document.
Components do not replace the traditional architecture. For example, the cascading behavior of CSS is still useful to guarantee consistency throughout the document. But components yield better organization for elements that make sense on their own: links, menus and tag functions in general.
While tools like React and Polymer target application development, we believe that document-preparation systems can benefit from components as well. Thus, we present Pollen Component: an extension to Pollen that allows for component-based development.
The example above becomes the following with Pollen Component:
Pollen Component is a Racket package. Install it in DrRacket or with the following command line:
$ raco pkg install pollen-component
(components-output-types [#:dynamic dynamic ...] [#:static static ...])
dynamic : identifier?
static : identifier?
The static output types receive this name because, with respect to the component being defined, the contents of the static output types are always the same and known at the time of defining the component. In contrast, the contents of dynamic output types will not be known until the component is used. For example, there may be many different HTML links on a page, so a link component would have HTML as a dynamic output type; but the styles associated with links are always the same, defined in a stylesheet, so CSS would be a static output type.
Using components-output-types introduces bindings for define-component and components/<static>s (one for each static output type) in the current environment. Thus, components-output-types must come first and appear only once.
The body corresponding to dynamic output types turn into a function tag that detects the output type of the current document and executes the appropriate code. Undefined dynamic output types fall back to default-tag-function.
The body corresponding to static output types are accumulated in Racket parameters of association lists named components/<static>. There is one components/<static> parameter for each static output type. The keys are the components names (as symbols) and the values are the components contents for that output type as defined by body.
Thank you Matthew Butterick for Pollen and for the feedback given in private email conversations. Thank you Greg Trzeciak for the feedback given in private conversations. Thank you all Racket developers. Thank you all users of this library.
Fix automated tests by ommitting examples directory.
Example in documentation of how to use Pollen Component with CSS-expressions and Urlang.
Acknowledgment to Greg Trzeciak.