beautiful-css 0.0.8 → 0.0.9
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/lib/beautiful-css/engine.rb +10 -3
- data/lib/beautiful-css/rule_parser.rb +10 -1
- data/lib/beautiful-css/version.rb +1 -1
- data/spec/convertions_spec.rb +43 -0
- metadata +3 -3
data/lib/beautiful-css/engine.rb
CHANGED
@@ -18,6 +18,7 @@ module BeautifulCss
|
|
18
18
|
|
19
19
|
def render
|
20
20
|
return nil if @input.nil?
|
21
|
+
save_imports
|
21
22
|
rules = build_rules
|
22
23
|
cleaned = remove_unset rules
|
23
24
|
groups = build_groups(cleaned)
|
@@ -27,11 +28,16 @@ module BeautifulCss
|
|
27
28
|
|
28
29
|
private
|
29
30
|
|
31
|
+
def save_imports
|
32
|
+
@imports = @input.scan(/@import[^;]+;/i)
|
33
|
+
end
|
34
|
+
|
30
35
|
def build_rules
|
31
36
|
text = scss_to_css @input
|
37
|
+
text = text.gsub(/@import[^;]+;/i, '') #remove imports
|
32
38
|
text = text.gsub( /[\n\r\t]/m, " " )
|
33
39
|
text = text.gsub( / +/m, " " )
|
34
|
-
text = text.gsub( /\/\*[^*]*\*\//m, " " )
|
40
|
+
text = text.gsub( /\/\*[^*]*\*\//m, " " ) #remove comments
|
35
41
|
rules = text.split('}')
|
36
42
|
rules = rules.map{|r| RuleParser.new(r).to_rules }.flatten
|
37
43
|
end
|
@@ -59,13 +65,14 @@ module BeautifulCss
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def format groups
|
62
|
-
output = ''
|
68
|
+
output = @imports.join('\n') + "\n"
|
69
|
+
|
63
70
|
groups.keys.sort.each do |key|
|
64
71
|
output += "\n"
|
65
72
|
output += groups[key].uniq.join(",\n") + "\n"
|
66
73
|
output += key + "\n"
|
67
74
|
end
|
68
|
-
output.gsub( /: +/, ':' )
|
75
|
+
output.gsub( /: +/, ':' ).strip
|
69
76
|
end
|
70
77
|
|
71
78
|
|
@@ -5,6 +5,8 @@ module BeautifulCss
|
|
5
5
|
|
6
6
|
def initialize(str)
|
7
7
|
@body = str
|
8
|
+
@body = @body.gsub( /url\( *data:/ , '__url_data__')
|
9
|
+
@body = @body.gsub( /;base64,/ , '__base64__')
|
8
10
|
end
|
9
11
|
|
10
12
|
def selectors
|
@@ -20,10 +22,17 @@ module BeautifulCss
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
25
|
+
def restore_special_strings str
|
26
|
+
str = str.gsub( /__url_data__/, 'url(data:')
|
27
|
+
str = str.gsub( /__base64__/, ';base64,')
|
28
|
+
str
|
29
|
+
end
|
30
|
+
|
23
31
|
def to_rules
|
24
32
|
selectors.map do |selector|
|
25
33
|
props.map do |prop|
|
26
|
-
|
34
|
+
val = restore_special_strings prop[1]
|
35
|
+
BeautifulCss::Rule.new(selector, prop[0], val)
|
27
36
|
end
|
28
37
|
end.flatten
|
29
38
|
end
|
data/spec/convertions_spec.rb
CHANGED
@@ -133,6 +133,49 @@ CLEAN
|
|
133
133
|
|
134
134
|
|
135
135
|
|
136
|
+
it 'should work with import' do
|
137
|
+
dirty = <<DIRTY
|
138
|
+
@import url("blargs.css");
|
139
|
+
a { color:green }
|
140
|
+
DIRTY
|
141
|
+
clean = <<CLEAN
|
142
|
+
@import url("blargs.css");
|
143
|
+
|
144
|
+
a
|
145
|
+
{ color:green }
|
146
|
+
CLEAN
|
147
|
+
assert_renders dirty, clean
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
it 'should work with base64 encoded images' do
|
154
|
+
dirty = <<DIRTY
|
155
|
+
a
|
156
|
+
{ background:url( data:image/png;base64,iVBORw0KGLKSsg= ); }
|
157
|
+
DIRTY
|
158
|
+
clean = <<CLEAN
|
159
|
+
a
|
160
|
+
{ background:url(data:image/png;base64,iVBORw0KGLKSsg=) }
|
161
|
+
CLEAN
|
162
|
+
assert_renders dirty, clean
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
136
179
|
def assert_renders(dirty,clean)
|
137
180
|
assert_equal clean.strip, convert(dirty).strip
|
138
181
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beautiful-css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A tool to help cleanup css
|
15
15
|
email:
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.8.
|
58
|
+
rubygems_version: 1.8.24
|
59
59
|
signing_key:
|
60
60
|
specification_version: 3
|
61
61
|
summary: reworks your css to make it simple and mantainable
|