Permalink
Browse files

fixed handling of @(). added ability to embedd Bliss in HTML pages.

  • Loading branch information...
1 parent 2804802 commit d8b4cdbaeb4a026049edf8377a408abb9b4b3673 @cstivers78 committed Jan 25, 2012
View
@@ -1,18 +1,17 @@
-var Bliss, Tokenizer, Writer, fs, path, tokenizer,
+var Bliss, Tokenizer, Writer, fs, path,
__slice = Array.prototype.slice;
-fs = require('fs');
+if (module !== void 0) {
+ fs = require('fs');
+ path = require('path');
+ Writer = require('./writer');
+ Tokenizer = require('./tokenizer');
+}
-path = require('path');
+Bliss = (function() {
+ var defaults, tokenizer;
-Writer = require('./writer');
-
-Tokenizer = require('./tokenizer');
-
-tokenizer = new Tokenizer();
-
-module.exports = Bliss = (function() {
- var defaults;
+ tokenizer = new Tokenizer();
function Bliss(options) {
this.options = options;
@@ -57,13 +56,21 @@ module.exports = Bliss = (function() {
writer.write(tokenizer.tokenize(source));
tmplParams = writer.parameters;
tmplSource = writer.source(context);
- func = Function.apply(null, __slice.call(tmplParams).concat([tmplSource]));
- tmpl = func.bind(context);
- tmpl.filename = options.filename;
- tmpl.toString = func.toString.bind(func);
- tmpl.toSource = function() {
- return source;
- };
+ console.log("~~~~~~~~~~");
+ console.log(tmplSource);
+ console.log("~~~~~~~~~~");
+ try {
+ func = Function.apply(null, __slice.call(tmplParams).concat([tmplSource]));
+ tmpl = func.bind(context);
+ tmpl.filename = options.filename;
+ tmpl.toString = func.toString.bind(func);
+ tmpl.toSource = function() {
+ return source;
+ };
+ } catch (error) {
+ error.templateSource = tmplSource;
+ throw error;
+ }
return tmpl;
};
@@ -126,3 +133,5 @@ module.exports = Bliss = (function() {
return Bliss;
})();
+
+if (module !== void 0) module.exports = Bliss;
View
@@ -0,0 +1,3 @@
+var module;
+
+module = void 0;
View
@@ -0,0 +1,35 @@
+
+this.Bliss = Bliss;
+
+this.bliss = new Bliss();
+
+this.bliss.compileNode = function(node) {
+ var id, output, source, template;
+ id = node.id;
+ source = node.innerHTML;
+ if (source) {
+ template = bliss.compile(source, {
+ context: window
+ });
+ if (id && window) {
+ window[id] = template;
+ node.parentNode.removeChild(node);
+ } else {
+ output = document.createElement("div");
+ output.innerHTML = template();
+ node.parentNode.replaceChild(output, node);
+ }
+ }
+};
+
+this.bliss.compileNodeList = function(nodeList) {
+ var node, _i, _len;
+ for (_i = 0, _len = nodeList.length; _i < _len; _i++) {
+ node = nodeList[_i];
+ try {
+ this.compileNode(node);
+ } catch (error) {
+ console.error('[error]', error);
+ }
+ }
+};
Oops, something went wrong.

0 comments on commit d8b4cdb

Please sign in to comment.