Unique name for client compiled template function

34 views
Skip to first unread message

GJ Coombes

unread,
Jul 8, 2014, 4:56:56 AM7/8/14
to jad...@googlegroups.com
Hi all,

The client option compiles templates with a generic function name of 'template'.
This makes combining a number of these functions into one file a bit difficult.

There are some options for renaming these functions with the grunt/gulp workflow
like here [0] and here [1] but these seem heavyweight, where a small change to the jade source could write function names based upon the template filename.

How might a pull request be regarded by the development team that accomplishes
'user.jade' -> 'user.js' with function 'userTemplate'

// lib/jade.js from line 225 or so

  var trim = function(name) {
    return filename.replace(/^.*[\\\/]/, '').slice(0, -6);
  }
  return 'function ' + trim(filename) + 'Template(locals) {\n'  + fn + '\n}';

There are more elegant solutions using the path library, but a solution without an extra dependency might be preferred.

I'd welcome any comments or suggestions,

Cheers, Gavin.

[0] http://stackoverflow.com/questions/22234869/compile-client-side-jade-templates-using-gulpjs
[1] http://programanddesign.com/php/compile-all-jade-files-to-a-single-client-side-javascript-file/

GJ Coombes

unread,
Jul 8, 2014, 5:22:09 AM7/8/14
to jad...@googlegroups.com
--Small edit--
I think I probably want a slightly different slice, like

filename.replace(/^.*[\\\/]/, '').slice(1, -6);

Gavin.

Reply all
Reply to author
Forward
0 new messages