Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gruntjs changing underscore template delimiters

I'm trying to generate a JSP page, and since the template delimiters used by JSP's are the same as the ones used by underscore.

looking at the docs --> https://github.com/gruntjs/grunt/wiki/grunt.template#wiki-grunt-template-setDelimiters i can see they have a function for that

grunt.template.addDelimiters(name, opener, closer)

Two questions:

  1. Where would i call that function ?
  2. Can i change the delimiters only for a grunt.template.process() ( i have more than one, and for other non .jsp templates, the default delimiters are fine ) ?

Any help is appreciated. Thanks.

like image 730
mfreitas Avatar asked May 22 '13 08:05

mfreitas


1 Answers

from the documentation for grunt.template.process:

The default template delimiters are <% %> but if options.delimiters is set to a custom delimiter name, those template delimiters will be used instead.

that basically would mean that you can call grunt.template.process with the name of the delimiter you added before.

e.g. if you want to use square-brackets as delimiters in one processing step that should do the job:

// first add the new delimiters which you want to use
grunt.template.addDelimiters('square-brackets', '[', ']');

//  and use it
grunt.template.process(template, {delimiters: 'square-brackets'});

// and use it with the default delimiters (named 'config')
grunt.template.process(template);
like image 129
hereandnow78 Avatar answered Oct 01 '22 07:10

hereandnow78