stylus-source 0.20.1 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.20.1
1
+ 0.21.0
data/vendor/History.md CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 0.21.0 / 2011-12-17
3
+ ==================
4
+
5
+ * Added unit casting, ex: `(n * 5)%`. Closes #285
6
+
2
7
  0.20.1 / 2011-12-16
3
8
  ==================
4
9
 
data/vendor/bin/stylus CHANGED
@@ -8,6 +8,7 @@ var fs = require('fs')
8
8
  , stylus = require('../lib/stylus')
9
9
  , basename = require('path').basename
10
10
  , dirname = require('path').dirname
11
+ , resolve = require('path').resolve
11
12
  , join = require('path').join;
12
13
 
13
14
  /**
@@ -607,7 +608,7 @@ function usePlugins(style) {
607
608
  plugins.forEach(function(plugin){
608
609
  var path = plugin.path;
609
610
  var options = plugin.options;
610
- fn = require(path);
611
+ fn = require(resolve(path));
611
612
  if ('function' != typeof fn) {
612
613
  throw new Error('plugin ' + path + ' does not export a function');
613
614
  }
@@ -410,6 +410,19 @@ The ternary operator works as we would expect in most languages, being the only
410
410
  num ? unit(num, 'px') : 20px
411
411
  // => 15px
412
412
 
413
+ ## Casting
414
+
415
+ As an terse alternative to the `unit()` built-in function, the syntax `(expr) unit` may be used to force the suffix.
416
+
417
+ body
418
+ n = 5
419
+ foo: (n)em
420
+ foo: (n)%
421
+ foo: (n + 5)%
422
+ foo: (n * 5)px
423
+ foo: unit(n + 5, '%')
424
+ foo: unit(5 + 180 / 2, deg)
425
+
413
426
  ## Color Operations
414
427
 
415
428
  Operations on colors provide a terse, expressive way to alter components. For example we can operate on each RGB:
data/vendor/lib/lexer.js CHANGED
@@ -11,7 +11,14 @@
11
11
 
12
12
  var Token = require('./token')
13
13
  , nodes = require('./nodes')
14
- , errors = require('./errors');
14
+ , errors = require('./errors')
15
+ , units = require('./units');
16
+
17
+ /**
18
+ * Expose `Lexer`.
19
+ */
20
+
21
+ exports = module.exports = Lexer;
15
22
 
16
23
  /**
17
24
  * Operator aliases.
@@ -30,24 +37,7 @@ var alias = {
30
37
  * Units.
31
38
  */
32
39
 
33
- var units = [
34
- 'em'
35
- , 'ex'
36
- , 'px'
37
- , 'mm'
38
- , 'cm'
39
- , 'in'
40
- , 'pt'
41
- , 'pc'
42
- , 'deg'
43
- , 'rad'
44
- , 'grad'
45
- , 'ms'
46
- , 's'
47
- , 'Hz'
48
- , 'kHz'
49
- , 'rem'
50
- , '%'].join('|');
40
+ units = units.join('|');
51
41
 
52
42
  /**
53
43
  * Unit RegExp.
@@ -63,7 +53,7 @@ var unit = new RegExp('^(-)?(\\d+\\.\\d+|\\d+|\\.\\d+)(' + units + ')?[ \\t]*');
63
53
  * @api private
64
54
  */
65
55
 
