Revisions
-
cesine revised this gist
Oct 26, 2012 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,9 +62,15 @@ function compileHandlebarsTemplate(file, onComplete) { } var handlebarsjs = fs.readFileSync('../../assets/handlebars.min.js', 'utf8') var emberjs = fs.readFileSync('js/libs/ember-latest.js', 'utf8') //var templatesDir = 'templates' /* Sample usage $ npm install optimist $ node compile_handlebars.js templates/* --output js/libs/compiled_templates.js */ var usage = '\n \ Precompile handlebar templates for Ember.js.\n \ @@ -94,4 +100,4 @@ function main(){ }); } main(); -
gabrielgrant revised this gist
Sep 15, 2012 . 1 changed file with 58 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,27 @@ var fs = require('fs'); var path = require('path'); var vm = require('vm'); var argv = require('optimist').argv; function compileHandlebarsTemplate(file, onComplete) { //dummy jQuery var jQuery = function () { return jQuery } jQuery.ready = function () { return jQuery } jQuery.inArray = function () { return jQuery } jQuery.jquery = "1.7.1" jQuery.event = { fixHooks: {} } //dummy DOM element var element = { firstChild: function () { return element }, innerHTML: function () { return element } } var sandbox = { // DOM document: { createRange: false, createElement: function () { return element } }, // Console @@ -39,33 +36,62 @@ function compileHandlebarsTemplate(templatesDir, fileName) { // compiled handlebars template templatejs: null } // window sandbox.window = sandbox // create a context for the vm using the sandbox data var context = vm.createContext(sandbox) // load Handlebars and Ember into the sandbox vm.runInContext(handlebarsjs, context, 'ember.js') vm.runInContext(emberjs, context, 'ember.js') //compile the handlebars template inside the vm context vm.runInContext('templatejs = Ember.Handlebars.precompile(template).toString()', context) var fileName = path.basename(file) var namedTemplateJs = 'Ember.TEMPLATES["' + fileName.replace(/.handlebars/, '') + '"] = Ember.Handlebars.template(' + context.templatejs + ');' return namedTemplateJs; //extract the compiled template from the vm context and save to .js file, //implicitely adding template to Ember.TEMPLATES when it is required } var handlebarsjs = fs.readFileSync('polldemo/polldemo/polls/static/polls/lib/handlebars-1.0.0.beta.6.js', 'utf8') var emberjs = fs.readFileSync('polldemo/polldemo/polls/static/polls/lib/ember-1.0.pre.js', 'utf8') var templatesDir = 'polldemo/polldemo/polls/static/polls/templates' var usage = '\n \ Precompile handlebar templates for Ember.js.\n \ Usage: ' + argv.$0 + ' template...\n\n \ Options:\n \ -f, --output Output File\n' function main(){ if ((argv.h)||(argv.help)) { console.log(usage); process.exit(0); } var inputFiles = argv._; var outputFile = argv.output || argv.f; if (outputFile) { // create a blank output file fs.writeFileSync(outputFile, '', 'utf8'); function write(output){ fs.appendFileSync(outputFile, output + '\n', 'utf8'); } } else { var write = console.log; } inputFiles.forEach(function(fileName){ write(compileHandlebarsTemplate(fileName)); }); } main(); -
zilkey renamed this gist
Mar 10, 2012 . 1 changed file with 20 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,13 @@ var fs = require('fs'); var vm = require('vm'); var emberjs = fs.readFileSync('public/javascripts/vendor/ember-0.9.5.min.js', 'utf8'); var templatesDir = 'templates'; var destinationDir = 'public/javascripts/templates'; function compileHandlebarsTemplate(templatesDir, fileName) { var file = templatesDir + '/' + fileName; //dummy jQuery var jQuery = function() { return jQuery; }; jQuery.ready = function() { return jQuery; }; @@ -64,6 +53,19 @@ function compileHandlebarsTemplate(file) { //compile the handlebars template inside the vm context vm.runInContext('templatejs = Ember.Handlebars.precompile(template).toString();', context); var namedTemplateJs = 'Ember.TEMPLATES["' + fileName.replace(/.handlebars/, '') + '"] = Handlebars.template(' + context.templatejs + ');'; //extract the compiled template from the vm context and save to .js file fs.writeFileSync(file.replace(/\.handlebars$/, '.js').replace(templatesDir, destinationDir), namedTemplateJs, 'utf8'); } console.log('Compiling .handlebars templates'); var files = fs.readdirSync(templatesDir); var i; for (i = 0; i < files.length; i++) { if (/\.handlebars$/.test(files[i])) { compileHandlebarsTemplate(templatesDir, files[i]); process.stdout.write('.'); } } console.log('done'); -
garth revised this gist
Jan 16, 2012 . 3 changed files with 69 additions and 53 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ var fs = require('fs'); var vm = require('vm'); var emberjs = fs.readFileSync('path/to/ember.js', 'utf8'); var templatesDir = 'path/to/template/dir'; desc('Compile all .handlebars templates'); task({ 'handlebars': [] }, function () { process.stdout.write('Compiling .handlebars templates'); var files = fs.readdirSync(templatesDir); var i; for (i = 0; i < files.length; i++) { if (/\.handlebars$/.test(files[i])) { compileHandlebarsTemplate(templatesDir + '/' + files[i]); process.stdout.write('.'); } } console.log('done'); }); function compileHandlebarsTemplate(file) { //dummy jQuery var jQuery = function() { return jQuery; }; jQuery.ready = function() { return jQuery; }; jQuery.inArray = function() { return jQuery; }; jQuery.jquery = "1.7.1"; //dummy DOM element var element = { firstChild: function () { return element; }, innerHTML: function () { return element; } }; var sandbox = { // DOM document: { createRange: false, createElement: function() { return element; } }, // Console console: console, // jQuery jQuery: jQuery, $: jQuery, // handlebars template to compile template: fs.readFileSync(file, 'utf8'), // compiled handlebars template templatejs: null }; // window sandbox.window = sandbox; // create a context for the vm using the sandbox data var context = vm.createContext(sandbox); // load Ember into the sandbox vm.runInContext(emberjs, context, 'ember.js'); //compile the handlebars template inside the vm context vm.runInContext('templatejs = Ember.Handlebars.precompile(template).toString();', context); //extract the compiled template from the vm context and save to .js file fs.writeFileSync(file.replace(/\.handlebars$/, '.js'), context.templatejs, 'utf8'); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +0,0 @@ -
wagenet renamed this gist
Jan 13, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
wagenet created this gist
Jan 13, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ require 'execjs' class HandlebarsFilter < Filter class << self def contents @@contents ||= [File.read("headless-ember.js"), File.read("ember.js")].join("\n") end def context @@context ||= ExecJS.compile(contents) end end def generate_output(inputs, output) inputs.each do |input| name = File.basename(input.path, '.handlebars') compiled = self.class.context.call("precompileEmberHandlebars", input.read) output.write "\nEmber.TEMPLATES['#{name}'] = Ember.Handlebars.template(#{compiled});\n" end end end input "templates" output "output" match "*.handlebars" do filter HandlebarsFilter concat "templates.js" end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // DOM var Element = {}; Element.firstChild = function () { return Element; }; Element.innerHTML = function () { return Element; }; var document = { createRange: false, createElement: function() { return Element; } }; var window = this; this.document = document; // Console var console = window.console = {}; console.log = console.info = console.warn = console.error = function(){}; // jQuery var jQuery = function() { return jQuery; }; jQuery.ready = function() { return jQuery; }; jQuery.inArray = function() { return jQuery; }; jQuery.jquery = "1.7.1"; var $ = jQuery; // Ember function precompileEmberHandlebars(string) { return Ember.Handlebars.precompile(string).toString(); }