diff --git a/lib/less.js b/lib/less.js index 07b0dca0..d054d969 100644 --- a/lib/less.js +++ b/lib/less.js @@ -1,2 +1,24 @@ -less = exports || {}; -less.version = [2, 0, 0]; +var path = require('path'); + +require.paths.unshift(__dirname); + +var less = { + version: [2, 0, 0], + parser: require('less/parser').parser, + tree: require('less/tree') +}; + +['color', 'directive', 'operation', 'dimension', + 'keyword', 'variable', 'ruleset', 'element', + 'selector', 'quoted', 'expression', 'rule', + 'call', 'url', 'alpha', + 'mixin', 'comment' +].forEach(function (n) { + require(path.join('less', 'tree', n)); +}); + +require('less/functions'); +require('ext/array'); + +process.mixin(exports, less); + diff --git a/lib/less/adapters/server.js b/lib/less/adapters/server.js index fddcbaa2..e69de29b 100644 --- a/lib/less/adapters/server.js +++ b/lib/less/adapters/server.js @@ -1,12 +0,0 @@ -var path = require('path'); - -require.paths.unshift(path.join(__dirname, '..', '..')); - -var less = require('less'); - -process.mixin(less, require('less/parser')); -process.mixin(less.tree, require('less/tree')); -process.mixin(exports, less); - -require('ext/array'); - diff --git a/lib/less/functions.js b/lib/less/functions.js index 59006de8..be2c123d 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.functions = { rgb: function (r, g, b) { diff --git a/lib/less/parser.js b/lib/less/parser.js index 147981b8..a3a78758 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -1,6 +1,6 @@ -if (typeof(window) === 'undefined') { +if (typeof(require) !== 'undefined') { var less = exports || {}; - var tree = require(require('path').join(__dirname, '..', 'less', 'tree')); + var tree = require('less/tree'); } // // less.js - parser diff --git a/lib/less/tree.js b/lib/less/tree.js index 62e3f366..c546f282 100644 --- a/lib/less/tree.js +++ b/lib/less/tree.js @@ -1,19 +1,5 @@ -var path = require('path'); var tree = exports; -require.paths.unshift(__dirname); - -['color', 'directive', 'operation', 'dimension', - 'keyword', 'variable', 'ruleset', 'element', - 'selector', 'quoted', 'expression', 'rule', - 'call', 'url', 'alpha', - 'mixin', 'comment' -].forEach(function (n) { - process.mixin(tree, require(path.join('less', 'tree', n))); -}); - -require('functions'); - tree.operate = function (op, a, b) { switch (op) { case '+': return a + b; diff --git a/lib/less/tree/alpha.js b/lib/less/tree/alpha.js index a2da3d0a..c56544eb 100644 --- a/lib/less/tree/alpha.js +++ b/lib/less/tree/alpha.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Alpha = function Alpha(val) { this.value = val; diff --git a/lib/less/tree/call.js b/lib/less/tree/call.js index 581b4a20..633c0831 100644 --- a/lib/less/tree/call.js +++ b/lib/less/tree/call.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Call = function Call(name, args) { this.name = name; diff --git a/lib/less/tree/color.js b/lib/less/tree/color.js index 14699e32..b778178b 100644 --- a/lib/less/tree/color.js +++ b/lib/less/tree/color.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } // // RGB Colors - #ff0014, #eee // diff --git a/lib/less/tree/comment.js b/lib/less/tree/comment.js index eb91a445..5e8744dd 100644 --- a/lib/less/tree/comment.js +++ b/lib/less/tree/comment.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Comment = function Comment(value) { this.value = value; diff --git a/lib/less/tree/dimension.js b/lib/less/tree/dimension.js index fb4cce98..77843e5a 100644 --- a/lib/less/tree/dimension.js +++ b/lib/less/tree/dimension.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Dimension = function Dimension(value, unit) { this.value = parseFloat(value); diff --git a/lib/less/tree/directive.js b/lib/less/tree/directive.js index 3e133a1d..1e3d1a28 100644 --- a/lib/less/tree/directive.js +++ b/lib/less/tree/directive.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Directive = function Directive(name, value) { this.name = name; diff --git a/lib/less/tree/element.js b/lib/less/tree/element.js index 9dd5a533..d5499a81 100644 --- a/lib/less/tree/element.js +++ b/lib/less/tree/element.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Element = function Element(combinator, value) { this.combinator = combinator instanceof tree.Combinator ? diff --git a/lib/less/tree/expression.js b/lib/less/tree/expression.js index be6b51f0..4d658d97 100644 --- a/lib/less/tree/expression.js +++ b/lib/less/tree/expression.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Expression = function Expression(value) { this.value = value }; tree.Expression.prototype = { diff --git a/lib/less/tree/keyword.js b/lib/less/tree/keyword.js index d7602cfd..104d863d 100644 --- a/lib/less/tree/keyword.js +++ b/lib/less/tree/keyword.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Keyword = function Keyword(value) { this.value = value }; tree.Keyword.prototype = { diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js index 6e8b2218..533f7693 100644 --- a/lib/less/tree/mixin.js +++ b/lib/less/tree/mixin.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.mixin = {}; tree.mixin.Call = function MixinCall(elements, args) { diff --git a/lib/less/tree/operation.js b/lib/less/tree/operation.js index 9daaf887..24c64a69 100644 --- a/lib/less/tree/operation.js +++ b/lib/less/tree/operation.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Operation = function Operation(op, operands) { this.op = op.trim(); diff --git a/lib/less/tree/quoted.js b/lib/less/tree/quoted.js index ba16fc7b..838e498f 100644 --- a/lib/less/tree/quoted.js +++ b/lib/less/tree/quoted.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Quoted = function Quoted(value, content) { this.value = value; diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 9a9ad99b..86d9f43d 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Rule = function Rule(name, value) { this.name = name; diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index c16eeac1..1119af32 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Ruleset = function Ruleset(selectors, rules) { this.selectors = selectors; diff --git a/lib/less/tree/selector.js b/lib/less/tree/selector.js index 0a49f6f2..027f546d 100644 --- a/lib/less/tree/selector.js +++ b/lib/less/tree/selector.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Selector = function Selector(elements) { this.elements = elements; diff --git a/lib/less/tree/url.js b/lib/less/tree/url.js index 4b32866d..b67d4d58 100644 --- a/lib/less/tree/url.js +++ b/lib/less/tree/url.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.URL = function URL(val) { this.value = val; diff --git a/lib/less/tree/variable.js b/lib/less/tree/variable.js index 1892e6c6..853d20ce 100644 --- a/lib/less/tree/variable.js +++ b/lib/less/tree/variable.js @@ -1,4 +1,4 @@ -if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); } +if (typeof(require) !== 'undefined') { var tree = require('less/tree') } tree.Variable = function Variable(name) { this.name = name }; tree.Variable.prototype = { diff --git a/test/less-test.js b/test/less-test.js index 077a6abe..75a0d134 100644 --- a/test/less-test.js +++ b/test/less-test.js @@ -4,10 +4,7 @@ var path = require('path'), require.paths.unshift(__dirname, path.join(__dirname, '..')); -var less = require('lib/less/adapters/server'); - -less.tree = {}; -process.mixin(less.tree, require(path.join(__dirname, '..', 'lib', 'less', 'tree'))); +var less = require('lib/less'); less.tree.functions.add = function (a, b) { return new(less.tree.Dimension)(a.value + b.value);