cloudhead-less 0.8.12 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/Rakefile +21 -2
- data/VERSION +1 -1
- data/bin/lessc +0 -8
- data/less.gemspec +48 -15
- data/lib/less/command.rb +24 -25
- data/lib/less/engine/builder.rb +13 -0
- data/lib/less/engine/less.tt +379 -0
- data/lib/less/engine/nodes/element.rb +153 -0
- data/lib/less/engine/nodes/entity.rb +59 -0
- data/lib/less/engine/nodes/function.rb +61 -0
- data/lib/less/engine/nodes/literal.rb +132 -0
- data/lib/less/engine/nodes/property.rb +120 -0
- data/lib/less/engine/nodes/selector.rb +39 -0
- data/lib/less/engine/nodes.rb +8 -0
- data/lib/less/engine/parser.rb +3854 -0
- data/lib/less/engine.rb +42 -139
- data/lib/less.rb +65 -10
- data/spec/command_spec.rb +2 -6
- data/spec/css/accessors-1.0.css +20 -0
- data/spec/css/big-1.0.css +3770 -0
- data/spec/css/comments-1.0.css +11 -0
- data/spec/css/css-1.0.css +40 -0
- data/spec/css/functions-1.0.css +8 -0
- data/spec/css/import-1.0.css +13 -0
- data/spec/css/mixins-1.0.css +30 -0
- data/spec/css/operations-1.0.css +30 -0
- data/spec/css/rulesets-1.0.css +19 -0
- data/spec/css/scope-1.0.css +16 -0
- data/spec/css/strings-1.0.css +14 -0
- data/spec/css/variables-1.0.css +7 -0
- data/spec/css/whitespace-1.0.css +11 -0
- data/spec/engine_spec.rb +66 -18
- data/spec/less/accessors-1.0.less +20 -0
- data/spec/less/big-1.0.less +4810 -0
- data/spec/less/colors-1.0.less +0 -0
- data/spec/less/comments-1.0.less +46 -0
- data/spec/less/css-1.0.less +82 -0
- data/spec/less/exceptions/mixed-units-error.less +0 -0
- data/spec/less/exceptions/name-error-1.0.less +0 -0
- data/spec/less/exceptions/syntax-error-1.0.less +0 -0
- data/spec/less/functions-1.0.less +6 -0
- data/spec/less/import/import-test-a.less +2 -0
- data/spec/less/import/import-test-b.less +8 -0
- data/spec/less/import/import-test-c.less +5 -0
- data/spec/less/import-1.0.less +7 -0
- data/spec/less/mixins-1.0.less +43 -0
- data/spec/less/operations-1.0.less +39 -0
- data/spec/less/rulesets-1.0.less +30 -0
- data/spec/less/scope-1.0.less +33 -0
- data/spec/less/strings-1.0.less +14 -0
- data/spec/less/variables-1.0.less +16 -0
- data/spec/less/whitespace-1.0.less +21 -0
- data/spec/spec.css +81 -23
- data/spec/spec.less +3 -4
- data/spec/spec_helper.rb +4 -1
- metadata +46 -13
- data/lib/less/tree.rb +0 -82
- data/spec/css/less-0.8.10.css +0 -30
- data/spec/css/less-0.8.11.css +0 -31
- data/spec/css/less-0.8.12.css +0 -28
- data/spec/css/less-0.8.5.css +0 -24
- data/spec/css/less-0.8.6.css +0 -24
- data/spec/css/less-0.8.7.css +0 -24
- data/spec/css/less-0.8.8.css +0 -25
- data/spec/tree_spec.rb +0 -5
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
* Comment Test
|
3
|
+
*
|
4
|
+
* - cloudhead (http://cloudhead.net)
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
|
8
|
+
////////////////
|
9
|
+
@var: "content";
|
10
|
+
////////////////
|
11
|
+
|
12
|
+
/* Colors
|
13
|
+
* ------
|
14
|
+
* #EDF8FC (background blue)
|
15
|
+
* #166C89 (darkest blue)
|
16
|
+
*
|
17
|
+
* Text:
|
18
|
+
* #333 (standard text) // A comment within a comment!
|
19
|
+
* #1F9EC9 (standard link)
|
20
|
+
*
|
21
|
+
*/
|
22
|
+
|
23
|
+
/* @group Variables
|
24
|
+
------------------- */
|
25
|
+
#comments {
|
26
|
+
/**/ // An empty comment
|
27
|
+
color: red; /* A C-style comment */
|
28
|
+
background-color: orange; // A little comment
|
29
|
+
font-size: 12px;
|
30
|
+
|
31
|
+
/* lost comment */ content: @var;
|
32
|
+
|
33
|
+
border: 1px solid black;
|
34
|
+
|
35
|
+
// padding & margin //
|
36
|
+
padding: 0;
|
37
|
+
margin: 2em;
|
38
|
+
} //
|
39
|
+
|
40
|
+
/* commented out
|
41
|
+
#more-comments {
|
42
|
+
color: grey;
|
43
|
+
}
|
44
|
+
*/
|
45
|
+
|
46
|
+
//
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
a CSS File
|
4
|
+
|
5
|
+
*/
|
6
|
+
|
7
|
+
div { color: black; }
|
8
|
+
div { width: 99%; }
|
9
|
+
|
10
|
+
* {
|
11
|
+
min-width: 45em;
|
12
|
+
}
|
13
|
+
|
14
|
+
h1, h2 > a > p, h3 {
|
15
|
+
color: none;
|
16
|
+
}
|
17
|
+
|
18
|
+
div.class {
|
19
|
+
color: blue;
|
20
|
+
}
|
21
|
+
|
22
|
+
div#id {
|
23
|
+
color: green;
|
24
|
+
}
|
25
|
+
|
26
|
+
.one.two.three {
|
27
|
+
color: grey;
|
28
|
+
}
|
29
|
+
|
30
|
+
@media print {
|
31
|
+
font-size: 3em;
|
32
|
+
}
|
33
|
+
|
34
|
+
@media screen {
|
35
|
+
font-size: 10px;
|
36
|
+
}
|
37
|
+
|
38
|
+
@font-face {
|
39
|
+
font-family: 'Garamond Pro';
|
40
|
+
src: url("/fonts/garamond-pro.ttf");
|
41
|
+
}
|
42
|
+
|
43
|
+
a:hover, a:link {
|
44
|
+
color: #999;
|
45
|
+
}
|
46
|
+
|
47
|
+
p, p:first-child {
|
48
|
+
text-transform: none;
|
49
|
+
}
|
50
|
+
|
51
|
+
q:lang(no) {
|
52
|
+
quotes: none;
|
53
|
+
}
|
54
|
+
|
55
|
+
p + h1 {
|
56
|
+
font-size: 2em;
|
57
|
+
}
|
58
|
+
|
59
|
+
input[type="text"] {
|
60
|
+
font-weight: normal;
|
61
|
+
}
|
62
|
+
|
63
|
+
#shorthands {
|
64
|
+
border: 1px solid #000;
|
65
|
+
font: 12px/16px Arial;
|
66
|
+
margin: 1px 0;
|
67
|
+
padding: 0 auto;
|
68
|
+
background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px;
|
69
|
+
}
|
70
|
+
|
71
|
+
#more-shorthands {
|
72
|
+
margin: 0;
|
73
|
+
padding: 1px 0 2px 0;
|
74
|
+
font: normal small/20px 'Trebuchet MS', Verdana, sans-serif;
|
75
|
+
}
|
76
|
+
|
77
|
+
.misc {
|
78
|
+
-moz-border-radius: 2px;
|
79
|
+
color: red !important;
|
80
|
+
margin: ;
|
81
|
+
}
|
82
|
+
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
.mixin { border: 1px solid black; }
|
2
|
+
.mixout { border-color: orange; }
|
3
|
+
.borders { border-style: dashed; }
|
4
|
+
|
5
|
+
#namespace {
|
6
|
+
.borders {
|
7
|
+
border-style: dotted;
|
8
|
+
}
|
9
|
+
.biohazard {
|
10
|
+
content: "death";
|
11
|
+
.man {
|
12
|
+
color: transparent;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
#theme > .mixin {
|
17
|
+
background-color: grey;
|
18
|
+
}
|
19
|
+
#container {
|
20
|
+
color: black;
|
21
|
+
.mixin, .mixout;
|
22
|
+
#theme > .mixin;
|
23
|
+
}
|
24
|
+
|
25
|
+
#header {
|
26
|
+
.milk {
|
27
|
+
color: white;
|
28
|
+
.mixin, #theme > .mixin;
|
29
|
+
}
|
30
|
+
#cookie {
|
31
|
+
.chips {
|
32
|
+
#namespace .borders;
|
33
|
+
.calories {
|
34
|
+
#container;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
.borders;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
.secure-zone { #namespace .biohazard .man; }
|
41
|
+
.direct {
|
42
|
+
#namespace > .borders;
|
43
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#operations {
|
2
|
+
color: #110000 + #000011 + #001100; // #111111
|
3
|
+
height: 10px / 2px + 6px - 1px * 2; // 9px
|
4
|
+
width: 2 * 4 - 5em; // 3em
|
5
|
+
.spacing {
|
6
|
+
height: 10px / 2px+6px-1px*2;
|
7
|
+
width: 2 * 4-5em;
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
@x: 4;
|
12
|
+
@y: 12em;
|
13
|
+
|
14
|
+
.with-variables {
|
15
|
+
height: @x + @y; // 16em
|
16
|
+
width: 12 + @y; // 24em
|
17
|
+
size: 5cm - @x; // 1cm
|
18
|
+
}
|
19
|
+
|
20
|
+
@z: -2;
|
21
|
+
|
22
|
+
.negative {
|
23
|
+
height: 2px + @z; // 0px
|
24
|
+
width: 2px - @z; // 4px
|
25
|
+
}
|
26
|
+
|
27
|
+
.shorthands {
|
28
|
+
padding: -1px 2px 0 -4px; //
|
29
|
+
}
|
30
|
+
|
31
|
+
.colors {
|
32
|
+
color: #123; // #123123
|
33
|
+
border-color: #234 + #111111; // #345345
|
34
|
+
background-color: #222222 - #fff; // #000000
|
35
|
+
.other {
|
36
|
+
color: 2 * #111; // #222222
|
37
|
+
border-color: #333333 / 3 + #111; // #222222
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#first > .one {
|
2
|
+
> #second .two > #deux {
|
3
|
+
width: 50%;
|
4
|
+
#third {
|
5
|
+
:focus {
|
6
|
+
color: black;
|
7
|
+
#fifth {
|
8
|
+
> #sixth {
|
9
|
+
.seventh #eighth {
|
10
|
+
+ #ninth {
|
11
|
+
color: purple;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
height: 100%;
|
18
|
+
}
|
19
|
+
#fourth, #five, #six {
|
20
|
+
color: #110000;
|
21
|
+
.seven, .eight > #nine {
|
22
|
+
border: 1px solid black;
|
23
|
+
}
|
24
|
+
#ten {
|
25
|
+
color: red;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
font-size: 2em;
|
30
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
@x: blue;
|
2
|
+
@z: transparent;
|
3
|
+
@mix: none;
|
4
|
+
|
5
|
+
.mixin {
|
6
|
+
@mix: #989;
|
7
|
+
}
|
8
|
+
|
9
|
+
.tiny-scope {
|
10
|
+
color: @mix; // none
|
11
|
+
.mixin;
|
12
|
+
border-color: @mix; // #989
|
13
|
+
}
|
14
|
+
|
15
|
+
.scope1 {
|
16
|
+
@y: orange;
|
17
|
+
@z: black;
|
18
|
+
color: @x; // blue
|
19
|
+
border-color: @z; // black
|
20
|
+
.hidden {
|
21
|
+
@x: #131313;
|
22
|
+
}
|
23
|
+
.scope2 {
|
24
|
+
@y: red;
|
25
|
+
color: @x; // blue
|
26
|
+
.scope3 {
|
27
|
+
@local: white;
|
28
|
+
color: @y; // red
|
29
|
+
border-color: @z; // black
|
30
|
+
background-color: @local; // white
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#strings {
|
2
|
+
background-image: url("http://son-of-a-banana.com");
|
3
|
+
quotes: "~" "~";
|
4
|
+
content: "#*%:&^,)!.(~*})";
|
5
|
+
empty: "";
|
6
|
+
}
|
7
|
+
#comments {
|
8
|
+
content: "/* hello */ // not-so-secret";
|
9
|
+
}
|
10
|
+
#single-quote {
|
11
|
+
quotes: "'" "'";
|
12
|
+
content: '""#!&""';
|
13
|
+
empty: '';
|
14
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
.whitespace
|
2
|
+
{ color: white; }
|
3
|
+
.whitespace
|
4
|
+
{
|
5
|
+
color: white;
|
6
|
+
}
|
7
|
+
.whitespace
|
8
|
+
{ color: white; }
|
9
|
+
|
10
|
+
.whitespace{color:white;}
|
11
|
+
.whitespace { color : white ; }
|
12
|
+
|
13
|
+
.white,
|
14
|
+
.space,
|
15
|
+
.mania
|
16
|
+
{ color: white; }
|
17
|
+
|
18
|
+
.no-semi-column { color: white }
|
19
|
+
.empty {
|
20
|
+
|
21
|
+
}
|
data/spec/spec.css
CHANGED
@@ -1,28 +1,86 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
.
|
8
|
-
.
|
1
|
+
/* Generated with Less 1.0.0 */
|
2
|
+
|
3
|
+
.theme {
|
4
|
+
color: #cccccc;
|
5
|
+
background-color: #aaaaaa;
|
6
|
+
}
|
7
|
+
.extra .dark-borders { border-color: #444444; }
|
8
|
+
.extra .light-borders { border-color: #888888; }
|
9
|
+
body { font-family: sans-serif; }
|
10
|
+
div > p a { font-family: sans-serif; }
|
11
|
+
h2 a > span:first-child { font-family: sans-serif; }
|
12
|
+
.root a {
|
13
|
+
color: blue;
|
14
|
+
display: none;
|
15
|
+
}
|
16
|
+
.root a:hover { color: orange; }
|
17
|
+
.root a:focus { color: orange; }
|
18
|
+
.root .first { color: green; }
|
19
|
+
.root .first .second .third {
|
20
|
+
background-color: blue;
|
21
|
+
font-size: 8px;
|
22
|
+
color: red;
|
23
|
+
border-color: red;
|
24
|
+
}
|
9
25
|
.root:hover a { display: block; }
|
10
|
-
body {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
26
|
+
body {
|
27
|
+
font-size: 10px;
|
28
|
+
font-family: "Lucida Grande", 'Helvetica', Verdana, sans-serif;
|
29
|
+
margin: -5px 0 5px 10px;
|
30
|
+
border: solid 1px #000000;
|
31
|
+
text-shadow: #333333 -1px 1px 2px;
|
32
|
+
-moz-border-radius: 3px;
|
33
|
+
color: #cccccc;
|
34
|
+
background-color: #aaaaaa;
|
35
|
+
}
|
36
|
+
#operations {
|
37
|
+
font: 12px/16px;
|
38
|
+
width: 110px;
|
39
|
+
font-size: 66;
|
40
|
+
color: #eeeeee;
|
41
|
+
colorb: #333333;
|
42
|
+
colorc: #777777;
|
43
|
+
}
|
44
|
+
#operations div { width: 80px; }
|
45
|
+
td { border-width: 88px; }
|
46
|
+
tr { border-width: 88px; }
|
47
|
+
table { border-width: 88px; }
|
48
|
+
blockquote:before { content: ""; }
|
49
|
+
blockquote:after { content: ""; }
|
50
|
+
q:before { content: ""; }
|
51
|
+
q:after { content: ""; }
|
52
|
+
a:link { color: brown; }
|
53
|
+
a:hover { color: brown; }
|
54
|
+
div > a { color: grey; }
|
55
|
+
a span { color: grey; }
|
17
56
|
ul li:first-child { border-top: none; }
|
18
|
-
ul li:first-child
|
57
|
+
ul li:first-child { background-color: #333333; }
|
58
|
+
ul li:last-child { background-color: #333333; }
|
19
59
|
.p:first-letter { color: red; }
|
20
|
-
h5:focus {
|
21
|
-
|
60
|
+
h5:focus {
|
61
|
+
outline: 0;
|
62
|
+
content: "*}#f~ ";
|
63
|
+
}
|
64
|
+
q:lang(no) { quotes: "~" "~"; }
|
22
65
|
blockquote:before { color: red; }
|
66
|
+
div { width: 9px; }
|
23
67
|
div { color: purple; }
|
24
|
-
.duplicate {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
.
|
68
|
+
.duplicate {
|
69
|
+
width: 9px;
|
70
|
+
height: 11px;
|
71
|
+
}
|
72
|
+
.duplicate {
|
73
|
+
width: 11px;
|
74
|
+
color: blue;
|
75
|
+
}
|
76
|
+
.loading { background: "http://"; }
|
77
|
+
input[type="text"] { background-color: blue; }
|
78
|
+
.transparent_box {
|
79
|
+
background-color: #ffffff;
|
80
|
+
opacity: 0.6;
|
81
|
+
}
|
82
|
+
.space {
|
83
|
+
color: purple;
|
84
|
+
font-color: yellow;
|
85
|
+
}
|
86
|
+
.no-semi-column { color: orange; }
|
data/spec/spec.less
CHANGED
@@ -131,14 +131,13 @@ div {
|
|
131
131
|
width: 11px;
|
132
132
|
color: blue;
|
133
133
|
}
|
134
|
-
|
134
|
+
.loading { background: "http://"; }
|
135
135
|
input[type="text"] {
|
136
136
|
background-color: blue;
|
137
137
|
}
|
138
138
|
.transparent_box {
|
139
|
-
background-color
|
140
|
-
|
141
|
-
opacity:0.6; /* CSS3 standard */
|
139
|
+
background-color: #FFF;
|
140
|
+
opacity: 0.6; /* CSS3 standard */
|
142
141
|
}
|
143
142
|
|
144
143
|
// Spacing
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudhead-less
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cloudhead
|
@@ -9,12 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-08 00:00:00 -07:00
|
13
13
|
default_executable: lessc
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: LESS is leaner CSS
|
17
|
-
email:
|
17
|
+
email: self@cloudhead.net
|
18
18
|
executables:
|
19
19
|
- lessc
|
20
20
|
extensions: []
|
@@ -33,20 +33,54 @@ files:
|
|
33
33
|
- lib/less.rb
|
34
34
|
- lib/less/command.rb
|
35
35
|
- lib/less/engine.rb
|
36
|
-
- lib/less/
|
36
|
+
- lib/less/engine/builder.rb
|
37
|
+
- lib/less/engine/less.tt
|
38
|
+
- lib/less/engine/nodes.rb
|
39
|
+
- lib/less/engine/nodes/element.rb
|
40
|
+
- lib/less/engine/nodes/entity.rb
|
41
|
+
- lib/less/engine/nodes/function.rb
|
42
|
+
- lib/less/engine/nodes/literal.rb
|
43
|
+
- lib/less/engine/nodes/property.rb
|
44
|
+
- lib/less/engine/nodes/selector.rb
|
45
|
+
- lib/less/engine/parser.rb
|
37
46
|
- spec/command_spec.rb
|
38
|
-
- spec/css/
|
39
|
-
- spec/css/
|
40
|
-
- spec/css/
|
41
|
-
- spec/css/
|
42
|
-
- spec/css/
|
43
|
-
- spec/css/
|
44
|
-
- spec/css/
|
47
|
+
- spec/css/accessors-1.0.css
|
48
|
+
- spec/css/big-1.0.css
|
49
|
+
- spec/css/comments-1.0.css
|
50
|
+
- spec/css/css-1.0.css
|
51
|
+
- spec/css/functions-1.0.css
|
52
|
+
- spec/css/import-1.0.css
|
53
|
+
- spec/css/mixins-1.0.css
|
54
|
+
- spec/css/operations-1.0.css
|
55
|
+
- spec/css/rulesets-1.0.css
|
56
|
+
- spec/css/scope-1.0.css
|
57
|
+
- spec/css/strings-1.0.css
|
58
|
+
- spec/css/variables-1.0.css
|
59
|
+
- spec/css/whitespace-1.0.css
|
45
60
|
- spec/engine_spec.rb
|
61
|
+
- spec/less/accessors-1.0.less
|
62
|
+
- spec/less/big-1.0.less
|
63
|
+
- spec/less/colors-1.0.less
|
64
|
+
- spec/less/comments-1.0.less
|
65
|
+
- spec/less/css-1.0.less
|
66
|
+
- spec/less/exceptions/mixed-units-error.less
|
67
|
+
- spec/less/exceptions/name-error-1.0.less
|
68
|
+
- spec/less/exceptions/syntax-error-1.0.less
|
69
|
+
- spec/less/functions-1.0.less
|
70
|
+
- spec/less/import-1.0.less
|
71
|
+
- spec/less/import/import-test-a.less
|
72
|
+
- spec/less/import/import-test-b.less
|
73
|
+
- spec/less/import/import-test-c.less
|
74
|
+
- spec/less/mixins-1.0.less
|
75
|
+
- spec/less/operations-1.0.less
|
76
|
+
- spec/less/rulesets-1.0.less
|
77
|
+
- spec/less/scope-1.0.less
|
78
|
+
- spec/less/strings-1.0.less
|
79
|
+
- spec/less/variables-1.0.less
|
80
|
+
- spec/less/whitespace-1.0.less
|
46
81
|
- spec/spec.css
|
47
82
|
- spec/spec.less
|
48
83
|
- spec/spec_helper.rb
|
49
|
-
- spec/tree_spec.rb
|
50
84
|
has_rdoc: true
|
51
85
|
homepage: http://www.lesscss.org
|
52
86
|
post_install_message:
|
@@ -77,4 +111,3 @@ test_files:
|
|
77
111
|
- spec/command_spec.rb
|
78
112
|
- spec/engine_spec.rb
|
79
113
|
- spec/spec_helper.rb
|
80
|
-
- spec/tree_spec.rb
|
data/lib/less/tree.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
module Less
|
2
|
-
class Tree < Hash
|
3
|
-
def initialize init = {}
|
4
|
-
self.replace init
|
5
|
-
end
|
6
|
-
|
7
|
-
def var k
|
8
|
-
self[:variables] ? self[:variables][ k ] : nil
|
9
|
-
end
|
10
|
-
|
11
|
-
def vars?
|
12
|
-
self.include? :variables
|
13
|
-
end
|
14
|
-
|
15
|
-
def vars
|
16
|
-
self[:variables] ? self[:variables] : nil
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
# Find a variable or mixin from a specific path
|
21
|
-
#
|
22
|
-
def find what = :var, path = []
|
23
|
-
path.inject(self) do |branch, k|
|
24
|
-
if what == :var && k == path.last
|
25
|
-
branch[:variables][ k ]
|
26
|
-
else
|
27
|
-
branch = branch[ k ] or raise PathError, path.join(' > ')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# Find the nearest variable in the hierarchy
|
34
|
-
#
|
35
|
-
def nearest var, path
|
36
|
-
values = []
|
37
|
-
path.inject(self) do |branch, k|
|
38
|
-
values << branch.var( var )
|
39
|
-
branch[ k ]
|
40
|
-
end
|
41
|
-
values.compact.last
|
42
|
-
end
|
43
|
-
|
44
|
-
def traverse by = :leaf, path = [], &blk
|
45
|
-
#
|
46
|
-
# Traverse the whole tree, returning each leaf or branch (recursive)
|
47
|
-
#
|
48
|
-
###
|
49
|
-
# Aside from the key & value, we yield the full path of the leaf,
|
50
|
-
# aswell as the branch which contains it (self).
|
51
|
-
# Note that in :branch mode, we only return 'twigs', branches which contain leaves.
|
52
|
-
#
|
53
|
-
self.each do |key, value| # `self` is the current node, starting with the trunk
|
54
|
-
if value.is_a? Hash and key != :variables # If the node is a branch, we can go deeper
|
55
|
-
path << key # Add the current branch to the path
|
56
|
-
yield path, self[ key ] if by == :branch # The node is a branch, yield it to the block
|
57
|
-
self[ key ] = value.to_tree. # Make sure any change is saved to the main tree
|
58
|
-
traverse by, path, &blk # Recurse, with the current node becoming `self`
|
59
|
-
path.pop # We're returning from a branch, pop the last path element
|
60
|
-
elsif by == :leaf and key.is_a? String
|
61
|
-
yield key, value, path, self # The node is a leaf, yield it to the block
|
62
|
-
else
|
63
|
-
next
|
64
|
-
end
|
65
|
-
end
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# Convert the tree to css, using full paths
|
71
|
-
#
|
72
|
-
def to_css chain, css = []
|
73
|
-
self.traverse :branch do |path, node|
|
74
|
-
properties = node.inject("") do |s, (k, v)|
|
75
|
-
v.is_a?(String) ? (s + "#{k}: #{CGI.unescape(v)}; ") : s # Add the property to the list
|
76
|
-
end
|
77
|
-
css << path * ( chain == :desc ? ' ' : ' > ') + " { " + properties + "}" unless properties.empty? # Add the rule-set to the CSS
|
78
|
-
end
|
79
|
-
css.join "\n"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|