Closure Templates in Ruby?

167 views
Skip to first unread message

Dylan Vaughn

unread,
Oct 31, 2011, 4:09:46 AM10/31/11
to closure-temp...@googlegroups.com
Hello all,

I'm interested in using Closure Templates within my Ruby (Rails)
application. I can see from the documentation[1] that:

"The Closure Templates compiler has one frontend for parsing template
syntax and constructing an intermediate tree representation, and
multiple backends for supporting usage from multiple programming
languages. You can use one of two backends"

where the current backends are JS and Java. Seems like I am looking
for a Ruby back-end. I am looking for advise on the following:

* Does anyone know of any efforts to use Closure Templates with Ruby
that already exist?

* If not, could someone give a little more detail on what / where the
"intermediate tree representation" is and if that would be a good
starting point for developing a Ruby back-end? I took a quick look at
the source and it wasn't obvious to me how to create additional
back-ends.

Thanks!

Dylan

1. http://code.google.com/closure/templates/docs/concepts.html#compilerbackends

Aliaksandr Zahatski

unread,
Nov 1, 2011, 4:52:18 AM11/1/11
to closure-temp...@googlegroups.com
hi, Dylan !

I was see the following usage (via require 'java') :

https://gist.github.com/1160217

I have a similar problem. I am currently working on the implementation
of Closure Templates in perl 6 for developing a Perl 5 back-end :-)

Alex


2011/10/31 Dylan Vaughn <dylanc...@gmail.com>:

Raul Rangel

unread,
Nov 2, 2011, 11:27:19 AM11/2/11
to Closure Templates Discuss
If you are using jruby then just start using it.
i.e)
@injector = com.google.inject.Guice.createInjector(
com.google.template.soy.SoyModule.new,
com.google.template.soy.xliffmsgplugin.XliffMsgPluginModule.new,
com.example.utility.CustomSoyModule.new
)
...

sfs =
@injector.getInstance(com.google.template.soy.SoyFileSet::Builder.java_class)

soyfileset.add(soy_template, ".")

etc.

It's really straight forward.

Raul
> 1.  http://code.google.com/closure/templates/docs/concepts.html#compilerb...

Dylan Vaughn

unread,
Nov 2, 2011, 2:27:02 PM11/2/11
to closure-temp...@googlegroups.com
I hadn't planned on using jruby for this project. I will play with it
a little and see if I can get it working. Probably easier than trying
to write a new MRI ruby back-end :).

Dylan Vaughn

unread,
Nov 11, 2011, 3:15:57 AM11/11/11
to closure-temp...@googlegroups.com
I ended up writing a little gem that helps with using Closure
Templates in jRuby apps - check it out:

https://github.com/dylanvaughn/closure-templates

Thanks!

Dylan

Reply all
Reply to author
Forward
0 new messages