hum 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -1
- data/README.md +6 -6
- data/lib/hum/array.rb +10 -6
- data/lib/hum/engine.rb +108 -31
- data/lib/hum/version.rb +1 -1
- data/test/engine_tests.rb +26 -1
- data/test/haml/anchor_links.haml +5 -0
- data/test/haml/direct_child.haml +6 -0
- data/test/haml/exclude_mixins.haml +6 -0
- data/test/haml/nested_direct_child.haml +6 -0
- data/test/haml/pseudo_elements.haml +6 -0
- data/test/sass/anchor_links.sass +2 -0
- data/test/sass/direct_child.sass +2 -0
- data/test/sass/exclude_mixins.sass +6 -0
- data/test/sass/nested_direct_child.sass +4 -0
- data/test/sass/pseudo_elements.sass +3 -0
- metadata +30 -10
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -16,10 +16,10 @@ Hum generates HTML from your SASS, SCSS or CSS.
|
|
16
16
|
.baz
|
17
17
|
color: red
|
18
18
|
|
19
|
-
|
19
|
+
#And crap out this HTML
|
20
20
|
<div class="foo">
|
21
21
|
<div class="bar">
|
22
|
-
<div class="baz"
|
22
|
+
<div class="baz">Inner content</div>
|
23
23
|
</div>
|
24
24
|
</div>
|
25
25
|
|
@@ -41,7 +41,7 @@ Hum generates HTML from your SASS, SCSS or CSS.
|
|
41
41
|
#And crap out this HTML
|
42
42
|
<div class="foo">
|
43
43
|
<div class="bar">
|
44
|
-
<div class="baz"
|
44
|
+
<div class="baz">Inner content</div>
|
45
45
|
</div>
|
46
46
|
</div>
|
47
47
|
|
@@ -56,14 +56,14 @@ Hum generates HTML from your SASS, SCSS or CSS.
|
|
56
56
|
.foo .bar{
|
57
57
|
font-size: 12px;
|
58
58
|
}
|
59
|
-
.foo .bar
|
59
|
+
.foo .bar .baz{
|
60
60
|
color: black;
|
61
61
|
}
|
62
62
|
|
63
63
|
#And crap out this HTML
|
64
64
|
<div class="foo">
|
65
65
|
<div class="bar">
|
66
|
-
<div class="baz"
|
66
|
+
<div class="baz">Inner content</div>
|
67
67
|
</div>
|
68
68
|
</div>
|
69
69
|
|
@@ -73,4 +73,4 @@ You can also watch a directory for changes to your SASS and SCSS files by using
|
|
73
73
|
|
74
74
|
## Notes
|
75
75
|
|
76
|
-
|
76
|
+
Hum doesn't work well with mixins that include selectors yet. Hum doesn't let you specify unique content for each HTML tag. Hum is pretty basic at the moment, so don't be too rough!
|
data/lib/hum/array.rb
CHANGED
@@ -40,10 +40,12 @@ class Array
|
|
40
40
|
#find the next one
|
41
41
|
found = self.find_line(next_line)
|
42
42
|
|
43
|
-
until found.nil? or hash[:tab]
|
43
|
+
until found.nil? or hash[:tab] >= found[:tab]
|
44
44
|
|
45
|
-
#collect it
|
46
|
-
|
45
|
+
#collect it if not a mixin
|
46
|
+
if !found[:exclude]
|
47
|
+
kids << found[:line]
|
48
|
+
end
|
47
49
|
|
48
50
|
#increment
|
49
51
|
next_line += 1
|
@@ -69,9 +71,11 @@ class Array
|
|
69
71
|
|
70
72
|
until found.nil? or next_line == hash[:line] or parent[:tab] == found[:tab]
|
71
73
|
|
72
|
-
#collect it
|
73
|
-
|
74
|
-
|
74
|
+
#collect it if not a mixin
|
75
|
+
if !found[:exclude]
|
76
|
+
kids << found[:line]
|
77
|
+
end
|
78
|
+
|
75
79
|
#increment
|
76
80
|
next_line += 1
|
77
81
|
|
data/lib/hum/engine.rb
CHANGED
@@ -53,7 +53,7 @@ module Hum
|
|
53
53
|
#close the output file
|
54
54
|
@output_file.close()
|
55
55
|
|
56
|
-
puts "updated #{@output_name}
|
56
|
+
puts "updated #{@output_name}".green
|
57
57
|
end
|
58
58
|
|
59
59
|
def run_haml
|
@@ -101,10 +101,19 @@ module Hum
|
|
101
101
|
|
102
102
|
def clean_sass
|
103
103
|
#remove all property: value; pairs
|
104
|
-
@sass.gsub!(
|
104
|
+
@sass.gsub!(/.*: .*/, "")
|
105
|
+
|
106
|
+
#make sure tabs are two spaces
|
107
|
+
@sass.gsub!(/\t/, " ")
|
108
|
+
|
109
|
+
#make sure nested direct descendant is normal
|
110
|
+
@sass.gsub!(/\& > /, "")
|
111
|
+
|
112
|
+
#make sure direct descendant is normal
|
113
|
+
@sass.gsub!(/ > /, " ")
|
105
114
|
|
106
115
|
#remove duplicate new lines
|
107
|
-
@sass.gsub!(
|
116
|
+
@sass.gsub!(/\n+/, "\n")
|
108
117
|
end
|
109
118
|
|
110
119
|
def build_hashes
|
@@ -136,6 +145,12 @@ module Hum
|
|
136
145
|
#process all tabs
|
137
146
|
_process_tabs
|
138
147
|
|
148
|
+
#process all mixins by fixing the tabs and removing the mixin
|
149
|
+
_process_mixins
|
150
|
+
|
151
|
+
#process all special selectors, like pseudo elements
|
152
|
+
_process_special
|
153
|
+
|
139
154
|
@tree
|
140
155
|
end
|
141
156
|
|
@@ -249,6 +264,58 @@ module Hum
|
|
249
264
|
}
|
250
265
|
end
|
251
266
|
|
267
|
+
def _process_mixins
|
268
|
+
#in each line
|
269
|
+
@tree.each { |hash|
|
270
|
+
|
271
|
+
#for each select
|
272
|
+
hash[:select].each do |code|
|
273
|
+
|
274
|
+
#if this is a mixin
|
275
|
+
if code.match(/\+/)
|
276
|
+
hash[:exclude] = true
|
277
|
+
|
278
|
+
#if this is a named mixin
|
279
|
+
elsif code.match(/\=/)
|
280
|
+
|
281
|
+
#ignore the hash on output
|
282
|
+
hash[:exclude] = true
|
283
|
+
|
284
|
+
#find kids
|
285
|
+
kids = @tree.find_kids(hash)
|
286
|
+
|
287
|
+
#for each kid
|
288
|
+
kids.each { |kid|
|
289
|
+
|
290
|
+
#find it
|
291
|
+
child = @tree.find_line(kid)
|
292
|
+
|
293
|
+
#and reduce it by one
|
294
|
+
child[:tab] -= 1
|
295
|
+
}
|
296
|
+
end
|
297
|
+
end
|
298
|
+
}
|
299
|
+
end
|
300
|
+
|
301
|
+
def _process_special
|
302
|
+
#in each line
|
303
|
+
@tree.each { |hash|
|
304
|
+
|
305
|
+
#for each select
|
306
|
+
hash[:select].each do |code|
|
307
|
+
|
308
|
+
#if this has a pseudo element
|
309
|
+
if code.match(/:/)
|
310
|
+
|
311
|
+
#remove it
|
312
|
+
code.gsub!(/:.*/, "")
|
313
|
+
end
|
314
|
+
|
315
|
+
end
|
316
|
+
}
|
317
|
+
end
|
318
|
+
|
252
319
|
def _grab_select(code)
|
253
320
|
result = []
|
254
321
|
temp = code.gsub(/\n/, "").gsub(/ /, "")
|
@@ -289,6 +356,11 @@ module Hum
|
|
289
356
|
tag = tag.gsub("%#", "%div#")
|
290
357
|
end
|
291
358
|
|
359
|
+
#give all links an href
|
360
|
+
if tag.match("%a")
|
361
|
+
tag = tag.gsub("%a", "%a{:href=>'#'}")
|
362
|
+
end
|
363
|
+
|
292
364
|
tag
|
293
365
|
end
|
294
366
|
|
@@ -302,45 +374,50 @@ module Hum
|
|
302
374
|
@haml += "\t%body\n"
|
303
375
|
|
304
376
|
#time to build the HAML
|
305
|
-
@tree.each do |hash|
|
306
|
-
extra = []
|
377
|
+
@tree.each do |hash|
|
307
378
|
|
308
|
-
|
309
|
-
|
310
|
-
extra =
|
311
|
-
|
379
|
+
if hash[:exclude] != true
|
380
|
+
|
381
|
+
extra = []
|
382
|
+
|
383
|
+
#if there's a parent, find the extra kids
|
384
|
+
if !hash[:parent].nil?
|
385
|
+
extra = @tree.find_extra_kids(hash)
|
386
|
+
end
|
312
387
|
|
313
|
-
|
314
|
-
|
388
|
+
#for each generate the HAML line
|
389
|
+
hash[:haml].each { |haml_tag|
|
315
390
|
|
316
|
-
|
317
|
-
|
318
|
-
|
391
|
+
#if no extra, just normal
|
392
|
+
if extra.empty?
|
393
|
+
@haml += _generate_haml_line(haml_tag, hash)
|
319
394
|
|
320
|
-
|
321
|
-
|
395
|
+
#else extra
|
396
|
+
else
|
322
397
|
|
323
|
-
|
324
|
-
|
398
|
+
#this hash has extra kids
|
399
|
+
hash[:extra] = true
|
325
400
|
|
326
|
-
|
401
|
+
@haml += _generate_haml_line(haml_tag, hash)
|
327
402
|
|
328
|
-
|
329
|
-
|
403
|
+
#for each kid
|
404
|
+
extra.each { |line|
|
330
405
|
|
331
|
-
|
332
|
-
|
406
|
+
#get the hash
|
407
|
+
extra_hash = @tree.find_line(line)
|
333
408
|
|
334
|
-
|
335
|
-
|
409
|
+
#for each generate the HAML line
|
410
|
+
extra_hash[:haml].each do |haml_tag|
|
336
411
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
412
|
+
#do it
|
413
|
+
@haml += _generate_haml_line(haml_tag, extra_hash)
|
414
|
+
end
|
415
|
+
}
|
416
|
+
end
|
342
417
|
|
343
|
-
|
418
|
+
}
|
419
|
+
|
420
|
+
end
|
344
421
|
end
|
345
422
|
@haml
|
346
423
|
end
|
data/lib/hum/version.rb
CHANGED
data/test/engine_tests.rb
CHANGED
@@ -46,7 +46,32 @@ class HumText < Test::Unit::TestCase
|
|
46
46
|
@file = "parent_siblings"
|
47
47
|
quick_test
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
|
+
def test_exclude_mixins
|
51
|
+
@file = "exclude_mixins"
|
52
|
+
quick_test
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_direct_child
|
56
|
+
@file = "direct_child"
|
57
|
+
quick_test
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_nested_direct_child
|
61
|
+
@file = "nested_direct_child"
|
62
|
+
quick_test
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_anchor_links
|
66
|
+
@file = "anchor_links"
|
67
|
+
quick_test
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_pseudo_elements
|
71
|
+
@file = "pseudo_elements"
|
72
|
+
quick_test
|
73
|
+
end
|
74
|
+
|
50
75
|
private
|
51
76
|
|
52
77
|
def quick_test
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sass
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153483860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.12
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153483860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: haml
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153483160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.4
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153483160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fssm
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153482500 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.2.7
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153482500
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: colored
|
49
|
-
requirement: &
|
49
|
+
requirement: &2153481820 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '1.2'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2153481820
|
58
58
|
description: Hum generates HTML from your SASS or CSS. View more info at github.com/jefweg/hum
|
59
59
|
email:
|
60
60
|
- jeff@jwegesin.com
|
@@ -79,20 +79,30 @@ files:
|
|
79
79
|
- lib/hum/version.rb
|
80
80
|
- test/bad_file_test.rb
|
81
81
|
- test/engine_tests.rb
|
82
|
+
- test/haml/anchor_links.haml
|
83
|
+
- test/haml/direct_child.haml
|
84
|
+
- test/haml/exclude_mixins.haml
|
82
85
|
- test/haml/insert_extra_child.haml
|
86
|
+
- test/haml/nested_direct_child.haml
|
83
87
|
- test/haml/nests.haml
|
84
88
|
- test/haml/parent_selector.haml
|
85
89
|
- test/haml/parent_siblings.haml
|
86
90
|
- test/haml/property_value.haml
|
91
|
+
- test/haml/pseudo_elements.haml
|
87
92
|
- test/haml/siblings.haml
|
88
93
|
- test/haml/single_line_nest.haml
|
89
94
|
- test/other/bad.file
|
90
95
|
- test/other/example.scss
|
96
|
+
- test/sass/anchor_links.sass
|
97
|
+
- test/sass/direct_child.sass
|
98
|
+
- test/sass/exclude_mixins.sass
|
91
99
|
- test/sass/insert_extra_child.sass
|
100
|
+
- test/sass/nested_direct_child.sass
|
92
101
|
- test/sass/nests.sass
|
93
102
|
- test/sass/parent_selector.sass
|
94
103
|
- test/sass/parent_siblings.sass
|
95
104
|
- test/sass/property_value.sass
|
105
|
+
- test/sass/pseudo_elements.sass
|
96
106
|
- test/sass/siblings.sass
|
97
107
|
- test/sass/single_line_nest.sass
|
98
108
|
- test/sass_convert_test.rb
|
@@ -123,20 +133,30 @@ summary: Generate HTML from your SASS or CSS
|
|
123
133
|
test_files:
|
124
134
|
- test/bad_file_test.rb
|
125
135
|
- test/engine_tests.rb
|
136
|
+
- test/haml/anchor_links.haml
|
137
|
+
- test/haml/direct_child.haml
|
138
|
+
- test/haml/exclude_mixins.haml
|
126
139
|
- test/haml/insert_extra_child.haml
|
140
|
+
- test/haml/nested_direct_child.haml
|
127
141
|
- test/haml/nests.haml
|
128
142
|
- test/haml/parent_selector.haml
|
129
143
|
- test/haml/parent_siblings.haml
|
130
144
|
- test/haml/property_value.haml
|
145
|
+
- test/haml/pseudo_elements.haml
|
131
146
|
- test/haml/siblings.haml
|
132
147
|
- test/haml/single_line_nest.haml
|
133
148
|
- test/other/bad.file
|
134
149
|
- test/other/example.scss
|
150
|
+
- test/sass/anchor_links.sass
|
151
|
+
- test/sass/direct_child.sass
|
152
|
+
- test/sass/exclude_mixins.sass
|
135
153
|
- test/sass/insert_extra_child.sass
|
154
|
+
- test/sass/nested_direct_child.sass
|
136
155
|
- test/sass/nests.sass
|
137
156
|
- test/sass/parent_selector.sass
|
138
157
|
- test/sass/parent_siblings.sass
|
139
158
|
- test/sass/property_value.sass
|
159
|
+
- test/sass/pseudo_elements.sass
|
140
160
|
- test/sass/siblings.sass
|
141
161
|
- test/sass/single_line_nest.sass
|
142
162
|
- test/sass_convert_test.rb
|