Client-side templates w/o Closure Library

26 views
Skip to first unread message

Rob Figueiredo

unread,
Jul 27, 2015, 6:43:06 PM7/27/15
to plovr
Hi all,

I would like to share templates between the client and server, and I was hoping to get advice on the right approach.  Here are some details about my situation:
  • We do not use Closure Library, but we do use Closure Compiler via Plovr (SIMPLE_OPTIMIZATIONS).
  • Both our javascript and our templates reside under a company.* javascript namespace using a simple in-house system similar to goog.provide, but no goog.require -- dependencies are not explicitly declared.  We declare "company" as a js extern in our prod-config.js.
I got something simple to work using plovr after switching the top level of our soy namespace to soy.* from company.*.  Otherwise plovr returns "ERROR - Variable company first declared in ... prod-externs.js".  The main remaining issue is i18n.

## Variation #1 - Add Closure
I added goog.require('soy.namespace') to javascript files that used it. This causes that namespace of soy functions to be generated.  I think I would have to reassign goog.getMsg to my custom lookup function to work with our i18n situation.  Also, it makes me a little nervous since we don't use otherwise goog.provide or goog.require anything. 

## Variation #2 - No Closure
I used the experimental-exclude-closure-library option and explicitly list the transitive set of soy templates to include in the plovr config.  This is similar to our current JS situation (not great I know), but it does not appear this mode allows for i18n message lookup.  Ideally I would like to wrap messages in a JS call "company.msg('message text')" which can access a lookup map that we ship with the page.  I suspect that is a hard change to make, deep in Soy JsSrc compiler though.

I'm leaning towards the "Add Closure" variation since the i18n problem seems easier to resolve, and maybe that can be the start of using goog.require / goog.provide more broadly.  

Anyone have thoughts on the approach or other ideas? 

Thank you,
Rob
Reply all
Reply to author
Forward
0 new messages