Browse files

small refactor

  • Loading branch information...
1 parent 823485a commit 18806921841586c86fd496f2307bda3548d77cb3 @chjj committed Mar 7, 2012
Showing with 44 additions and 40 deletions.
  1. +1 −1 lib/liquor.js
  2. +43 −39 lib/liquor_minimal.js
View
2 lib/liquor.js
@@ -62,7 +62,7 @@ var each = function(obj, func) {
liquor.compile = liquor;
-if (typeof module !== 'undefined' && module.exports) {
+if (typeof module !== 'undefined') {
module.exports = liquor;
} else {
this.liquor = liquor;
View
82 lib/liquor_minimal.js
@@ -11,32 +11,6 @@
*/
var liquor = (function() {
- var each = function(obj, func) {
- if (!obj) return;
-
- var l = obj.length
- , i = 0;
-
- if (typeof l === 'number' && typeof obj !== 'function') {
- for (; i < l; i++) {
- if (func.call(obj[i], obj[i], i, obj) === false) {
- break;
- }
- }
- } else {
- var keys = Object.keys(obj)
- , l = keys.length
- , key;
-
- for (; i < l; i++) {
- key = keys[i];
- if (func.call(obj[key], obj[key], key, obj) === false) {
- break;
- }
- }
- }
- };
-
var rules = {
iterate: /^( *)@:([^\s]+) *([^\n]*(?:\n+\1 {2}[^\n]*)*)/,
condition: /^( *)(?:\?|(!)):([^\s]+) *([^\n]*(?:\n+\1 {2}[^\n]*)*)/,
@@ -45,18 +19,6 @@ var liquor = (function() {
text: /^[^\0]+?(?= *@:| *\?:| *!:|`|#{|$)/
};
- var outdent = function(src, n) {
- if (!n) return src;
- return src.replace(new RegExp('^ {' + n + '}', 'gm'), '');
- };
-
- var indent = function(src) {
- var start = /^( +)(?:[^\n]+\n\1)+/.exec(src);
- if (start) src = outdent(src, start[1].length);
- var size = /\n( +)/.exec(src);
- return size ? size[1].length : 0;
- };
-
var depth
, size;
@@ -142,12 +104,54 @@ var liquor = (function() {
})();
/**
+ * Helpers
+ */
+
+var each = function(obj, func) {
+ if (!obj) return;
+
+ var l = obj.length
+ , i = 0;
+
+ if (typeof l === 'number' && typeof obj !== 'function') {
+ for (; i < l; i++) {
+ if (func.call(obj[i], obj[i], i, obj) === false) {
+ break;
+ }
+ }
+ } else {
+ var keys = Object.keys(obj)
+ , l = keys.length
+ , key;
+
+ for (; i < l; i++) {
+ key = keys[i];
+ if (func.call(obj[key], obj[key], key, obj) === false) {
+ break;
+ }
+ }
+ }
+};
+
+var outdent = function(src, n) {
+ if (!n) return src;
+ return src.replace(new RegExp('^ {' + n + '}', 'gm'), '');
+};
+
+var indent = function(src) {
+ var start = /^( +)(?:[^\n]+\n\1)+/.exec(src);
+ if (start) src = outdent(src, start[1].length);
+ var size = /\n( +)/.exec(src);
+ return size ? size[1].length : 0;
+};
+
+/**
* Expose
*/
liquor.compile = liquor;
-if (typeof module !== 'undefined' && module.exports) {
+if (typeof module !== 'undefined') {
module.exports = liquor;
} else {
this.liquor = liquor;

0 comments on commit 1880692

Please sign in to comment.