Permalink
Browse files

Adding in initial files

  • Loading branch information...
SlexAxton committed Sep 2, 2011
1 parent 8ea6971 commit abc92ae8e39f94ef66c3bf2e3ff0b227775a3b7f
Showing with 111 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +11 −0 .npmignore
  3. +78 −0 lib/main.js
  4. +16 −0 package.json
View
@@ -0,0 +1,6 @@
+dist
+vendor
+.rvmrc
+.DS_Store
+lib/handlebars/compiler/parser.js
+node_modules
View
@@ -0,0 +1,11 @@
+.DS_Store
+.gitignore
+.rvmrc
+Gemfile
+Gemfile.lock
+Rakefile
+bench/*
+dist/*
+spec/*
+src/*
+vendor/*
View
@@ -0,0 +1,78 @@
+var Handlebars = require('handlebars');
+
+var SC = { Handlebars : {} };
+
+SC.Handlebars.Compiler = function() {};
+SC.Handlebars.Compiler.prototype = Object.create( Handlebars.Compiler.prototype );
+SC.Handlebars.Compiler.prototype.compiler = SC.Handlebars.Compiler;
+
+SC.Handlebars.JavaScriptCompiler = function() {};
+SC.Handlebars.JavaScriptCompiler.prototype = Object.create(Handlebars.JavaScriptCompiler.prototype);
+SC.Handlebars.JavaScriptCompiler.prototype.compiler = SC.Handlebars.JavaScriptCompiler;
+
+/**
+ Override the default property lookup semantics of Handlebars.
+
+ By default, Handlebars uses object[property] to look up properties. SproutCore's Handlebars
+ uses SC.get().
+
+ @private
+*/
+SC.Handlebars.JavaScriptCompiler.prototype.nameLookup = function(parent, name, type) {
+ if (type === 'context') {
+ return "SC.get(" + parent + ", " + this.quotedString(name) + ");";
+ } else {
+ return Handlebars.JavaScriptCompiler.prototype.nameLookup.call(this, parent, name, type);
+ }
+};
+
+SC.Handlebars.JavaScriptCompiler.prototype.initializeBuffer = function() {
+ return "''";
+};
+
+/**
+ Override the default buffer for SproutCore Handlebars. By default, Handlebars creates
+ an empty String at the beginning of each invocation and appends to it. SproutCore's
+ Handlebars overrides this to append to a single shared buffer.
+
+ @private
+*/
+SC.Handlebars.JavaScriptCompiler.prototype.appendToBuffer = function(string) {
+ return "data.buffer.push("+string+");";
+};
+
+/**
+ Rewrite simple mustaches from {{foo}} to {{bind "foo"}}. This means that all simple
+ mustaches in SproutCore's Handlebars will also set up an observer to keep the DOM
+ up to date when the underlying property changes.
+
+ @private
+*/
+SC.Handlebars.Compiler.prototype.mustache = function(mustache) {
+ if (mustache.params.length || mustache.hash) {
+ return Handlebars.Compiler.prototype.mustache.call(this, mustache);
+ } else {
+ var id = new Handlebars.AST.IdNode(['bind']);
+
+ // Update the mustache node to include a hash value indicating whether the original node
+ // was escaped. This will allow us to properly escape values when the underlying value
+ // changes and we need to re-render the value.
+ if(mustache.escaped) {
+ mustache.hash = mustache.hash || new Handlebars.AST.HashNode([]);
+ mustache.hash.pairs.push(["escaped", new Handlebars.AST.StringNode("true")]);
+ }
+ mustache = new Handlebars.AST.MustacheNode([id].concat([mustache.id]), mustache.hash, !mustache.escaped);
+ return Handlebars.Compiler.prototype.mustache.call(this, mustache);
+ }
+};
+
+SC.Handlebars.precompile = function(string) {
+ var options = { data: true, stringParams: true };
+
+ var ast = Handlebars.parse(string);
+
+ var environment = new SC.Handlebars.Compiler().compile(ast, options);
+ return new SC.Handlebars.JavaScriptCompiler().compile(environment, options);
+};
+
+exports.precompile = SC.Handlebars.precompile;
View
@@ -0,0 +1,16 @@
+{ "name" : "sc-handlebars-precompiler"
+, "description" : "Sproutcore Handlebars Precompiler"
+, "version" : "1.0.2beta"
+, "homepage": "http://www.handlebarsjs.com/"
+, "author" : "Alex Sexton <Alex.Sexton@bazaarvoice.com>"
+, "engines" : ["node >=0.4.7"]
+, "keywords": "sproutcore precompile handlebars mustache template html"
+, "repository": {
+ "type": "git",
+ "url": "git://github.com/SlexAxton/sc-handlebars-precompiler.git"
+ },
+, "main" : "./lib/main"
+, "dependencies": {
+ "handlebars": "1.0.x"
+}
+}

0 comments on commit abc92ae

Please sign in to comment.