raco pollen start uses incorrect template in nested directory #47

Closed
opened 9 years ago by basus · 3 comments
basus commented 9 years ago (Migrated from github.com)

I have a pollen project set up which has a couple of directories under the main one. Each of the nested directories has it's own template.html so that I can generate different types of pages. I've been running raco pollen start in the top-level directory for development work. However, it seems like for generating pages in the nested directories, it's still using the top-level template.html file, rather the one corresponding to each directory. If I run raco pollen render inside each directory, it uses the correct one.

I have a pollen project set up which has a couple of directories under the main one. Each of the nested directories has it's own `template.html` so that I can generate different types of pages. I've been running `raco pollen start` in the top-level directory for development work. However, it seems like for generating pages in the nested directories, it's still using the top-level `template.html` file, rather the one corresponding to each directory. If I run `raco pollen render` inside each directory, it uses the correct one.
mbutterick commented 9 years ago (Migrated from github.com)

The behavior you describe is intentional. My idea with template.html was just to provide unsurprising default behavior for the simple case of a single-directory project. See the docs for get-template-for, which explain how a template is chosen.

The template.html in the project directory is used only when there’s no template explicitly specified using a meta tag. And the project directory is always the one where you do raco pollen start.

If you want source files in subdirectories to use a different template, you have two choices.

  1. You can specify it explicitly in those source files.
#lang pollen
◊meta['template: "my-template.html"]
etc ...
  1. I’ve just pushed an update that lets you specify a metaroot tag function in the directory-require.rkt file that can process the metas. By using metaroot, you can append a 'template meta to every source file in that directory.

metaroot is an X-expression that just holds a list of meta tags, like so:

(metaroot (meta ((key1 "value1"))) (meta ((key2 "value2"))) ...)

So for instance, this metaroot tag function will set the template for all the files in this directory to "new-template.html":

(define (metaroot . metas)
  `(metaroot ,@(append metas (list '(meta ((template "new-template.html")))))))

Keeping with the usual logic of metas, later metas with the same name overwrite earlier ones. The function above guarantees that the files use "new-template.html" (because it comes last). If you want to still allow per-file overrides, you could switch it around like so:

(define (metaroot . metas)
  `(metaroot ,@(cons '(meta ((template "new-template.html"))) metas)))
The behavior you describe is intentional. My idea with `template.html` was just to provide unsurprising default behavior for the simple case of a single-directory project. See the docs for [get-template-for](http://pkg-build.racket-lang.org/doc/pollen/Render.html?q=get-template#%28def._%28%28lib._pollen%2Frender..rkt%29._get-template-for%29%29), which explain how a template is chosen. The `template.html` in the project directory is used only when there’s no template explicitly specified using a `meta` tag. And the project directory is always the one where you do `raco pollen start`. If you want source files in subdirectories to use a different template, you have two choices. 1) You can specify it explicitly in those source files. ``` racket #lang pollen ◊meta['template: "my-template.html"] etc ... ``` 2) I’ve just pushed an update that lets you specify a `metaroot` tag function in the `directory-require.rkt` file that can process the metas. By using `metaroot`, you can append a `'template` meta to every source file in that directory. `metaroot` is an X-expression that just holds a list of `meta` tags, like so: ``` racket (metaroot (meta ((key1 "value1"))) (meta ((key2 "value2"))) ...) ``` So for instance, this `metaroot` tag function will set the template for all the files in this directory to `"new-template.html"`: ``` racket (define (metaroot . metas) `(metaroot ,@(append metas (list '(meta ((template "new-template.html"))))))) ``` Keeping with the usual logic of metas, later metas with the same name overwrite earlier ones. The function above guarantees that the files use `"new-template.html"` (because it comes last). If you want to still allow per-file overrides, you could switch it around like so: ``` racket (define (metaroot . metas) `(metaroot ,@(cons '(meta ((template "new-template.html"))) metas))) ```
basus commented 9 years ago (Migrated from github.com)

Thanks much. The metaroot approach seems handy for my current use case.

Thanks much. The metaroot approach seems handy for my current use case.
mbutterick commented 9 years ago (Migrated from github.com)

Warning: I just pushed an update that changes the format of the list of metas that are passed to metaroot. It used to be a list of metas where the key-value pairs are attributes:

(metaroot (meta ((key1 "value1"))) (meta ((key2 "value2"))) ...)

Now, it’s a list where the key-value pairs are tagged X-expressions:

(metaroot (meta (key1 "value1")) (meta (key2 "value2")) ...)

Moreover, rather than just holding strings, metas can now hold one or more X-expressions, so things like this are possible:

(metaroot (meta (key1 "value1" "value2")) (meta (key2 (img ((src "value3")))) ...)

More info on the change.

Warning: I just pushed an update that changes the format of the list of `metas` that are passed to `metaroot`. It used to be a list of metas where the key-value pairs are attributes: ``` racket (metaroot (meta ((key1 "value1"))) (meta ((key2 "value2"))) ...) ``` Now, it’s a list where the key-value pairs are tagged X-expressions: ``` racket (metaroot (meta (key1 "value1")) (meta (key2 "value2")) ...) ``` Moreover, rather than just holding strings, `metas` can now hold one or more X-expressions, so things like this are possible: ``` racket (metaroot (meta (key1 "value1" "value2")) (meta (key2 (img ((src "value3")))) ...) ``` [More info on the change.](https://github.com/mbutterick/pollen/issues/57#issuecomment-113973150)
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen#47
Loading…
There is no content yet.