66
- var Lexer = module.exports = function Lexer(str, options) {
56
+ function Lexer(str, options) {
67
57
  options = options || {};
68
58
  this.stash = [];
69
59
  this.indentStack = [];
data/vendor/lib/parser.js CHANGED
@@ -1498,7 +1498,7 @@ Parser.prototype = {
1498
1498
  * | ident
1499
1499
  * | boolean
1500
1500
  * | literal
1501
- * | '(' expression ')'
1501
+ * | '(' expression ')' '%'?
1502
1502
  */
1503
1503
 
1504
1504
  primary: function() {
@@ -1511,6 +1511,7 @@ Parser.prototype = {
1511
1511
  var expr = this.expression();
1512
1512
  this.expect(')');
1513
1513
  --this.parens;
1514
+ if (this.accept('%')) expr.push(new nodes.Ident('%'));
1514
1515
  return expr;
1515
1516
  }
1516
1517
 
data/vendor/lib/stylus.js CHANGED
@@ -24,7 +24,7 @@ exports = module.exports = render;
24
24
  * Library version.
25
25
  */
26
26
 
27
- exports.version = '0.20.1';
27
+ exports.version = '0.21.0';
28
28
 
29
29
  /**
30
30
  * Expose nodes.
@@ -0,0 +1,26 @@
1
+
2
+ /*!
3
+ * Stylus - units
4
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
5
+ * MIT Licensed
6
+ */
7
+
8
+ module.exports = [
9
+ 'em'
10
+ , 'ex'
11
+ , 'px'
12
+ , 'mm'
13
+ , 'cm'
14
+ , 'in'
15
+ , 'pt'
16
+ , 'pc'
17
+ , 'deg'
18
+ , 'rad'
19
+ , 'grad'
20
+ , 'ms'
21
+ , 's'
22
+ , 'Hz'
23
+ , 'kHz'
24
+ , 'rem'
25
+ , '%'
26
+ ];
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
  var Visitor = require('./')
13
+ , units = require('../units')
13
14
  , nodes = require('../nodes')
14
15
  , Stack = require('../stack')
15
16
  , Frame = require('../stack/frame')
@@ -251,6 +252,8 @@ Evaluator.prototype.visitFunction = function(fn){
251
252
  */
252
253
 
253
254
  Evaluator.prototype.visitEach = function(each){
255
+ var _ = this.return;
256
+ this.return = true;
254
257
  var expr = utils.unwrap(this.visit(utils.unwrap(each.expr)))
255
258
  , len = expr.nodes.length
256
259
  , val = new nodes.Ident(each.val)
@@ -259,6 +262,7 @@ Evaluator.prototype.visitEach = function(each){
259
262
  , block = this.currentBlock
260
263
  , vals = []
261
264
  , body;
265
+ this.return = _;
262
266
 
263
267
  each.block.scope = false;
264
268
  for (var i = 0; i < len; ++i) {
@@ -449,6 +453,10 @@ Evaluator.prototype.visitExpression = function(expr){
449
453
  for (var i = 0, len = expr.nodes.length; i < len; ++i) {
450
454
  expr.nodes[i] = this.visit(expr.nodes[i]);
451
455
  }
456
+
457
+ // support (n * 5)px etc
458
+ if (this.castable(expr)) expr = this.cast(expr);
459
+
452
460
  return expr;
453
461
  };
454
462
 
@@ -1078,6 +1086,32 @@ Evaluator.prototype.propertyExpression = function(prop, name){
1078
1086
  return expr;
1079
1087
  };
1080
1088
 
1089
+ /**
1090
+ * Cast `expr` to the trailing ident.
1091
+ *
1092
+ * @param {Expression} expr
1093
+ * @return {Unit}
1094
+ * @api private
1095
+ */
1096
+
1097
+ Evaluator.prototype.cast = function(expr){
1098
+ return new nodes.Unit(expr.first.val, expr.nodes[1].name);
1099
+ };
1100
+
1101
+ /**
1102
+ * Check if `expr` is castable.
1103
+ *
1104
+ * @param {Expression} expr
1105
+ * @return {Boolean}
1106
+ * @api private
1107
+ */
1108
+
1109
+ Evaluator.prototype.castable = function(expr){
1110
+ return 2 == expr.nodes.length
1111
+ && 'unit' == expr.first.nodeName
1112
+ && ~units.indexOf(expr.nodes[1].name);
1113
+ };
1114
+
1081
1115
  /**
1082
1116
  * Warn with the given `msg`.
1083
1117
  *
data/vendor/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  { "name": "stylus"
2
2
  , "description": "Robust, expressive, and feature-rich CSS superset"
3
- , "version": "0.20.1"
3
+ , "version": "0.21.0"
4
4
  , "author": "TJ Holowaychuk <tj@vision-media.ca>"
5
5
  , "keywords": ["css", "parser", "style", "stylesheets", "jade", "language"]
6
6
  , "repository": "git://github.com/learnboost/stylus"
@@ -0,0 +1,12 @@
1
+ body {
2
+ foo: 5em;
3
+ foo: 5em;
4
+ foo: 5%;
5
+ foo: 5%;
6
+ foo: 10%;
7
+ foo: 25px;
8
+ foo: 95deg;
9
+ }
10
+ body {
11
+ foo: 25deg;
12
+ }
@@ -0,0 +1,14 @@
1
+
2
+ body
3
+ n = 5
4
+ foo: (n)em
5
+ foo: (n) em
6
+ foo: (n)%
7
+ foo: (n) %
8
+ foo: (n + 5)%
9
+ foo: (n * 5)px
10
+ foo: (5 + 180 / 2)deg
11
+
12
+ body
13
+ n = 5 * 5
14
+ foo: (n)deg
@@ -0,0 +1,9 @@
1
+ body {
2
+ foo: 1;
3
+ }
4
+ body {
5
+ foo: 2;
6
+ }
7
+ body {
8
+ foo: 3;
9
+ }
@@ -0,0 +1,8 @@
1
+
2
+
3
+ list()
4
+ 1 2 3
5
+
6
+ for n in list()
7
+ body
8
+ foo: n
@@ -0,0 +1,15 @@
1
+
2
+ /**
3
+ * Module dependencies.
4
+ */
5
+
6
+ var stylus = require('../')
7
+ , fs = require('fs')
8
+ , str = fs.readFileSync('testing/test.styl', 'utf8');
9
+
10
+ stylus(str)
11
+ .set('filename', 'testing/test.styl')
12
+ .render(function(err, css){
13
+ if (err) throw err;
14
+ console.log(css);
15
+ });
@@ -1,2 +1,2 @@
1
1
 
2
- @import utils
2
+ body * foo { display: none; }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylus-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.21.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -149,6 +149,7 @@ files:
149
149
  - vendor/lib/stack/scope.js
150
150
  - vendor/lib/stylus.js
151
151
  - vendor/lib/token.js
152
+ - vendor/lib/units.js
152
153
  - vendor/lib/utils.js
153
154
  - vendor/lib/visitor/compiler.js
154
155
  - vendor/lib/visitor/evaluator.js
@@ -275,6 +276,8 @@ files:
275
276
  - vendor/test/cases/bifs.unquote.styl
276
277
  - vendor/test/cases/bifs.url.css
277
278
  - vendor/test/cases/bifs.url.styl
279
+ - vendor/test/cases/casting.css
280
+ - vendor/test/cases/casting.styl
278
281
  - vendor/test/cases/coercion.css
279
282
  - vendor/test/cases/coercion.styl
280
283
  - vendor/test/cases/comments.css
@@ -571,6 +574,8 @@ files:
571
574
  - vendor/test/cases/regression.475.styl
572
575
  - vendor/test/cases/regression.480.css
573
576
  - vendor/test/cases/regression.480.styl
577
+ - vendor/test/cases/regression.484.css
578
+ - vendor/test/cases/regression.484.styl
574
579
  - vendor/test/cases/reset.css
575
580
  - vendor/test/cases/reset.styl
576
581
  - vendor/test/cases/rule.charset.css
@@ -613,15 +618,8 @@ files:
613
618
  - vendor/test/images/squirrel.jpeg
614
619
  - vendor/test/images/tux.png
615
620
  - vendor/test/run.js
616
- - vendor/testing/foo.css
617
- - vendor/testing/index.html
618
- - vendor/testing/stylus.js
619
- - vendor/testing/test-js.js
620
- - vendor/testing/test.css
621
- - vendor/testing/test.js
621
+ - vendor/testing/index.js
622
622
  - vendor/testing/test.styl
623
- - vendor/testing/utils.styl
624
- - vendor/testing/vendor.styl
625
623
  homepage: https://github.com/railsjedi/ruby-stylus-source
626
624
  licenses: []
627
625
  post_install_message:
@@ -1,4 +0,0 @@
1
-
2
- foo {
3
- bar: 'baz';
4
- }
@@ -1,56 +0,0 @@
1
- <html>
2
- <head>
3
- <!--<link rel="stylesheet/stylus"></link>-->
4
- <style type="text/stylus">
5
- fg = white
6
- body {
7
- color: fg;
8
- background: black;
9
- }
10
- </style>
11
- <script src="../stylus.js"></script>
12
- <script>
13
-
14
- function createStylesheet(css) {
15
- var el = document.createElement('style');
16
- el.type = 'text/css';
17
- el.media = 'screen';
18
- el.id = 'todo';
19
- el.textContent = css;
20
- document.getElementsByTagName('head')[0].appendChild(el);
21
- }
22
-
23
- onload = function(){
24
- var styles = document.getElementsByTagName('style')
25
- , indent
26
- , styl;
27
-
28
- // TODO: link tags like https://github.com/cloudhead/less.js/blob/master/dist/less-1.1.4.js#L2463
29
- // TODO: strip indentation
30
- for (var i = 0, len = styles.length; i < len; ++i) {
31
- if ('text/stylus' == styles[i].type) {
32
- styl = styles[i].textContent;
33
- stylus(styl.trim())
34
- .render(function(err, css){
35
- if (err) throw err;
36
- createStylesheet(css);
37
- });
38
- }
39
- }
40
- };
41
- </script>
42
- </head>
43
- <body>
44
- <div id="dialog">
45
- <h1>Dialog</h1>
46
- <p>Some random dialog</p>
47
- </div>
48
-
49
- <div class="tip username-tip">Please enter your username</div>
50
- <div class="tip password-tip">Please enter your password</div>
51
- <div id="content">
52
- <p><input type="text" class="username" placeholder="Username:"></p>
53
- <p><input type="text" class="password" placeholder="Password:"></p>
54
- </div>
55
- </body>
56
- </html>
@@ -1,146 +0,0 @@
1
-
2
- var stylus = (function(){
3
- function center(selector) {
4
- jQuery(function(){
5
- var el = jQuery(selector);
6
-
7
- function center() {
8
- var w = el.outerWidth()
9
- , h = el.outerHeight();
10
-
11
- el.css({
12
- top: window.innerHeight / 2 - h / 2
13
- , left: window.innerWidth / 2 - w / 2
14
- });
15
- }
16
-
17
- jQuery(window).resize(center);
18
- center();
19
- });
20
- }
21
-
22
- function tip(selector, pos, color, width, height) {
23
- width = parseInt(width, 10);
24
- height = parseInt(height, 10);
25
- jQuery(function(){
26
- var el = jQuery(selector)
27
- , tip = $('<canvas>')
28
- , canvas = tip.get(0)
29
- , ctx = canvas.getContext('2d')
30
- , w = el.outerWidth()
31
- , h = el.outerHeight()
32
- , off = el.offset()
33
- , top
34
- , left;
35
-
36
- el.append(canvas);
37
- canvas.width = width;
38
- canvas.height = height;
39
-
40
- function calc() {
41
- ctx.beginPath();
42
- switch (pos) {
43
- case 'top':
44
- top = -height;
45
- left = w / 2 - width / 2;
46
- ctx.lineTo(width / 2, 0);
47
- ctx.lineTo(width, height);
48
- ctx.lineTo(0, height);
49
- break;
50
- case 'right':
51
- top = h / 2 - height / 2;
52
- left = w;
53
- ctx.lineTo(0, 0);
54
- ctx.lineTo(0, height);
55
- ctx.lineTo(width, height / 2);
56
- break;
57
- case 'bottom':
58
- top = h;
59
- left = w / 2 - width / 2;
60
- ctx.lineTo(width / 2, height);
61
- ctx.lineTo(0, 0);
62
- ctx.lineTo(width, 0);
63
- break;
64
- case 'left':
65
- top = h / 2 - height / 2;
66
- left = -width;
67
- ctx.lineTo(0, height / 2);
68
- ctx.lineTo(width, 0);
69
- ctx.lineTo(width, height);
70
- break;
71
- }
72
- }
73
-
74
- calc();
75
-
76
- tip.css({ top: top, left: left });
77
- ctx.fillStyle = color;
78
- ctx.fill();
79
- });
80
- }
81
-
82
- function snapTo(selector, target, pos, pad) {
83
- pad = parseInt(pad, 10);
84
- jQuery(function(){
85
- var el = jQuery(selector);
86
- target = jQuery(target);
87
-
88
- function snap() {
89
- var w = el.outerWidth()
90
- , h = el.outerHeight()
91
- , tw = target.outerWidth()
92
- , th = target.outerHeight()
93
- , off = target.offset()
94
- , ww = window.innerWidth
95
- , wh = window.innerHeight
96
- , auto = 'auto' == pos
97
- , top
98
- , left;
99
-
100
- if (auto) pos = 'right';
101
-
102
- function calc() {
103
- switch (pos) {
104
- case 'top':
105
- top = off.top - h - pad;
106
- left = off.left - w / 2 + tw / 2;
107
- break;
108
- case 'left':
109
- top = off.top - h / 2 + th / 2;
110
- left = off.left - w - pad;
111
- break;
112
- case 'bottom':
113
- top = off.top + th + pad;
114
- left = off.left - w / 2 + tw / 2;
115
- break;
116
- case 'right':
117
- top = off.top - h / 2 + th / 2;
118
- left = off.left + tw + pad;
119
- break;
120
- }
121
- }
122
-
123
- calc();
124
-
125
- if (auto) {
126
- // right
127
- if (left + w > ww) {
128
- pos = 'left';
129
- calc();
130
- }
131
- }
132
-
133
- el.css({ top: top, left: left });
134
- }
135
-
136
- jQuery(window).resize(snap);
137
- snap();
138
- });
139
- }
140
-
141
- return {
142
- snapTo: snapTo
143
- , tip: tip
144
- , center: center
145
- }
146
- })()
@@ -1,23 +0,0 @@
1
-
2
- /**
3
- * Module dependencies.
4
- */
5
-
6
- var connect = require('connect')
7
- , stylus = require('../');
8
-
9
- // Setup server
10
- // $ curl http://localhost:3000/functions.css
11
-
12
- var server = connect.createServer(
13
- stylus.middleware({
14
- src: __dirname
15
- , dest: __dirname
16
- , compress: true
17
- , debug: true
18
- }),
19
- connect.static(__dirname)
20
- );
21
-
22
- server.listen(3000);
23
- console.log('server listening on port 3000');
@@ -1,6 +0,0 @@
1
- foo {
2
- bar: 'baz';
3
- }
4
- body {
5
- foo: 'bar';
6
- }
@@ -1,28 +0,0 @@
1
-
2
- /**
3
- * Module dependencies.
4
- */
5
-
6
- var stylus = require('../')
7
- , utils = stylus.utils
8
- , nodes = stylus.nodes
9
- , str = require('fs').readFileSync(__dirname + '/test.styl', 'utf8')
10
- , fs = require('fs');
11
-
12
- stylus(str)
13
- //.import(__dirname + '/mixins/vendor')
14
- .set('filename', __dirname + '/test.styl')
15
- // .set('compress', true)
16
- // .set('firebug', true)
17
- // .set('linenos', true)
18
- // .set('warn', true)
19
- .set('include css', true)
20
- .define('string', 'some string')
21
- .define('number', 15.5)
22
- .define('some-bool', true)
23
- .define('list', ['Helvetica Neue', 'Helvetica', 'sans-serif'])
24
- .render(function(err, css, js){
25
- if (err) throw err;
26
- process.stdout.write(css);
27
- });
28
-
@@ -1,3 +0,0 @@
1
-
2
- // bar
3
-
@@ -1,3 +0,0 @@
1
-
2
- body
3
- foo: 'bar'