Medium / soynode

Utility for working with Closure Templates, aka Soy, from with a node.js application.
Other
90 stars 27 forks source link

loadCompiledTemplates with closure style soy.js files #22

Closed nalbion closed 10 years ago

nalbion commented 10 years ago

Could you please provide an example of how to use soynode.loadCompiledTemplates() with pre-compiled .soy.js files?

My .soy.js files look like this, and soynode throws Fatal error: Object [object Object] has no method 'provide'

goog.provide('demo.soy');

goog.require('soy');
goog.require('soydata');

/**
 * @param {Object.<string, *>=} opt_data
 * @param {(null|undefined)=} opt_ignored
 * @return {string}
 * @notypecheck
 */
demo.soy.helloWorld = function(opt_data, opt_ignored) {
  return '<div>hello ' + ((opt_data.name) ? opt_data.name : 'world') + '</div>';
};
nalbion commented 10 years ago

...I've tried soynode.setOptions({ contextJsPaths: closurePath + '/closure/goog/base.js' }); and soynode.setOptions({ contextJsPaths: closurePath + '/closure/goog/bootstrap/nodejs.js' });

...but that didn't seem to work...

dpup commented 10 years ago

You need to compile without --shouldProvideRequireSoyNamespaces

nicks commented 10 years ago

?

that doesn't sound right.

isn't the soyutils support code supposed to declare this? https://github.com/Medium/closure-templates/blob/master/javascript/soyutils.js#L43

if goog isn't defined, that probably means the support code isn't loading properly

dpup commented 10 years ago

soyutils doesn't stub out goog.provide and require.

nicks commented 10 years ago

ah you're right

nalbion commented 10 years ago

Is there a way that I can use soynode with goog.provide/require()? My front-end uses closure and it makes sense to use the same soy.js file...

dpup commented 10 years ago

You'd probably need to monkey patch soyutils that soynode sucks in.

-- Dan

On Thu, Jun 12, 2014 at 3:14 PM, Nicholas Albion notifications@github.com wrote:

Is there a way that I can use soynode with goog.provide/require()? My front-end uses closure and it makes sense to use the same soy.js file...

— Reply to this email directly or view it on GitHub https://github.com/Medium/soynode/issues/22#issuecomment-45954879.

nalbion commented 10 years ago

No luck there - even with soynode.js hacked with var PATH_TO_SOY_UTILS = closureTemplates['soyutils_usegoog.js'] and my app with:

contextJsPaths: [
    closurePath + '/closure/goog/base.js',
    closurePath + '/closure/goog/bootstrap/nodejs.js'
]

I get Fatal error: goog is not defined when trying to run soyutils_usegoog.js:39:1

I think I'll just have to generate a second version of the .soy.js files into a different location. ...it only takes a moment...