Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modifications to the file pre-compilation step

  • Loading branch information...
commit f3c90a8e8880d4f3d8b5f98a919d985d3fb02c0c 1 parent 91d649b
Laura Doktorova authored
Showing with 19 additions and 9 deletions.
  1. +2 −2 README.md
  2. +2 −1  bin/{dottojs → dot-packer}
  3. +15 −6 index.js
4 README.md
View
@@ -33,9 +33,9 @@ Added parameters support in partials:
{{#def.macro:myvariable}}
-Compile tool to compile dot templates into js (thanks to @Katahdin https://github.com/Katahdin/dot-packer ):
+Compile tool to compile dot templates into js files (thanks to @Katahdin https://github.com/Katahdin/dot-packer ):
- ./bin/dottojs -s examples/views -d out/views
+ ./bin/dot-packer -s examples/views -d out/views
## Notes:
doU.js is here only so that legacy external tests do not break. Use doT.js.
3  bin/dottojs → bin/dot-packer
View
@@ -1,4 +1,5 @@
#!/usr/bin/env node
+/* Continuation of https://github.com/Katahdin/dot-packer */
var program = require('commander'),
dot = require('../');
@@ -8,7 +9,7 @@ program
.usage('dottojs')
.option('-s, --source [value]', 'source folder/file path')
.option('-d, --dest [value]', 'destination folder')
- .option('-g, --global [value]', 'the global variable to install the templates in',"_render")
+ .option('-g, --global [value]', 'the global variable to install the templates in',"window.render")
.option('-p, --package [value]', 'if specified, package all templates from destination folder into specified file')
.parse(process.argv);
21 index.js
View
@@ -11,7 +11,8 @@
* can be accessed as renderer.filename
* Files with .jst extension are compiled into .js files. Produced .js file can be
* loaded as a commonJS, AMD module, or just installed into a global variable
- * (default is set to _render). All inline defines defined in the .jst file are
+ * (default is set to window.render).
+ * All inline defines defined in the .jst file are
* compiled into separate functions and are available via _render.filename.definename
*
* Basic usage:
@@ -39,7 +40,7 @@ function InstallDots(o) {
if (this.__path[this.__path.length-1] !== '/') this.__path += '/';
this.__destination = o.destination || this.__path;
if (this.__destination[this.__destination.length-1] !== '/') this.__destination += '/';
- this.__global = o.global || "_render";
+ this.__global = o.global || "window.render";
this.__rendermodule = o.rendermodule || {};
this.__settings = o.templateSettings ? copy(o.templateSettings, copy(doT.templateSettings)) : undefined;
this.__includes = {};
@@ -52,7 +53,7 @@ InstallDots.prototype.compileToFile = function(path, template, def) {
, settings = this.__settings || doT.templateSettings
, compileoptions = copy(settings)
, defaultcompiled = doT.template(template, settings, defs)
- , exports = "dot:" + modulename
+ , exports = []
, compiled = ""
, fn;
@@ -69,17 +70,25 @@ InstallDots.prototype.compileToFile = function(path, template, def) {
}
if (fn) {
compiled += fn.toString().replace('anonymous', property);
- exports += ',' + property + ":" + property;
+ exports.push(property);
}
}
}
compiled += defaultcompiled.toString().replace('anonymous', modulename);
fs.writeFileSync(path, "(function(){" + compiled
- + "var itself={" + exports
- + "};if(typeof module!=='undefined' && module.exports) module.exports=itself;else if(typeof define==='function')define(function(){return itself;});else {"
+ + "var itself=" + modulename + ";"
+ + addexports(exports)
+ + "if(typeof module!=='undefined' && module.exports) module.exports=itself;else if(typeof define==='function')define(function(){return itself;});else {"
+ this.__global + "=" + this.__global + "||{};" + this.__global + "['" + modulename + "']=itself;}}());");
};
+function addexports(exports) {
+ for (var ret ='', i=0; i< exports.length; i++) {
+ ret += "itself." + exports[i]+ "=" + exports[i]+";";
+ }
+ return ret;
+}
+
function copy(o, to) {
to = to || {};
for (var property in o) {
Please sign in to comment.
Something went wrong with that request. Please try again.