[pollen] local-require local files in a template

2018-12-19 Thread sorawee
It doesn't seem to be possible to local-require local files in a template. 
Consider:

;; template.html.p

◊(local-require "utils.rkt")
◊blah

;; utils.rkt

...
(provide blah)
...

;; sub/test.html.pm

test

When rendering sub/test.html, I would get the error that sub/utils.rkt 
doesn't exist.

I tried to fix this using a macro that expands to (local-require 
"../../../utils.rkt") with the appropriate number of "../", but that 
somehow also doesn't work due to an error that I don't totally understand:

template.html:2:2: blah: unbound identifier
  in: blah
  context...:
   #(100195 module) #(100198 module render-helper) #(100881 module g1707)
   #(100883 macro) #(102592 local) #(102593 intdef) #(102601 local)
   #(102602 intdef) [common scopes]
  other binding...:
   local
   #(-102508 module pollen) #(-102491 module) #(102764 macro)
   [common scopes]
  common scopes...:
   #(102643 intdef) #(103568 local) #(103569 intdef)


The reason why I want to local-require local files is that there are a lot 
of functions that are only specific to the template file. Putting those in 
pollen.rkt would solve the problem, but it would pollute the environment 
unnecessarily.

-- 
You received this message because you are subscribed to the Google Groups 
"Pollen" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pollenpub+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [pollen] local-require local files in a template

2018-12-19 Thread Matthew Butterick
The template is merely an accessory for a source file being rendered. 
Everything in the template (including relative path strings) will be evaluated 
as if it were in the source file already. AFAICT this is consistent with how we 
usually expect relative path strings to behave. You hint that you'd prefer 
"utils.rkt" to resolve as if it were an absolute path, but that seems more 
contrarian.

If you don't like putting things in pollen.rkt — you say "pollute" but that is 
its raison d'être — then you could also make a helper package that can be 
invoked as `(local-require sorawee/utils)`.




> On Dec 19, 2018, at 1:54 PM, sora...@cs.washington.edu wrote:
> 
> It doesn't seem to be possible to local-require local files in a template. 
> Consider:

> 
> The reason why I want to local-require local files is that there are a lot of 
> functions that are only specific to the template file. Putting those in 
> pollen.rkt would solve the problem, but it would pollute the environment 
> unnecessarily.

-- 
You received this message because you are subscribed to the Google Groups 
"Pollen" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pollenpub+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.