ckirkendall / kioo

Enlive/Enfocus style templating for Facebook's React and Om in ClojureScript.
Eclipse Public License 1.0
404 stars 39 forks source link

Compile-time transforms? #64

Closed tdammers closed 8 years ago

tdammers commented 8 years ago

We have this situation here where we want to add translation / i18n to our templates.

Most of the translatable strings are hard-coded into the HTML templates, so what we would ideally want is a way to hook into the compilation process that detects translation syntax and injects calls to a translation function. IMO, the cleanest way for this would be to add an optional field to the emitter options where one could inject a transformation function which will be run after parsing the HTML template, but before handing it to the emitter.

Does that sound like a reasonable idea, and how would I go about it? It seems to me that this would require patching kioo itself, but maybe there are other ways of getting what I want?

ckirkendall commented 8 years ago

I would handle this as a separate compile phast on the resource. Kioo allows you to pass it a resource. If it receives a string it will try to find a file but you could just pass it a resource directly by wrapping your file paths with this logic.

(defsnippet with-translation (translate "resources/my-cool.html") [...]  {...})

The emitters were built to be pluggable because I have several emit targets. If you look at the om.clj and om.cjs you will see it is not much code to replace the emitter and create your own my_om.clj & my_om.cljs that controls the how the nodes are written out.

tdammers commented 8 years ago

Wouldn't that require doing the actual translation compile-time though? I'd rather do it run-time, having the compile-time code only inject the function calls to the translation function, but not actually executing them yet.

tdammers commented 8 years ago

Thanks a lot!