Getting error about duplicate template definitions in file with a single template definition, Google closure templates - google-closure-templates

I'm using google closure templates in java. I'm getting the following error when using the SoyFileSet builder to compile my templates to a single java object (I have many template files which I compile to a java object):
com.google.template.soy.base.SoySyntaxException: Found two definitions for template name 'namespace.qualifier.templateName', both in the file /templates/namespace/qualifier/TemplateName.soy.
The problem with this error is - for the template it is complaining about - I only have a single template defined in that file. Also, I did a file search through all of my template files to verify that was the only template I had by that name.
Anyone have any idea what my issue is?

The problem was I was adding the same template to the SoyFileSet builder twice.

Related

Liferay 7.1 npm-react-module localization

I'm trying to include localization into my npm-react-module, but I have failed receiving the value for the corresponding key from the Langugage.properties file. It simply returns the key. I did some research but I couldn't find any source that would help me solve my problem.
In the code which I will show you bellow, I have included a Language.properties file into my module. In my portlet, I have included the needed configuration for the language properties. I have also tried to add a separate file for a specific locale, but that didn't help me either.
This is an example of my portlet configuration:
"javax.portlet.resource-bundle=content.Language"
This is an example content from my Language.properties file:
example-key=example-value
This is how I'm trying to access the value in my React Component:
<h1> {Liferay.Language.get('example-key')} </h1>
But it only returns "example-key" instead of "example-value".
In my view.jsp file I am able to retrieve the corresponding values using
<liferay-ui:message key='example-key'/>
I have tried this method: https://portal.liferay.dev/docs/7-1/tutorials/-/knowledge_base/t/localizing-your-portlet but it didn't work either. Did anyone get this to work properly in their npm-react-module? I really don't want to spend time implementing my own localization service. Thanks!
Liferay.Language.get('key') gets text replaced by the build mechanism. Therefore there is no actual object/class to do this. I have been trying to get this to work myself and have resolved that I will have to do internationalization on my own.
localizing is done only in build time meaning if you have a language
key that generated dynamicly , you can't localizate it or for example
if you get a key from api fetch and need to localizate it, you can't
beacuse Liferay localization method for react (
Liferay.Language.get("yourLanguageKey") ) its undefined in runtime and
you can't use it.
from: https://npm.io/package/liferay-react-runtime-localization

Is it possible to override BakeTasks in a plugin

I want Bake to add a custom TimestampBehavior to every table which has the fields created_at, modified_at, proved_at. I also want to remove the Validators for these fields.
Whether a model is added the TimestampBehavior is programmed in Bake/src/Shell/Task/ModelTask.php. I don't want to edit the file in the vendor folder, because my file might be overridden by an update.
Moving the file to my plugins folder doesn't work since i get the error message "class ModelTask is already defined".
Is it possible to extend the ModelTask somehow or to use a custom ModelTask.php in my plugins folder for bake to achieve my goal?
Thanks for your help!
Moving the file to my plugins folder doesn't work since i get the error message "class ModelTask is already defined".
It doesn't work because you probably haven't changed the namespace. Fix the namespace to the one the plugin uses and you're done. You can even extend classes of the same name by using uses Foo as Bar and then Foo extends Bar.

How to merge multiple html files into one with brunch.js

I'm using underscore.js for my templates which are stored in multiple separate XXX_tpl.html files inside sections similar to:
<script type="text/x-template" id="tpl_XXX">
<h1>hi</h1>
</script>
Which I am then using inside backbone.js views as follows:
render: function () {
this.$el.html($('#tpl_XXX').text());
}
I am now using brunch.js build tool which nicely outputs all my libs/js/css code into several optimized files but I am having issue with managing / organizing my templates. How do I make brunch.js build tool to append all *_tpl.html files at the end of index.html? All the examples I am seeing online show how to use brunch.js to merge templates into .js files but I don't yet understand how that works (the templates are a mix of html/js and I lose both access by ID and syntax formatting/highlighting when storing templates in .js files).
Q1. If what I'm doing is right (multiple templates in multiple different .tpl.html files all appended at the end of index.html when built) then how do I make build.js merge all of that?
Q2. If what I'm doing isn't right, what's a better approach to:
have multiple templates that are organized and easily managed
not create additional http requests to pull / all compiled into a single file
have easy access from backbone.js models
want to achieve syntax highlighting in my IDE for the template markup (i.e. no JS string concatenations, etc)
Nice question, but I don't know if you understood how underscore templates should work precisely. Let's try to clear that up first.
Template compilation
An underscore template source is any text with interpolated code. For example:
var myTemplateString = "hello: <%= name %>";
When you want to use that template, you need to compile it into a function first. What? Here's how it works:
var myTemplateFunction = _.template(myTemplateString);
This creates a myTemplateFunction which contains your template logic. In a very simplified, pseudo-code way, you can expect myTemplateFunction to work somewhat like this:
function (context) { return "hello: " + context.name };
So, now you understand why you can call this function and produce a string!
myTemplateFunction({name: 'moe'}) // hello: moe
Using compiled templates
OK, but why do you need to compile it previously? Why not always call directly:
_.template(myTemplateString)({name: 'moe'})
Because compilation can be CPU-intensive. Therefore, it's much faster to use a pre-compiled template. You should not force the user's browser to do it! You should do it for him!
Delivering compiled templates
By now, you understand you don't care about delivering the text of your functions to your client, only the compiled template functions. There are many ways to accomplish that.
Brunch has a bunch of plugins for pre-compiled templates, but apparently none for underscore: http://brunch.io/plugins.html
You can use webpack and it's EJS template loader.
Your code would look something like this:
var myTemplateFunction = require('./template.html')
console.log(myTemplateFunction);
You can also use Grunt and it's underscore template task: grunt-contrib-jst.
Whichever you choose, they will all work similarly: they'll compile your template into a function and you'll be able to use that function. Personally, I recommend learning webpack!

Which JavaScript file is the angular.module() function defined in?

I was wondering if anybody knows which file the angular.module() function is defined in. I ask because when I type "angular." My IDE's auto-complete feature does not show the module method on the angular object.
Regarding the files in which the .module() is defined:
in the build version it is the main angular.js file (corresponding to the ngModule): http://code.angularjs.org/1.0.2/angular.js, check the line 1052
in the source code it is here: https://github.com/angular/angular.js/blob/master/src/loader.js#L67
You might want to search for the function module(name, requires, configFn) string to locate it in your version of AngularJS.
According to the AngularJS documentation it's in the ng module.

Google App Engine Go SDK update problems with template

I`ve just updated my GAE Go SDK to the newest release. I ran the gofix
on my code, but there were still some errors. The code used to look:
AnkietaTemp = template.New(nil)
err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
but now passing nil doesn't seem to work, so I replaced it into:
AnkietaTemp = template.New("")
_, err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
Tried running my app, but in HTML source I get:
<td width="400"><img src="images/{.section One}{#}{.end}"
alt="images/{.section One}{#}{.end}" width="100%"/></td>
Instead of a neat reference to an image file.
What is the proper way to parse the template files now, after the
update?
In the new template package the template tag syntax changed, as you can see in the documentation. E.g. dot (.) is used instead of # for referencing the "current" item and the template tags are indicated with two curly braces instead of one.
Edit: Oh, and there's no .section tag any more. You didn't provide the structure you pass to template's Execute() method so I can't provide details on how mitigate that exactly, but I guess you can use {{with}} tag like {{with One}}{.}{{end}} or maybe {{.One}}.

Resources