0

I am trying to use Google Closure templates (Soy) with Google Closure.

I am including the soyutils_usegoog.js utilities file as instructed. This file provides a number of utilities used by the generated templates, notably soy.StringBuilder. Here's how it is creating it:

soy.StringBuilder = goog.string.StringBuffer;

The soyutils file requires goog.string.StringBuffer a few lines above, but when running in non-compiled mode this results in a runtime error because the JS file that StringBuffer resides in will not be loaded until after soyutils has executed.

Unless I am mistaken, JS files in Closure should not immediately access namespaces that they 'require'. The <script> tag is only added after the execution of the current script (in non-compiled mode) so immediate usage will result in a runtime error.

In short, how can I load in soyutils_usegoog.js without triggering a runtime error due to the early access of good.string.StringBuffer.

4

2 回答 2

1

您是否使用已编译的模板作为输入(和soyutils_usegoog.js)重新创建 deps.js?然后你是在goog.require-ing 你的模板吗?像这样的东西应该工作:

<script src="/closure-library/closure/goog/base.js"></script>
<script src="/closure-library/closure/goog/deps.js"></script><!-- might not need this line if base.js is setup to auto include deps.js -->
<script>
    goog.require('your.template');//this will pull in and execute all the dependencies (including StringBuffer) for your template
</script>
<script>
    alert(your.template());
</script>
于 2012-01-01T17:50:10.690 回答
0

也许已经在http://groups.google.com/group/closure-templates-discuss上提出了这个问题?

于 2011-11-21T16:34:36.590 回答