The reason I haven't made Temple more language-agnostic is that it's
much more useful to have the template engine implemented in the same
language as the runtime language; less dependencies, more dynamic
possibilities (see Handlebars-JIT and Heffigy) and it makes everything
easier.
If we want to go this way, it means we'll need to more clearly specify
which compilers are language-agnostic, and split more compilers into
two parts (general part, code generation part).
Another possibility is to say that everything we have today (below the
parser) is considered Ruby-stuff. So we need to write a completely new
HTML::Pretty::CoffeeScript (or whatever). These can share code from
the default HTML::Pretty (either by inheritance or some other way).
> https://github.com/jfirebaugh/skim
>
> Here are some more details. Slim makes use of the following Temple
> filters that assume that the target language is Ruby:
>
> * `DynamicInliner` assumes interpolation syntax, line continuations
> via backslash, and implicit string literal concatenation.
Language-specific optimization; doesn't make sense to port to other
languages (other languages might have other useful optimization
filters).
> * `HTML::Pretty` uses bits of Ruby code.
> * `AttributeMerger` and `AttributeRemover` use `[:if, "!
> #{tmp}.empty?", sexp]`.
These would need to split up…
> * `Escapable` uses a Ruby-specific `:escape_code` option by default,
> and assumes that it can both be embedded in the output *and* evaled as
> Ruby code. In my case, I wanted to use
> `Temple::Utils.escape_html[_safe]` Ruby-side and `@escape` (i.e.
> `this.escape`) in CoffeeScript.
This could be better separated into a method/proc (for static stuff)
and :escape_code (for code generation).
> I worked around these issues by providing CoffeeScript-specific
> implementations of the essential filters (`AttributeMerger`,
> `AttributeRemover`, and `Escapable`) and by avoiding the use of
> `DynamicInliner` and `HTML::Pretty` (as a consequence, Skim doesn't
> support pretty printing and is presumably slightly less efficient than
> it could be).
>
> Since CoffeeScript is whitespace sensitive, I also had to add one new
> core abstraction: `[:indent, sexp]`, and use it appropriately in
> `ControlFlow` and `Skim::Compiler`, so that the CoffeeScript
> `Generator` can emit correctly-indented CoffeeScript.
Interesting. I've always heard that generation whitespace sensitive
code can be tricky, but I assume it's much easier when you already
everything as a tree-structure.
> Fortunately, I found that most of Slim's pipeline could be used as-is,
> because it is mostly language agnostic, and where it isn't, it uses
> syntax that is mostly common to Ruby and CoffeeScript (e.g. string
> interpolation). I had to override only a couple `Slim::Compiler`
> methods that emit several Ruby-specific fragments. One of them happens
> also to be valid CoffeeScript, but the one dealing with dynamic array-
> valued HTML attributes will need to be ported. I punted on it for the
> time being. I also have yet to implement sections (logicless mode),
> though I don't think it will be difficult.
>
> I've kept the CoffeeScript portions of the implementation separated
> from the rest of Skim, with the thought that they could later be
> extracted to a temple-coffee gem for reuse.
Yes, if we go for cross-compilation I'd prefer to make the temple gem
just contain language-agnostic and Ruby-specific code.
> Take a look, let me know if you think cross-compilation is an
> interesting direction for Temple.
I'm not sure. It's pretty amazing seeing (pretty much) the same
compilers generate code for both CoffeeScript and Ruby, but wow long
will it take before someone ports Skim to JavaScript? This isn't
actually a million-lines-codebase so porting it to another language
(while basing it on Temple ideas) wouldn't take so long. And for how
many languages is it actually useful to be able to cross-compile? Is
it worth the hassle?
Bernard Lambeau has also been working on cross-compilation for WLang2,
so we should probably figure what he needs too:
https://github.com/blambeau/wlang/tree/wlang2
> Cheers,
> John
Thanks for a *very* cool project, John :-)
The reason I haven't made Temple more language-agnostic is that it'smuch more useful to have the template engine implemented in the same
language as the runtime language; less dependencies, more dynamic
possibilities (see Handlebars-JIT and Heffigy) and it makes everything
easier.
> * `AttributeMerger` and `AttributeRemover` use `[:if, "!These would need to split up…
> #{tmp}.empty?", sexp]`.
Interesting. I've always heard that generation whitespace sensitive
code can be tricky, but I assume it's much easier when you already
everything as a tree-structure.
Yes, if we go for cross-compilation I'd prefer to make the temple gem
just contain language-agnostic and Ruby-specific code.
> Take a look, let me know if you think cross-compilation is anI'm not sure. It's pretty amazing seeing (pretty much) the same
> interesting direction for Temple.
compilers generate code for both CoffeeScript and Ruby, but wow long
will it take before someone ports Skim to JavaScript? This isn't
actually a million-lines-codebase so porting it to another language
(while basing it on Temple ideas) wouldn't take so long. And for how
many languages is it actually useful to be able to cross-compile? Is
it worth the hassle?