getting the filename of current input source in pollen.rkt

36 views
Skip to first unread message

Ifeoluwapo Eleyinafe

unread,
Mar 28, 2019, 9:23:46 AM3/28/19
to Pollen

I'd like to use the current input source as "filename" to generate a filename.data for storing previously obtained json data from api pulls.

Among the many things I can't figure out is how to get the filename of the file currently being rendered into my pollen.rkt. Is there a way to do this? I've been trawling through the pollen docs on racket and can't find it. I think I can pull from metas using 'here-path but I don't know how to access metas from pollen.rkt. I can do so from the template file but then I won't be able to use the data in my tag definitions.

Any help would be greatly appreciated. Thank you all for helping me out so much already.

- Ife

Matthew Butterick

unread,
Mar 28, 2019, 11:21:27 AM3/28/19
to Ifeoluwapo Eleyinafe, Pollen
On Mar 28, 2019, at 6:23 AM, Ifeoluwapo Eleyinafe <eleyi...@gmail.com> wrote:

 I think I can pull from metas using 'here-path but I don't know how to access metas from pollen.rkt. I can do so from the template file but then I won't be able to use the data in my tag definitions.

Ifeoluwapo Eleyinafe

unread,
Mar 28, 2019, 8:12:29 PM3/28/19
to Pollen
Thanks so much for the quick reply. So I tried to access (current-metas) from the pollen.rkt but I keep getting false.
I tried creating a test meta with (define-meta ...) but it was not accessible and it wasn't visible on (current-metas).
Tried running (select-from-metas) from pollen.rkt but metas was an unbound identifier.
I'm sure I'm doing something wrong. I'll keep re-reading the documentation.

Thanks much for your help.

Sorawee Porncharoenwase

unread,
Mar 28, 2019, 10:10:02 PM3/28/19
to Ifeoluwapo Eleyinafe, Pollen

Can we see your pollen.rkt? Anyhow, it’s very likely that you call (current-metas) outside of tag functions.

(current-metas) is “undefined” outside of tag functions, which make sense if you think about it: pollen.rkt can be used by several Pollen markup files, and each markup file can define different metas. Therefore, outside of tag functions, the concept of metas is not well-defined.

On the other hand, a tag function is invoked from markup files, so it's possible to associate metas to (current-metas).

corr

--
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+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ifeoluwapo Eleyinafe

unread,
Mar 29, 2019, 12:17:32 AM3/29/19
to Pollen
Great advice. Thanks so much. So I've defined an arbitrary function:
(define (output-filename meta-source)
   
(path->string
       
(car (reverse (explode-path (string->path (select-from-metas 'here-path meta-source)))))))

Then I call it from within a tag function like so:
(output-filename (current-metas))

Just want to say thanks again. In hindsight, here are the words from the manual about (current-metas):
"Holds the metas of the current Pollen source. In tag functions, ..."

Have a good evening and I really appreciate your help and that of Mr. Butterick.

To unsubscribe from this group and stop receiving emails from it, send an email to poll...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages