stylus-source 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/README.md +3 -0
- data/lib/.DS_Store +0 -0
- data/lib/node_modules/cssom/.idea/CSSOM.iml +9 -0
- data/lib/node_modules/cssom/.idea/dictionaries/nv.xml +3 -0
- data/lib/node_modules/cssom/.idea/encodings.xml +5 -0
- data/lib/node_modules/cssom/.idea/misc.xml +17 -0
- data/lib/node_modules/cssom/.idea/modules.xml +9 -0
- data/lib/node_modules/cssom/.idea/projectCodeStyle.xml +82 -0
- data/lib/node_modules/cssom/.idea/vcs.xml +8 -0
- data/lib/node_modules/cssom/.idea/workspace.xml +467 -0
- data/lib/node_modules/cssom/.livereload +19 -0
- data/lib/node_modules/cssom/Jakefile +37 -0
- data/lib/node_modules/cssom/README.mdown +33 -0
- data/lib/node_modules/cssom/Rakefile +23 -0
- data/lib/node_modules/cssom/docs/.livereload +19 -0
- data/lib/node_modules/cssom/docs/bar.css +3 -0
- data/lib/node_modules/cssom/docs/demo.css +0 -0
- data/lib/node_modules/cssom/docs/foo.css +4 -0
- data/lib/node_modules/cssom/docs/parse.html +170 -0
- data/lib/node_modules/cssom/docs/parse2.html +431 -0
- data/lib/node_modules/cssom/index.html +100 -0
- data/lib/node_modules/cssom/lib/CSSImportRule.js +34 -0
- data/lib/node_modules/cssom/lib/CSSMediaRule.js +38 -0
- data/lib/node_modules/cssom/lib/CSSOM.js +3 -0
- data/lib/node_modules/cssom/lib/CSSRule.js +38 -0
- data/lib/node_modules/cssom/lib/CSSStyleDeclaration.js +130 -0
- data/lib/node_modules/cssom/lib/CSSStyleRule.js +187 -0
- data/lib/node_modules/cssom/lib/CSSStyleSheet.js +85 -0
- data/lib/node_modules/cssom/lib/MediaList.js +61 -0
- data/lib/node_modules/cssom/lib/StyleSheet.js +15 -0
- data/lib/node_modules/cssom/lib/clone.js +69 -0
- data/lib/node_modules/cssom/lib/index.js +10 -0
- data/lib/node_modules/cssom/lib/parse.js +195 -0
- data/lib/node_modules/cssom/media.html +17 -0
- data/lib/node_modules/cssom/package.json +30 -0
- data/lib/node_modules/cssom/plugins/toHTML.js +32 -0
- data/lib/node_modules/cssom/server/index.html +22 -0
- data/lib/node_modules/cssom/server/index.js +21 -0
- data/lib/node_modules/cssom/shorthands.html +21 -0
- data/lib/node_modules/cssom/test/CSSStyleDeclaration.test.js +35 -0
- data/lib/node_modules/cssom/test/CSSStyleRule.test.js +12 -0
- data/lib/node_modules/cssom/test/CSSStyleSheet.test.js +16 -0
- data/lib/node_modules/cssom/test/MediaList.test.js +21 -0
- data/lib/node_modules/cssom/test/clone.test.js +38 -0
- data/lib/node_modules/cssom/test/fixtures/dummy.css +3 -0
- data/lib/node_modules/cssom/test/helper.js +97 -0
- data/lib/node_modules/cssom/test/index.html +42 -0
- data/lib/node_modules/cssom/test/parse.test.js +346 -0
- data/lib/node_modules/cssom/test/vendor/qunit.css +189 -0
- data/lib/node_modules/cssom/test/vendor/qunit.js +1341 -0
- data/lib/node_modules/growl/History.md +16 -0
- data/lib/node_modules/growl/Readme.md +74 -0
- data/lib/node_modules/growl/lib/growl.js +82 -0
- data/lib/node_modules/growl/package.json +6 -0
- data/lib/node_modules/growl/test.js +17 -0
- data/lib/stylus/colors.js +156 -0
- data/lib/stylus/convert/css.js +130 -0
- data/lib/stylus/errors.js +58 -0
- data/lib/stylus/functions/image.js +120 -0
- data/lib/stylus/functions/index.js +722 -0
- data/lib/stylus/functions/index.styl +123 -0
- data/lib/stylus/functions/url.js +98 -0
- data/lib/stylus/lexer.js +728 -0
- data/lib/stylus/middleware.js +223 -0
- data/lib/stylus/nodes/arguments.js +65 -0
- data/lib/stylus/nodes/binop.js +54 -0
- data/lib/stylus/nodes/block.js +99 -0
- data/lib/stylus/nodes/boolean.js +103 -0
- data/lib/stylus/nodes/call.js +57 -0
- data/lib/stylus/nodes/charset.js +42 -0
- data/lib/stylus/nodes/comment.js +32 -0
- data/lib/stylus/nodes/each.js +56 -0
- data/lib/stylus/nodes/expression.js +168 -0
- data/lib/stylus/nodes/fontface.js +55 -0
- data/lib/stylus/nodes/function.js +104 -0
- data/lib/stylus/nodes/group.js +79 -0
- data/lib/stylus/nodes/hsla.js +256 -0
- data/lib/stylus/nodes/ident.js +127 -0
- data/lib/stylus/nodes/if.js +55 -0
- data/lib/stylus/nodes/import.js +30 -0
- data/lib/stylus/nodes/index.js +52 -0
- data/lib/stylus/nodes/jsliteral.js +32 -0
- data/lib/stylus/nodes/keyframes.js +78 -0
- data/lib/stylus/nodes/literal.js +92 -0
- data/lib/stylus/nodes/media.js +42 -0
- data/lib/stylus/nodes/node.js +209 -0
- data/lib/stylus/nodes/null.js +72 -0
- data/lib/stylus/nodes/page.js +43 -0
- data/lib/stylus/nodes/params.js +72 -0
- data/lib/stylus/nodes/property.js +72 -0
- data/lib/stylus/nodes/return.js +44 -0
- data/lib/stylus/nodes/rgba.js +335 -0
- data/lib/stylus/nodes/root.js +50 -0
- data/lib/stylus/nodes/selector.js +57 -0
- data/lib/stylus/nodes/string.js +120 -0
- data/lib/stylus/nodes/ternary.js +51 -0
- data/lib/stylus/nodes/unaryop.js +46 -0
- data/lib/stylus/nodes/unit.js +207 -0
- data/lib/stylus/parser.js +1514 -0
- data/lib/stylus/renderer.js +157 -0
- data/lib/stylus/source.rb +7 -0
- data/lib/stylus/stack/frame.js +66 -0
- data/lib/stylus/stack/index.js +146 -0
- data/lib/stylus/stack/scope.js +53 -0
- data/lib/stylus/stylus.js +102 -0
- data/lib/stylus/token.js +53 -0
- data/lib/stylus/utils.js +237 -0
- data/lib/stylus/visitor/compiler.js +472 -0
- data/lib/stylus/visitor/evaluator.js +1070 -0
- data/lib/stylus/visitor/index.js +31 -0
- data/stylus-source.gemspec +15 -0
- metadata +158 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Stylus - middleware
|
|
3
|
+
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Module dependencies.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
var stylus = require('./stylus')
|
|
12
|
+
, fs = require('fs')
|
|
13
|
+
, url = require('url')
|
|
14
|
+
, basename = require('path').basename
|
|
15
|
+
, join = require('path').join;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Import map.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var imports = {};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return Connect middleware with the given `options`.
|
|
25
|
+
*
|
|
26
|
+
* Options:
|
|
27
|
+
*
|
|
28
|
+
* `force` Always re-compile
|
|
29
|
+
* `debug` Output debugging information
|
|
30
|
+
* `src` Source directory used to find .styl files
|
|
31
|
+
* `dest` Destination directory used to output .css files
|
|
32
|
+
* when undefined defaults to `src`.
|
|
33
|
+
* `compile` Custom compile function, accepting the arguments
|
|
34
|
+
* `(str, path)`.
|
|
35
|
+
* `compress` Whether the output .css files should be compressed
|
|
36
|
+
* `firebug` Emits debug infos in the generated css that can
|
|
37
|
+
* be used by the FireStylus Firebug plugin
|
|
38
|
+
* `linenos` Emits comments in the generated css indicating
|
|
39
|
+
* the corresponding stylus line
|
|
40
|
+
*
|
|
41
|
+
* Examples:
|
|
42
|
+
*
|
|
43
|
+
* Here we set up the custom compile function so that we may
|
|
44
|
+
* set the `compress` option, or define additional functions.
|
|
45
|
+
*
|
|
46
|
+
* By default the compile function simply sets the `filename`
|
|
47
|
+
* and renders the CSS.
|
|
48
|
+
*
|
|
49
|
+
* function compile(str, path) {
|
|
50
|
+
* return stylus(str)
|
|
51
|
+
* .set('filename', path)
|
|
52
|
+
* .set('compress', true);
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* Pass the middleware to Connect, grabbing .styl files from this directory
|
|
56
|
+
* and saving .css files to _./public_. Also supplying our custom `compile` function.
|
|
57
|
+
*
|
|
58
|
+
* Following that we have a `staticProvider` layer setup to serve the .css
|
|
59
|
+
* files generated by Stylus.
|
|
60
|
+
*
|
|
61
|
+
* var server = connect.createServer(
|
|
62
|
+
* stylus.middleware({
|
|
63
|
+
* src: __dirname
|
|
64
|
+
* , dest: __dirname + '/public'
|
|
65
|
+
* , compile: compile
|
|
66
|
+
* })
|
|
67
|
+
* , connect.static(__dirname + '/public')
|
|
68
|
+
* );
|
|
69
|
+
*
|
|
70
|
+
* @param {Object} options
|
|
71
|
+
* @return {Function}
|
|
72
|
+
* @api public
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
module.exports = function(options){
|
|
76
|
+
options = options || {};
|
|
77
|
+
|
|
78
|
+
// Accept src/dest dir
|
|
79
|
+
if ('string' == typeof options) {
|
|
80
|
+
options = { src: options };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Force compilation
|
|
84
|
+
var force = options.force;
|
|
85
|
+
|
|
86
|
+
// Debug option
|
|
87
|
+
var debug = options.debug;
|
|
88
|
+
|
|
89
|
+
// Source dir required
|
|
90
|
+
var src = options.src;
|
|
91
|
+
if (!src) throw new Error('stylus.middleware() requires "src" directory');
|
|
92
|
+
|
|
93
|
+
// Default dest dir to source
|
|
94
|
+
var dest = options.dest
|
|
95
|
+
? options.dest
|
|
96
|
+
: src;
|
|
97
|
+
|
|
98
|
+
// Default compile callback
|
|
99
|
+
options.compile = options.compile || function(str, path){
|
|
100
|
+
return stylus(str)
|
|
101
|
+
.set('filename', path)
|
|
102
|
+
.set('compress', options.compress)
|
|
103
|
+
.set('firebug', options.firebug)
|
|
104
|
+
.set('linenos', options.linenos);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Middleware
|
|
108
|
+
return function(req, res, next){
|
|
109
|
+
if ('GET' != req.method && 'HEAD' != req.method) return next();
|
|
110
|
+
var path = url.parse(req.url).pathname;
|
|
111
|
+
if (/\.css$/.test(path)) {
|
|
112
|
+
var cssPath = join(dest, path)
|
|
113
|
+
, stylusPath = join(src, path.replace('.css', '.styl'));
|
|
114
|
+
|
|
115
|
+
if (debug) {
|
|
116
|
+
log('source', stylusPath);
|
|
117
|
+
log('dest', cssPath);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Ignore ENOENT to fall through as 404
|
|
121
|
+
function error(err) {
|
|
122
|
+
next('ENOENT' == err.code
|
|
123
|
+
? null
|
|
124
|
+
: err);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Force
|
|
128
|
+
if (force) return compile();
|
|
129
|
+
|
|
130
|
+
// Compile to cssPath
|
|
131
|
+
function compile() {
|
|
132
|
+
if (debug) log('read', stylusPath);
|
|
133
|
+
fs.readFile(stylusPath, 'utf8', function(err, str){
|
|
134
|
+
if (err) return error(err);
|
|
135
|
+
var style = options.compile(str, stylusPath);
|
|
136
|
+
var paths = style.options._imports = [];
|
|
137
|
+
delete imports[stylusPath];
|
|
138
|
+
style.render(function(err, css){
|
|
139
|
+
if (err) return next(err);
|
|
140
|
+
if (debug) log('render', stylusPath);
|
|
141
|
+
imports[stylusPath] = paths;
|
|
142
|
+
fs.writeFile(cssPath, css, 'utf8', next);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Re-compile on server restart, disregarding
|
|
148
|
+
// mtimes since we need to map imports
|
|
149
|
+
if (!imports[stylusPath]) return compile();
|
|
150
|
+
|
|
151
|
+
// Compare mtimes
|
|
152
|
+
fs.stat(stylusPath, function(err, stylusStats){
|
|
153
|
+
if (err) return error(err);
|
|
154
|
+
fs.stat(cssPath, function(err, cssStats){
|
|
155
|
+
// CSS has not been compiled, compile it!
|
|
156
|
+
if (err) {
|
|
157
|
+
if ('ENOENT' == err.code) {
|
|
158
|
+
if (debug) log('not found', cssPath);
|
|
159
|
+
compile();
|
|
160
|
+
} else {
|
|
161
|
+
next(err);
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
// Source has changed, compile it
|
|
165
|
+
if (stylusStats.mtime > cssStats.mtime) {
|
|
166
|
+
if (debug) log('modified', cssPath);
|
|
167
|
+
compile();
|
|
168
|
+
// Already compiled, check imports
|
|
169
|
+
} else {
|
|
170
|
+
checkImports(stylusPath, function(changed){
|
|
171
|
+
if (debug && changed.length) {
|
|
172
|
+
changed.forEach(function(path) {
|
|
173
|
+
log('modified import %s', path);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
changed.length ? compile() : next();
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
next();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Check `path`'s imports to see if they have been altered.
|
|
190
|
+
*
|
|
191
|
+
* @param {String} path
|
|
192
|
+
* @param {Function} fn
|
|
193
|
+
* @api private
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
function checkImports(path, fn) {
|
|
197
|
+
var nodes = imports[path];
|
|
198
|
+
if (!nodes) return fn();
|
|
199
|
+
if (!nodes.length) return fn();
|
|
200
|
+
|
|
201
|
+
var pending = nodes.length
|
|
202
|
+
, changed = [];
|
|
203
|
+
|
|
204
|
+
nodes.forEach(function(imported){
|
|
205
|
+
fs.stat(imported.path, function(err, stat){
|
|
206
|
+
// error or newer mtime
|
|
207
|
+
if (err || !imported.mtime || stat.mtime > imported.mtime) {
|
|
208
|
+
changed.push(imported.path);
|
|
209
|
+
}
|
|
210
|
+
--pending || fn(changed);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Log a message.
|
|
217
|
+
*
|
|
218
|
+
* @api private
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
function log(key, val) {
|
|
222
|
+
console.error(' \033[90m%s :\033[0m \033[36m%s\033[0m', key, val);
|
|
223
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* Stylus - Arguments
|
|
4
|
+
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Module dependencies.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var Node = require('./node')
|
|
13
|
+
, nodes = require('../nodes')
|
|
14
|
+
, utils = require('../utils');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initialize a new `Arguments`.
|
|
18
|
+
*
|
|
19
|
+
* @api public
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var Arguments = module.exports = function Arguments(){
|
|
23
|
+
nodes.Expression.call(this);
|
|
24
|
+
this.map = {};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Inherit from `nodes.Expression.prototype`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
Arguments.prototype.__proto__ = nodes.Expression.prototype;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Initialize an `Arguments` object with the nodes
|
|
35
|
+
* from the given `expr`.
|
|
36
|
+
*
|
|
37
|
+
* @param {Expression} expr
|
|
38
|
+
* @return {Arguments}
|
|
39
|
+
* @api public
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
Arguments.fromExpression = function(expr){
|
|
43
|
+
var args = new Arguments
|
|
44
|
+
, len = expr.nodes.length;
|
|
45
|
+
args.lineno = expr.lineno;
|
|
46
|
+
args.isList = expr.isList;
|
|
47
|
+
for (var i = 0; i < len; ++i) {
|
|
48
|
+
args.push(expr.nodes[i]);
|
|
49
|
+
}
|
|
50
|
+
return args;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Return a clone of this node.
|
|
55
|
+
*
|
|
56
|
+
* @return {Node}
|
|
57
|
+
* @api public
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
Arguments.prototype.clone = function(){
|
|
61
|
+
var clone = nodes.Expression.prototype.clone.call(this);
|
|
62
|
+
clone.map = this.map;
|
|
63
|
+
return clone;
|
|
64
|
+
};
|
|
65
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* Stylus - BinOp
|
|
4
|
+
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Module dependencies.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var Node = require('./node');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initialize a new `BinOp` with `op`, `left` and `right`.
|
|
16
|
+
*
|
|
17
|
+
* @param {String} op
|
|
18
|
+
* @param {Node} left
|
|
19
|
+
* @param {Node} right
|
|
20
|
+
* @api public
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
var BinOp = module.exports = function BinOp(op, left, right){
|
|
24
|
+
Node.call(this);
|
|
25
|
+
this.op = op;
|
|
26
|
+
this.left = left;
|
|
27
|
+
this.right = right;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Inherit from `Node.prototype`.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
BinOp.prototype.__proto__ = Node.prototype;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Return a clone of this node.
|
|
38
|
+
*
|
|
39
|
+
* @return {Node}
|
|
40
|
+
* @api public
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
BinOp.prototype.clone = function(){
|
|
44
|
+
var clone = new BinOp(
|
|
45
|
+
this.op
|
|
46
|
+
, this.left.clone()
|
|
47
|
+
, this.right ?
|
|
48
|
+
this.right.clone()
|
|
49
|
+
: null);
|
|
50
|
+
clone.lineno = this.lineno;
|
|
51
|
+
clone.filename = this.filename;
|
|
52
|
+
if (this.val) clone.val = this.val.clone();
|
|
53
|
+
return clone;
|
|
54
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* Stylus - Block
|
|
4
|
+
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Module dependencies.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var Node = require('./node');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initialize a new `Block` node with `parent` Block.
|
|
16
|
+
*
|
|
17
|
+
* @param {Block} parent
|
|
18
|
+
* @api public
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var Block = module.exports = function Block(parent, node){
|
|
22
|
+
Node.call(this);
|
|
23
|
+
this.nodes = [];
|
|
24
|
+
this.parent = parent;
|
|
25
|
+
this.node = node;
|
|
26
|
+
this.scope = true;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Inherit from `Node.prototype`.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
Block.prototype.__proto__ = Node.prototype;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Check if this block has properties..
|
|
37
|
+
*
|
|
38
|
+
* @return {Boolean}
|
|
39
|
+
* @api public
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
Block.prototype.__defineGetter__('hasProperties', function(){
|
|
43
|
+
for (var i = 0, len = this.nodes.length; i < len; ++i) {
|
|
44
|
+
if ('property' == this.nodes[i].nodeName) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Check if this block is empty.
|
|
52
|
+
*
|
|
53
|
+
* @return {Boolean}
|
|
54
|
+
* @api public
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
Block.prototype.__defineGetter__('isEmpty', function(){
|
|
58
|
+
return !this.nodes.length;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Return a clone of this node.
|
|
63
|
+
*
|
|
64
|
+
* @return {Node}
|
|
65
|
+
* @api public
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
Block.prototype.clone = function(){
|
|
69
|
+
var clone = new Block(this.parent, this.node);
|
|
70
|
+
clone.lineno = this.lineno;
|
|
71
|
+
clone.filename = this.filename;
|
|
72
|
+
clone.scope = this.scope;
|
|
73
|
+
this.nodes.forEach(function(node){
|
|
74
|
+
node = node.clone();
|
|
75
|
+
switch (node.nodeName) {
|
|
76
|
+
case 'each':
|
|
77
|
+
case 'group':
|
|
78
|
+
node.block.parent = clone;
|
|
79
|
+
break;
|
|
80
|
+
case 'ident':
|
|
81
|
+
if ('function' == node.val.nodeName) {
|
|
82
|
+
node.val.block.parent = clone;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
clone.push(node);
|
|
86
|
+
});
|
|
87
|
+
return clone;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Push a `node` to this block.
|
|
92
|
+
*
|
|
93
|
+
* @param {Node} node
|
|
94
|
+
* @api public
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
Block.prototype.push = function(node){
|
|
98
|
+
this.nodes.push(node);
|
|
99
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* Stylus - Boolean
|
|
4
|
+
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Module dependencies.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var Node = require('./node')
|
|
13
|
+
, nodes = require('./');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initialize a new `Boolean` node with the given `val`.
|
|
17
|
+
*
|
|
18
|
+
* @param {Boolean} val
|
|
19
|
+
* @api public
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var Boolean = module.exports = function Boolean(val){
|
|
23
|
+
Node.call(this);
|
|
24
|
+
if (this.nodeName) {
|
|
25
|
+
this.val = !!val;
|
|
26
|
+
} else {
|
|
27
|
+
return new Boolean(val);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Inherit from `Node.prototype`.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
Boolean.prototype.__proto__ = Node.prototype;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Return `this` node.
|
|
39
|
+
*
|
|
40
|
+
* @return {Boolean}
|
|
41
|
+
* @api public
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
Boolean.prototype.toBoolean = function(){
|
|
45
|
+
return this;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Return `true` if this node represents `true`.
|
|
50
|
+
*
|
|
51
|
+
* @return {Boolean}
|
|
52
|
+
* @api public
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
Boolean.prototype.__defineGetter__('isTrue', function(){
|
|
56
|
+
return this.val;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Return `true` if this node represents `false`.
|
|
61
|
+
*
|
|
62
|
+
* @return {Boolean}
|
|
63
|
+
* @api public
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
Boolean.prototype.__defineGetter__('isFalse', function(){
|
|
67
|
+
return ! this.val;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Negate the value.
|
|
72
|
+
*
|
|
73
|
+
* @return {Boolean}
|
|
74
|
+
* @api public
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
Boolean.prototype.negate = function(){
|
|
78
|
+
return Boolean(!this.val);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Return 'Boolean'.
|
|
83
|
+
*
|
|
84
|
+
* @return {String}
|
|
85
|
+
* @api public
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
Boolean.prototype.inspect = function(){
|
|
89
|
+
return '[Boolean ' + this.val + ']';
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Return 'true' or 'false'.
|
|
94
|
+
*
|
|
95
|
+
* @return {String}
|
|
96
|
+
* @api public
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
Boolean.prototype.toString = function(){
|
|
100
|
+
return this.val
|
|
101
|
+
? 'true'
|
|
102
|
+
: 'false';
|
|
103
|
+
};
|