Requiring a closure-stylesheet css renaming map from a soy template

265 views
Skip to first unread message

Matt Powell

unread,
Apr 10, 2012, 2:55:47 AM4/10/12
to closure-temp...@googlegroups.com
I'm using soy templates to render full html pages (the templates are compiled to js and executed w/ nodejs). I'm also using closure-stylesheets (gss) with --output-renaming-map-format set to CLOSURE_COMPILED. This generates a js file that calls goog.setCssNameMapping with a map of the shortened classnames. The part I'm stuck on is making the generated js file a dependency of the template that it needs to be used in. Ideally, I'd prepend the generated js file w/ a goog.provide call and I'd have a custom soy function that would set a flag to add a goog.require call referencing the generated js file from the compiled template. (btw, I'm compiling the templates w/ shouldProvideRequireSoyNamespaces and node is taking care of the goog.provide and goog.require calls).

Here's what it'd look like in actual code:

===map.js===
//generated from gss file
goog.provide('namespace.map');
goog.setCssNameMapping({'long-name':'a'});
========

===template.soy===
{template ...}
  {cssNameMapping('namespace.map')/}
  <span class="{css long-name}"></span>
{/template}
========

===template.soy.js===
//executed from within node
goog.require('soy');
goog.require('namespace.map');

namespace.template = function(){return '<span class="'+goog.getCssName('long-name')+'"></span>'}
========


cssNameMapping would be an implementation of SoyJsSrcFunction, but, would somehow tell the compiler to add a goog.require statement w/ the first passed in parameter ('namespace.map').

So, think some variation of this is possible? And if so, tips on where I should start looking?

Thanks,

Matt

Kyaw

unread,
May 28, 2012, 11:06:11 PM5/28/12
to Closure Templates Discuss
you shouldn't need cssNameMapping in template.soy.

Michael Bolin

unread,
May 30, 2012, 5:21:05 PM5/30/12
to closure-temp...@googlegroups.com
Use {css long-name} in Soy, but you also need to pass --cssHandlingScheme=goog when generating the JS from the Soy. Unfortunately, I don't see that flag listed on https://developers.google.com/closure/templates/docs/javascript_usage, but you can find it in the source code: http://code.google.com/p/closure-templates/source/browse/trunk/java/src/com/google/template/soy/SoyToJsSrcCompiler.java
Reply all
Reply to author
Forward
0 new messages