sassificator 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -12
- data/lib/sassificator.rb +18 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YjkxZDYwMDE1MTRmYjM3OTdiMmY1ZmViNmEwZmVlMWFkZjcyYTQxNA==
|
3
|
+
metadata.gz: 390fc141a58ee31ba2bb65188e62eeac0c7d826b
|
4
|
+
data.tar.gz: 4b337475041f992449a2481790fc751b45689dee
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
Y2Y0ODUwN2JjOThjZjRkMjY4ZGJlMDhlMjQzOGM4Yzk4MTg5MWE0MGY2NWY2
|
11
|
-
MjFiNjcyNTg5ZTI5YjcwYTFkZjIwNDcyZGI3NzE5MjhiYTQ1ZTA=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NmExNmEzMWVkNzQxMTI2YTkzMTI3MWQ4ZGMyOTgwMzBkNWY5MzdhMzQ5NTRi
|
14
|
-
NDU3MjYzZjgxY2UyZjk0YjU0MGZmYWVjNWNkNjgwZjk3ZTVjNTY4OWNkZmU2
|
15
|
-
YTkxYWZiOTY3ZjllMzU5YmVjYWExZDg3NTk5ZWI5ZGQ5ZDRiY2Y=
|
6
|
+
metadata.gz: 96fc95dabd748618691e89470bc4f7a53d8f182c62a6f3ecc05f75061a5bdecfcc1aa44f5d2f7532d9df4bae5ccc9889443e3ea74e36b027b4ab267dcaea7cb4
|
7
|
+
data.tar.gz: 6ff9d0aa6539d6e14a40742738f0cf6b5884c6da74215835f214bc6e04aa3063d2e3e7ae057824422acd1dda7c6045fd9fcc579ebffc1f55b706df574174eabb
|
data/lib/sassificator.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
#TODO:
|
2
|
-
# - mediaquery inside of a mediaquery
|
2
|
+
# - mediaquery inside of a mediaquery - done partically (only for one tree level deep)
|
3
3
|
# - images formating pattern setting
|
4
4
|
# - add convertor: all #_colors_ to rgb
|
5
5
|
# - MAJOR: formatting is done only for output sass_string, but not for sass_obj. Move formatting options applyment to object creation
|
6
|
+
# - write tests
|
7
|
+
# - had issue with [] brackets - test
|
8
|
+
# - had issue with asset-url asigning - test - background: asset-url('#{$brand}offersButton_on.png',image',image) 100% 50% no-repeat;
|
9
|
+
# background: asset-url('#{$brand}//offersButton_on.png) 100% 50% no-repeat;
|
10
|
+
# - issue with assigning same roles one after onother
|
6
11
|
|
7
12
|
class Sassificator
|
8
13
|
attr_accessor :colors_to_vars
|
@@ -20,6 +25,7 @@ class Sassificator
|
|
20
25
|
@colors_to_vars = (param[:colors_to_vars] != false) != false
|
21
26
|
@fromat_image_declarations = (param[:fromat_image_declarations] != false) != false
|
22
27
|
@download_images = (param[:download_images] != false) != false
|
28
|
+
|
23
29
|
@image_assets_path = param[:image_assets_path] ? param[:image_assets_path] : ''
|
24
30
|
@output_path = param[:output_path] ? param[:output_path] : "#{ENV['HOME']}/Desktop/sassificator_output/"
|
25
31
|
end
|
@@ -57,12 +63,17 @@ class Sassificator
|
|
57
63
|
line.gsub(/\n/,'').gsub(/\t/,'').gsub(/\s+(?=\})/,'').gsub(/(?<=\{)\s+/,'')
|
58
64
|
end
|
59
65
|
|
66
|
+
def prepare_input_css(input_css)
|
67
|
+
## 1. reduses double :: pseudo selectors to :
|
68
|
+
## 2. removes empty rules
|
69
|
+
input_css.gsub(/::/,':').gsub(/^.+{[\s\t\n]{0,}}/,'')
|
70
|
+
end
|
71
|
+
|
60
72
|
def css_to_hash (input_css)
|
61
|
-
input_css = input_css
|
73
|
+
input_css = prepare_input_css(input_css)
|
62
74
|
selectors_arr = remove_white_spaces_and_new_lines(input_css).gsub(/@media/,"\n@media").gsub(/(?<={{1}).+}(?=[\s\t\n]{0,}}{1})/,'').gsub(/(?<={{1}).+}(?=[\s\t\n]{0,}}{1})/,'').scan(/[^{^}]+(?=\{)/).map {|line| line.sub(/^\s+/,'').sub(/\s+$/,'')}
|
63
75
|
rules_arr = remove_white_spaces_and_new_lines(input_css).gsub(/@media/,"\n@media").scan(/(((?<={{1}).+}(?=[\s\t\n]{0,}}{1})|(?<=\{)[^}]+\}{0,}[\\t\\n\s]{0,}(?=\}))|((?<=\{)[^}]+\}{0,}[\\t\\n\s]{0,}(?=\}))|(?<={{1}).+}(?=[\s\t\n]{0,}}{1}))/).map {|item| item.compact.uniq.join} #super-mega reg-exp that scans for normal rules as well as inlined media-query rule + make a single_string_items out of matched array groups
|
64
76
|
return_hash = {}
|
65
|
-
|
66
77
|
selectors_arr.each_with_index do |selector, index|
|
67
78
|
unless return_hash[selector]
|
68
79
|
return_hash[selector] = rules_arr[index.to_i]
|
@@ -93,7 +104,6 @@ class Sassificator
|
|
93
104
|
#TODO : optimize this
|
94
105
|
unless sub_pat.empty?
|
95
106
|
unless selector.match(/,/)
|
96
|
-
|
97
107
|
match = sub_pat
|
98
108
|
selector = selector.sub( Regexp.new('^'+match) ,match+' &')
|
99
109
|
end
|
@@ -104,7 +114,7 @@ class Sassificator
|
|
104
114
|
node = CssNode.new
|
105
115
|
childrens_stack[match] = node
|
106
116
|
end
|
107
|
-
node.uninitialized[selector.sub( Regexp.new('^'+match+' ') ,'')] = rule
|
117
|
+
node.uninitialized[selector.sub( Regexp.new('^'+match.sub( /\[/ ,'\[').sub(/\]/, '\]')+' ') ,'')] = rule
|
108
118
|
node.parent = parent_node
|
109
119
|
else
|
110
120
|
if node = childrens_stack[selector]
|
@@ -167,7 +177,7 @@ class Sassificator
|
|
167
177
|
sassed_str.scan(/(url\((((http[s]{0,1}:\/\/)([a-z0-9].+\.[a-z]+).+)(\/.+)))\)/).each do |match|
|
168
178
|
#TODO: optimize this - move mathched to variables for clarification of match
|
169
179
|
formated_rule = formated_rule.sub(Regexp.new(match[0].gsub(/\(/,'\(').gsub(match[5],'')),'asset-url(\''+@image_assets_path)
|
170
|
-
.sub( Regexp.new(match[5]),match[5].sub(/\//,'')+'\'
|
180
|
+
.sub( Regexp.new(match[5]),match[5].sub(/\//,'')+'\'')
|
171
181
|
|
172
182
|
Net::HTTP.start(match[4]) do |http|
|
173
183
|
resp = http.get(match[1])
|
@@ -189,6 +199,7 @@ class Sassificator
|
|
189
199
|
end
|
190
200
|
|
191
201
|
def format_color(sassed_str)
|
202
|
+
#TODO: resolve the match for colors in format #sdsd
|
192
203
|
formated_rule = sassed_str
|
193
204
|
color_hash = {}
|
194
205
|
sassed_str.scan(/rgba\([0-9\,\s\.]+\)|rgb\([0-9\,\s\.]+\)|#[0-9A-Za-z]+(?=;)/).each do|m|
|
@@ -200,7 +211,7 @@ class Sassificator
|
|
200
211
|
end
|
201
212
|
|
202
213
|
color_hash.invert.to_a.reverse_each {|m|
|
203
|
-
formated_rule = m.join(":")+"
|
214
|
+
formated_rule = m.join(":")+";\n" + formated_rule
|
204
215
|
}
|
205
216
|
|
206
217
|
formated_rule
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sassificator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Fromrome
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Converts Css formatted code to Sass. Generates a Sass formatted hierarchy
|
14
14
|
object, as well as properly formatted Sass code text
|
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
40
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.2.
|
41
|
+
rubygems_version: 2.2.2
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: A tool for parsing Css to Sass
|