Hi, I updated the whole template plugin based on current text loader plugin implementation and underscore template plugin #8

Open
wants to merge 3 commits into
from

Conversation

Projects
None yet
8 participants

eeroan commented Oct 19, 2012

Now it works with latest r.js and require.js versions both with node and java

@eeroan eeroan Support latest require.js by using current implementation of text plu…
…gin and also latest verison of Underscore.template
5bc85bc

eeroan commented Dec 11, 2012

Here's a gentre reminder for accepting this pull requiest :). It works with latest require.js and r.js versions (2.1.2) and supports bundling with both node and rhino unlike the current one

I now use it and it works great
👍

I third the motion! lets merge this in!

+1

What's the advantage of embedding text.js and underscore's templating in tpl.js? Why not load them in as external dependencies, and tell people they need them too? That'd make PRs like this unnecessary.

For example: https://github.com/dawsontoth/requirejs-tpl/blob/master/tpl.js

eeroan commented Jan 9, 2013

I totally aggree with you, but I couldn't make it work with the bundling. I tried to use the json loader plugin as an example until I discovered that I does not work either for bundles :(

If you find a way to make it work I'm more than hapy. I also remember that there where some problems when using relative paths for templates, like tpl!./template.html

Eero Anttila

Dawson Toth notifications@github.com kirjoitti 9.1.2013 kello 20.19:

What's the advantage of embedding text.js and underscore's templating in tpl.js? Why not load them in as external dependencies, and tell people they need them too? That'd make PRs like this unnecessary.

For example: https://github.com/dawsontoth/requirejs-tpl/blob/master/tpl.js


Reply to this email directly or view it on GitHub.

K! I'll look in to it. I bet I'll fail if you couldn't figure it out, but at least I'll have tons of fun in the process. ;)

ingro commented Jan 17, 2013

+1!

+1

Fixed it. Now it works for me doing both: 1) dynamic inclusion, and 2) bundling. I also added some very verbose log output when attempting to compile invalid templates. https://github.com/dawsontoth/requirejs-tpl/blob/master/tpl.js Note that I set { variable: 'data' } as my default options in tpl.js (for performance of ease of falsy checking). If you want other settings, do it there.

Example bundled output (note that the text! is included too... not optimal, I know):

define('tpl!views/common/charts/templates/loader.html',[],function() { return function(data){
var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
__p+='<div class="charts_container charts_container_'+
((__t=( data.type ))==null?'':_.escape(__t))+
'">\n</div>';
return __p;
} });
define('text!views/common/charts/templates/loader.html',[],function () { return '<div class="charts_container charts_container_<%- data.type %>">\n</div>';});

eeroan commented Jan 21, 2013

Cool! It works. Great work!

Could it be somehow possible to read the template settings from requirejs global settings? Do you have experience?
Then a minor thing: should the opening curly brace be on the same line instead of new line?

On 17.1.2013, at 23.40, Dawson Toth wrote:

Fixed it. Now it works for me doing both: 1) dynamic inclusion, and 2) bundling. I also added some very verbose log output when attempting to compile invalid templates. https://github.com/dawsontoth/requirejs-tpl/blob/master/tpl.js Note that I set { variable: 'data' } as my default options in tpl.js (for performance of ease of falsy checking). If you want other settings, do it there.

Example bundled output (note that the text! is included too... not optimal, I know):

define('tpl!views/common/charts/templates/loader.html',[],function() { return function(data){
var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
__p+='

\n
';
return __p;
} });
define('text!views/common/charts/templates/loader.html',[],function () { return '
\n
';});

Reply to this email directly or view it on GitHub.

Eero Anttila eero.anttila@iki.fi
+358 50 359 0079

I wonder if you can use module config:
http://requirejs.org/docs/api.html#config-moduleconfig

So instead of:

var settings = { variable: 'data' };

You could do:

var settings = _.defaults(module.config() || {}, { variable: 'data' });

And in theory you could should be able to define the settings in Require's
config:

requirejs.config({
config: {
tpl: { interpolate : /{{(.+?)}}/g }
}
});

Would need to test to make sure the whole thing works...

On Mon, Jan 21, 2013 at 5:16 AM, Eero Anttila notifications@github.comwrote:

Cool! It works. Great work!

Could it be somehow possible to read the template settings from requirejs
global settings? Do you have experience?
Then a minor thing: should the opening curly brace be on the same line
instead of new line?

On 17.1.2013, at 23.40, Dawson Toth wrote:

Fixed it. Now it works for me doing both: 1) dynamic inclusion, and 2)
bundling. I also added some very verbose log output when attempting to
compile invalid templates.
https://github.com/dawsontoth/requirejs-tpl/blob/master/tpl.js Note that
I set { variable: 'data' } as my default options in tpl.js (for performance
of ease of falsy checking). If you want other settings, do it there.

Example bundled output (note that the text! is included too... not
optimal, I know):

define('tpl!views/common/charts/templates/loader.html',[],function() {
return function(data){
var
__t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};

__p+='

\n
';
return __p;
} });
define('text!views/common/charts/templates/loader.html',[],function () {
return '
\n
';});

Reply to this email directly or view it on GitHub.

Eero Anttila eero.anttila@iki.fi
+358 50 359 0079


Reply to this email directly or view it on GitHubhttps://github.com/ZeeAgency/requirejs-tpl/pull/8#issuecomment-12493518.

Nice points, @eeroan and @aglemann. I've just pushed some changes. They work in my project great. I've also changed it back to use the default settings for better compatibility (and then you can override via the module config).

eeroan commented Jan 22, 2013

Found something interesting: With this version where text plugin is included as dependency this is what happens for minified version:

define('text!app/navigation.html',[],function () { return '<header id="header" class="siteContent">\n  <h1 class="logo"><a href="#">Logo</a></h1>\n</header>\n';});

define('tpl!app/navigation.html',[],function() { return function(obj){
var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
with(obj||{}){
__p+='<header id="header" class="siteContent">\n  <h1 class="logo"><a href="#">Logo</a></h1>\n</header>\n';
}
return __p;
} });

So each template is introduced twice: on version for text plugin and another for tpl.

Fixed.

nuragic commented Mar 6, 2015

Hi! Briefly... How the templateSettings can be overridden?

eeroan commented Mar 9, 2015

By using module config (see above) with this fork: https://github.com/dawsontoth/requirejs-tpl/blob/master/tpl.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment