visionmedia-ass 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +4 -0
- data/ass.gemspec +2 -2
- data/examples/benchmarks.rb +47 -5
- data/lib/ass/parser.rb +45 -50
- data/lib/ass/version.rb +1 -1
- data/spec/functional/parser_spec.rb +25 -7
- metadata +2 -2
data/History.rdoc
CHANGED
data/ass.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ass}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
9
|
-
s.date = %q{2009-01-
|
9
|
+
s.date = %q{2009-01-19}
|
10
10
|
s.default_executable = %q{ass}
|
11
11
|
s.description = %q{'Amazing Style Sheets'}
|
12
12
|
s.email = %q{tj@vision-media.ca}
|
data/examples/benchmarks.rb
CHANGED
@@ -1,7 +1,50 @@
|
|
1
1
|
|
2
2
|
$:.unshift File.dirname(__FILE__) + '/../lib/'
|
3
|
+
|
3
4
|
require 'ass'
|
4
|
-
require '
|
5
|
+
require 'rubygems'
|
6
|
+
require 'sass'
|
7
|
+
require 'rgauge'
|
8
|
+
|
9
|
+
large_sass = <<-SASS
|
10
|
+
=highlighted-background
|
11
|
+
background:
|
12
|
+
color: #fc0
|
13
|
+
=header-text
|
14
|
+
font:
|
15
|
+
size: 20px
|
16
|
+
|
17
|
+
=compound
|
18
|
+
+highlighted-background
|
19
|
+
+header-text
|
20
|
+
|
21
|
+
.page-title
|
22
|
+
+header-text
|
23
|
+
:padding 4px
|
24
|
+
:margin
|
25
|
+
:top 10px
|
26
|
+
|
27
|
+
#footer
|
28
|
+
:padding 0
|
29
|
+
:margin 15px 1px
|
30
|
+
:background red
|
31
|
+
|
32
|
+
.copyright < somethng
|
33
|
+
:color green
|
34
|
+
|
35
|
+
:hover
|
36
|
+
:background
|
37
|
+
:color red
|
38
|
+
|
39
|
+
body
|
40
|
+
:color #fff
|
41
|
+
|
42
|
+
a
|
43
|
+
:font
|
44
|
+
:size 12px
|
45
|
+
:family "Arial"
|
46
|
+
:weight bold
|
47
|
+
SASS
|
5
48
|
|
6
49
|
large_ass = <<-ASS
|
7
50
|
/* Inline comment
|
@@ -67,9 +110,8 @@ a
|
|
67
110
|
|
68
111
|
ASS
|
69
112
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
113
|
+
benchmark 'Parsing Speed', :times => 20 do
|
114
|
+
report('Large Ass') { Ass::Parser.parse(large_ass) }
|
115
|
+
report('Large Sass') { Sass::Engine.new(large_sass).render }
|
74
116
|
end
|
75
117
|
|
data/lib/ass/parser.rb
CHANGED
@@ -20,7 +20,7 @@ module Ass
|
|
20
20
|
PROPERTY = /^ *#{HYPHENATED_WORD}/
|
21
21
|
|
22
22
|
attr_accessor :ass, :constants, :css
|
23
|
-
alias :to_s :
|
23
|
+
alias :to_s :css
|
24
24
|
|
25
25
|
def initialize ass = ''
|
26
26
|
@ass, @css, @constants = ass, '', {}
|
@@ -32,64 +32,59 @@ module Ass
|
|
32
32
|
last_selector = ''
|
33
33
|
lines = @ass.split "\n"
|
34
34
|
lines.each do |line|
|
35
|
-
|
35
|
+
|
36
|
+
case line
|
37
|
+
when COMMENT
|
36
38
|
@css << "/* #{$1.strip} */\n"
|
37
|
-
|
38
|
-
|
39
|
-
elsif not in_block and line.match MIXIN
|
40
|
-
in_mixin, in_block = $1, true
|
41
|
-
elsif in_block and line.match MIXIN
|
42
|
-
next if in_mixin
|
43
|
-
@css << mixins[$1]
|
44
|
-
elsif in_block and line.match BLANK
|
45
|
-
in_block = false
|
46
|
-
next if in_mixin
|
47
|
-
@css << CLOSING_BRACE
|
48
|
-
elsif line.match AT
|
49
|
-
@css << line << "\n"
|
50
|
-
elsif line.match BLANK or line.match ASS_COMMENT
|
51
|
-
# Do nothing
|
52
|
-
elsif not in_block and line.match SELECTOR
|
53
|
-
in_block = true
|
54
|
-
if sub_selector?($1, last_selector)
|
39
|
+
when MIXIN
|
40
|
+
if in_block
|
55
41
|
next if in_mixin
|
56
|
-
|
57
|
-
@css << selector << OPEN_BRACE
|
42
|
+
@css << mixins[$1]
|
58
43
|
else
|
59
|
-
in_mixin =
|
60
|
-
selector = $1.strip
|
61
|
-
@css << selector << OPEN_BRACE
|
44
|
+
in_mixin, in_block = $1, true
|
62
45
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
46
|
+
when CONSTANT_WITH_VALUE
|
47
|
+
@constants[$1.to_sym] = $2
|
48
|
+
when BLANK
|
49
|
+
if in_block
|
50
|
+
in_block = false
|
51
|
+
next if in_mixin
|
52
|
+
@css << CLOSING_BRACE
|
53
|
+
end
|
54
|
+
when AT
|
55
|
+
@css << line << "\n"
|
56
|
+
else
|
57
|
+
if not in_block and line.match SELECTOR
|
58
|
+
in_block = true
|
59
|
+
if nested_selector?($1, last_selector)
|
60
|
+
next if in_mixin
|
61
|
+
selector = splice_selectors last_selector, $1.strip
|
62
|
+
@css << selector << OPEN_BRACE
|
63
|
+
else
|
64
|
+
in_mixin = false
|
65
|
+
selector = $1.strip
|
66
|
+
@css << selector << OPEN_BRACE
|
67
|
+
end
|
68
|
+
last_selector = selector
|
69
|
+
elsif line.match PROPERTY
|
70
|
+
if mixin = in_mixin
|
71
|
+
mixins[mixin] << format_property(line)
|
72
|
+
else
|
73
|
+
@css << format_property(line)
|
74
|
+
end
|
69
75
|
end
|
70
76
|
end
|
71
77
|
end
|
72
78
|
self
|
73
79
|
end
|
74
80
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
selector_a.split(',').collect { |selector| selector << selector_b }.join(',')
|
79
|
-
else
|
80
|
-
selector_a << selector_b
|
81
|
-
end
|
82
|
-
else
|
83
|
-
if selector_a.include? ','
|
84
|
-
selector_a.split(',').collect { |selector| selector << ' ' << selector_b }.join(',')
|
85
|
-
else
|
86
|
-
selector_a << ' ' << selector_b
|
87
|
-
end
|
88
|
-
end
|
81
|
+
def splice_selectors selector_a, selector_b
|
82
|
+
selector_b[0,0] = ' ' unless selector_b[0,1] == ':'
|
83
|
+
selector_a.strip.gsub(/([^,]+),/, "\\1#{selector_b},") << selector_b
|
89
84
|
end
|
90
85
|
|
91
|
-
def
|
92
|
-
|
86
|
+
def nested_selector? selector_a, selector_b
|
87
|
+
indents_in(selector_a) > indents_in(selector_b)
|
93
88
|
end
|
94
89
|
|
95
90
|
def indents_in string
|
@@ -98,9 +93,9 @@ module Ass
|
|
98
93
|
|
99
94
|
def format_property line
|
100
95
|
line.gsub! PROPERTY, ' \1:'
|
101
|
-
line.gsub! CONSTANT do |constant|
|
102
|
-
|
103
|
-
@constants[
|
96
|
+
line.gsub! CONSTANT do |constant|
|
97
|
+
constant[0,1] = ''
|
98
|
+
@constants[constant.to_sym] || 'undefined_constant'
|
104
99
|
end
|
105
100
|
line << ";\n"
|
106
101
|
end
|
data/lib/ass/version.rb
CHANGED
@@ -12,15 +12,15 @@ describe Ass::Parser do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should determine sub selectors" do
|
15
|
-
@parser.
|
16
|
-
@parser.
|
15
|
+
@parser.nested_selector?(' sub', 'primary').should be_true
|
16
|
+
@parser.nested_selector?('primary', 'primary').should be_false
|
17
17
|
end
|
18
18
|
|
19
|
-
it "should
|
20
|
-
@parser.
|
21
|
-
@parser.
|
22
|
-
@parser.
|
23
|
-
@parser.
|
19
|
+
it "should splice sub selectors" do
|
20
|
+
@parser.splice_selectors('a', ':hover').should == 'a:hover'
|
21
|
+
@parser.splice_selectors('h1', 'a').should == 'h1 a'
|
22
|
+
@parser.splice_selectors('h1, h2, h3', ':hover').should == 'h1:hover, h2:hover, h3:hover'
|
23
|
+
@parser.splice_selectors('h1, h2, h3', 'a').should == 'h1 a, h2 a, h3 a'
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should populate constants" do
|
@@ -35,6 +35,24 @@ describe Ass::Parser do
|
|
35
35
|
@parser.constants[:tertiary_size].should == '9em'
|
36
36
|
end
|
37
37
|
|
38
|
+
it "should populate output undefined constant" do
|
39
|
+
@parser.ass = <<-ASS.deindent
|
40
|
+
:color = #fff
|
41
|
+
|
42
|
+
body
|
43
|
+
background :color
|
44
|
+
font :font_size
|
45
|
+
|
46
|
+
ASS
|
47
|
+
@parser.parse!
|
48
|
+
@parser.css.should == <<-CSS.deindent
|
49
|
+
body {
|
50
|
+
background: #fff;
|
51
|
+
font: undefined_constant;
|
52
|
+
}
|
53
|
+
CSS
|
54
|
+
end
|
55
|
+
|
38
56
|
it "should translate ass document from file" do
|
39
57
|
Ass::Parser.parse_file(File.dirname(__FILE__) + '/../fixtures/test.ass').should == <<-ASS.deindent
|
40
58
|
body.some-class {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visionmedia-ass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-19 00:00:00 -08:00
|
13
13
|
default_executable: ass
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|