hum 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/CHANGELOG.md +5 -1
  2. data/README.md +61 -20
  3. data/hum.gemspec +4 -3
  4. data/lib/hum/array.rb +41 -18
  5. data/lib/hum/engine.rb +205 -190
  6. data/lib/hum/exec.rb +3 -2
  7. data/lib/hum/version.rb +1 -1
  8. data/test/bad_file_test.rb +28 -0
  9. data/test/engine_tests.rb +132 -0
  10. data/test/haml/insert_extra_child.haml +9 -0
  11. data/test/{hum/templates/nest/nest.haml → haml/nests.haml} +1 -1
  12. data/test/haml/parent_selector.haml +7 -0
  13. data/test/haml/parent_siblings.haml +10 -0
  14. data/test/{hum/templates/simple/simple.haml → haml/property_value.haml} +1 -1
  15. data/test/haml/siblings.haml +6 -0
  16. data/test/{hum/templates/single/single.haml → haml/single_line_nest.haml} +4 -2
  17. data/test/{hum/templates/comma/comma.html → other/bad.file} +0 -0
  18. data/test/other/example.scss +6 -0
  19. data/test/sass/insert_extra_child.sass +8 -0
  20. data/test/{hum/templates/nest/nest.sass → sass/nests.sass} +0 -0
  21. data/test/sass/parent_selector.sass +6 -0
  22. data/test/sass/parent_siblings.sass +6 -0
  23. data/test/{hum/templates/simple/simple.sass → sass/property_value.sass} +0 -0
  24. data/test/sass/siblings.sass +2 -0
  25. data/test/{hum/templates/single/single.sass → sass/single_line_nest.sass} +1 -1
  26. data/test/sass_convert_test.rb +28 -0
  27. metadata +60 -159
  28. data/test/hum/templates/comma/comma.array +0 -1
  29. data/test/hum/templates/comma/comma.css +0 -6
  30. data/test/hum/templates/comma/comma.haml +0 -6
  31. data/test/hum/templates/comma/comma.haml_tags +0 -1
  32. data/test/hum/templates/comma/comma.sass +0 -2
  33. data/test/hum/templates/comma/comma_clean.sass +0 -1
  34. data/test/hum/templates/comma/comma_end.html +0 -9
  35. data/test/hum/templates/complex_parent/complex_parent.array +0 -1
  36. data/test/hum/templates/complex_parent/complex_parent.css +0 -18
  37. data/test/hum/templates/complex_parent/complex_parent.haml +0 -12
  38. data/test/hum/templates/complex_parent/complex_parent.haml_tags +0 -1
  39. data/test/hum/templates/complex_parent/complex_parent.html +0 -0
  40. data/test/hum/templates/complex_parent/complex_parent.sass +0 -12
  41. data/test/hum/templates/complex_parent/complex_parent_clean.sass +0 -6
  42. data/test/hum/templates/complex_parent/complex_parent_end.html +0 -18
  43. data/test/hum/templates/deep_nest/deep_nest.array +0 -1
  44. data/test/hum/templates/deep_nest/deep_nest.css +0 -15
  45. data/test/hum/templates/deep_nest/deep_nest.haml +0 -19
  46. data/test/hum/templates/deep_nest/deep_nest.haml_tags +0 -1
  47. data/test/hum/templates/deep_nest/deep_nest.html +0 -0
  48. data/test/hum/templates/deep_nest/deep_nest.sass +0 -10
  49. data/test/hum/templates/deep_nest/deep_nest_clean.sass +0 -5
  50. data/test/hum/templates/deep_nest/deep_nest_end.html +0 -27
  51. data/test/hum/templates/deep_nest/deep_nest_start.scss +0 -15
  52. data/test/hum/templates/line_nest/line_nest.array +0 -1
  53. data/test/hum/templates/line_nest/line_nest.css +0 -6
  54. data/test/hum/templates/line_nest/line_nest.haml +0 -9
  55. data/test/hum/templates/line_nest/line_nest.haml_tags +0 -1
  56. data/test/hum/templates/line_nest/line_nest.html +0 -0
  57. data/test/hum/templates/line_nest/line_nest.sass +0 -5
  58. data/test/hum/templates/line_nest/line_nest_clean.sass +0 -2
  59. data/test/hum/templates/line_nest/line_nest_end.html +0 -15
  60. data/test/hum/templates/nest/nest.array +0 -1
  61. data/test/hum/templates/nest/nest.css +0 -9
  62. data/test/hum/templates/nest/nest.haml_tags +0 -1
  63. data/test/hum/templates/nest/nest.html +0 -0
  64. data/test/hum/templates/nest/nest_clean.sass +0 -3
  65. data/test/hum/templates/nest/nest_end.html +0 -12
  66. data/test/hum/templates/parent_nest/parent_nest.array +0 -1
  67. data/test/hum/templates/parent_nest/parent_nest.css +0 -12
  68. data/test/hum/templates/parent_nest/parent_nest.haml +0 -8
  69. data/test/hum/templates/parent_nest/parent_nest.haml_tags +0 -1
  70. data/test/hum/templates/parent_nest/parent_nest.html +0 -0
  71. data/test/hum/templates/parent_nest/parent_nest.sass +0 -8
  72. data/test/hum/templates/parent_nest/parent_nest_clean.sass +0 -4
  73. data/test/hum/templates/parent_nest/parent_nest_end.html +0 -12
  74. data/test/hum/templates/parent_select/parent_select.array +0 -1
  75. data/test/hum/templates/parent_select/parent_select.css +0 -4
  76. data/test/hum/templates/parent_select/parent_select.haml +0 -6
  77. data/test/hum/templates/parent_select/parent_select.haml_tags +0 -1
  78. data/test/hum/templates/parent_select/parent_select.html +0 -0
  79. data/test/hum/templates/parent_select/parent_select.sass +0 -4
  80. data/test/hum/templates/parent_select/parent_select_clean.sass +0 -2
  81. data/test/hum/templates/parent_select/parent_select_end.html +0 -9
  82. data/test/hum/templates/simple/simple.array +0 -1
  83. data/test/hum/templates/simple/simple.css +0 -9
  84. data/test/hum/templates/simple/simple.haml_tags +0 -1
  85. data/test/hum/templates/simple/simple.html +0 -0
  86. data/test/hum/templates/simple/simple_clean.sass +0 -3
  87. data/test/hum/templates/simple/simple_end.html +0 -10
  88. data/test/hum/templates/single/single.array +0 -1
  89. data/test/hum/templates/single/single.css +0 -3
  90. data/test/hum/templates/single/single.haml_tags +0 -1
  91. data/test/hum/templates/single/single.html +0 -0
  92. data/test/hum/templates/single/single_clean.sass +0 -1
  93. data/test/hum/templates/single/single_end.html +0 -8
  94. data/test/run_tests.rb +0 -119
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ## 0.0.1
2
2
 
3
- * Initial release
3
+ * Initial release
4
+
5
+ ## 0.0.2
6
+
7
+ * Added support for .sass and .scss files, added more tests
data/README.md CHANGED
@@ -1,35 +1,76 @@
1
1
  # Hum
2
2
 
3
- Hum generates HTML from your SASS or CSS.
3
+ Hum generates HTML from your SASS, SCSS or CSS.
4
4
 
5
5
  `gem install hum`
6
6
 
7
- Here's an example of what he can do:
7
+ ## SASS to HTML
8
8
 
9
- #He'll eat this CSS
10
- .foo{
11
- border-width: 1px;
12
- }
13
- .foo .bar{
14
- font-size: 12px;
15
- }
16
- .foo .bar p{
17
- color: black;
18
- }
9
+ `hum [stylesheet].sass`
10
+
11
+ #He'll eat this SASS
12
+ .foo
13
+ color: white
14
+ .bar
15
+ color: black
16
+ .baz
17
+ color: red
19
18
 
20
19
  #And crap out this HTML
21
- <div class="foo">
22
- <div class="bar">
23
- <p></p>
24
- </div>
25
- </div>
20
+ <div class="foo">
21
+ <div class="bar">
22
+ <div class="baz"></div>
23
+ </div>
24
+ </div>
25
+
26
+ ## SCSS to HTML
27
+
28
+ `hum [stylesheet].scss`
29
+
30
+ #He'll eat this SCSS
31
+ .foo {
32
+ color: white;
33
+ .bar {
34
+ color: black;
35
+ .baz {
36
+ color: red;
37
+ }
38
+ }
39
+ }
26
40
 
27
- To do that run
41
+ #And crap out this HTML
42
+ <div class="foo">
43
+ <div class="bar">
44
+ <div class="baz"></div>
45
+ </div>
46
+ </div>
47
+
48
+ ## CSS to HTML
28
49
 
29
50
  `hum [stylesheet].css`
30
51
 
31
- You can also watch a directory for changes by using
52
+ #He'll eat this CSS
53
+ .foo{
54
+ border-width: 1px;
55
+ }
56
+ .foo .bar{
57
+ font-size: 12px;
58
+ }
59
+ .foo .bar p{
60
+ color: black;
61
+ }
62
+
63
+ #And crap out this HTML
64
+ <div class="foo">
65
+ <div class="bar">
66
+ <div class="baz"></div>
67
+ </div>
68
+ </div>
69
+
70
+ You can also watch a directory for changes to your SASS and SCSS files by using
32
71
 
33
72
  `hum --watch`
34
73
 
35
- He can't generate HTML from SASS directly yet, so you must specify a CSS file.
74
+ ## Notes
75
+
76
+ Just so you know, hum doesn't work well with mixins that include selectors yet.
data/hum.gemspec CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency 'sass'
22
- s.add_dependency 'haml'
23
- s.add_dependency 'fssm'
21
+ s.add_dependency 'sass', '>= 3.1.12'
22
+ s.add_dependency 'haml', '>= 3.1.4'
23
+ s.add_dependency 'fssm', '>= 0.2.7'
24
+ s.add_dependency 'colored', '>= 1.2'
24
25
  end
data/lib/hum/array.rb CHANGED
@@ -28,34 +28,57 @@ class Array
28
28
  found = self.find_line(line_number)
29
29
  end
30
30
 
31
- #return the right parent
32
- found
31
+ #return the right parent line
32
+ found[:line]
33
33
  end
34
34
 
35
- #find the children from a line to a hash
36
- def find_all_kids(line, to_line, kids = [])
35
+ def find_kids(hash, kids = [])
36
+
37
+ #get the next line number
38
+ next_line = hash[:line] + 1
39
+
40
+ #find the next one
41
+ found = self.find_line(next_line)
42
+
43
+ until found.nil? or hash[:tab] == found[:tab]
37
44
 
38
- #find the parent
39
- parent = self.find_line(line)
45
+ #collect it
46
+ kids << found[:line]
47
+
48
+ #increment
49
+ next_line += 1
50
+
51
+ #find the next one
52
+ found = self.find_line(next_line)
53
+ end
40
54
 
41
- #target the line number
42
- line_number = line + 1
55
+ #return all kids
56
+ kids
57
+ end
58
+
59
+ def find_extra_kids(hash, kids = [])
43
60
 
44
- #find the first found
45
- found = self.find_line(line_number)
61
+ #find the parent
62
+ parent = self.find_line(hash[:parent])
46
63
 
47
- until found.nil? or line_number == to_line or parent[:tab] == found[:tab]
48
- #add the line to the array
49
- kids << found
64
+ #target the next line
65
+ next_line = hash[:parent] + 1
66
+
67
+ #find the next line
68
+ found = self.find_line(next_line)
69
+
70
+ until found.nil? or next_line == hash[:line] or parent[:tab] == found[:tab]
50
71
 
51
- #increment the line number
52
- line_number += 1
72
+ #collect it
73
+ kids << found[:line]
53
74
 
54
- #find the new found
55
- found = self.find_line(line_number)
75
+ #increment
76
+ next_line += 1
77
+
78
+ #find the next one
79
+ found = self.find_line(next_line)
56
80
  end
57
81
 
58
- #return the kids
59
82
  kids
60
83
  end
61
84
  end
data/lib/hum/engine.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  require 'rubygems'
2
2
  require 'haml'
3
3
  require 'sass'
4
+ require 'sass/exec'
4
5
  require 'sass/css'
5
6
  require 'hum/string'
6
7
  require 'hum/array'
8
+ require 'colored'
9
+ require 'optparse'
10
+ require 'fileutils'
7
11
 
8
12
  module Hum
9
13
  #Hum
@@ -17,25 +21,43 @@ module Hum
17
21
  #the array that holds the parsed CSS
18
22
  @tree = []
19
23
 
24
+ @input_path = file
25
+
20
26
  #the name of the input file
21
27
  @input_name = File.basename(file)
22
28
 
23
29
  #read the input file
24
30
  @input_file = File.open(file, 'r')
25
31
 
32
+ @directory = File.dirname(file)
33
+
26
34
  #the output path
27
35
  @output_path = File.absolute_path(file).gsub(/\..*/, ".html")
28
36
 
29
37
  #the name of the output file
30
38
  @output_name = File.basename(@output_path)
39
+ end
40
+
41
+ def run
42
+ run_haml
31
43
 
32
44
  #create the output file
33
45
  @output_file = File.open(@output_path, "w")
46
+
47
+ #output the html
48
+ @output_file.write(output_html)
49
+
50
+ #close the input file
51
+ @input_file.close()
52
+
53
+ #close the output file
54
+ @output_file.close()
55
+
56
+ puts "updated #{@output_name}!".green
34
57
  end
35
58
 
36
- #runs through all the commands
37
- def run
38
- #renders SASS from CSS
59
+ def run_haml
60
+ #render SASS from CSS
39
61
  render_sass
40
62
 
41
63
  #remove property value pairs
@@ -49,84 +71,101 @@ module Hum
49
71
 
50
72
  #generate HAML
51
73
  output_haml
52
-
53
- #output the html
54
- @output_file.write(output_html)
55
-
56
- #close the input file
57
- @input_file.close()
58
-
59
- #close the output file
60
- @output_file.close()
61
-
62
- puts "updated #{@output_name}!\n"
63
74
  end
64
75
 
65
76
  def render_sass
66
- return _render_sass
67
- end
68
-
69
- def clean_sass
70
- return _clean_sass
71
- end
72
-
73
- def build_hashes
74
- return _build_hashes
75
- end
76
-
77
- def render_haml_tags
78
- return _render_haml_tags
79
- end
80
-
81
- def output_haml
82
- return _output_haml
83
- end
84
-
85
- def output_html
86
- return _output_html
87
- end
88
-
89
-
90
- private
91
-
92
-
93
- def _render_sass
94
-
95
- #if input file is scss, output CSS and convert to SASS
96
- #if input file is sass, output CSS and continue
97
- #if input file is CSS, do below
98
-
99
- #convert to SASS
77
+ #read content
100
78
  content = @input_file.read
79
+
101
80
  #remove all comments
102
81
  content.gsub!(/\/\*([\s\S]*?)\*\//, "")
103
- #render sass
104
- @sass = Sass::CSS.new(content).render(:sass)
82
+
83
+ #if CSS render SASS
84
+ if @input_name.match(/\.css/)
85
+ @sass = Sass::CSS.new(content).render(:sass)
86
+
87
+ #if SCSS convert to SASS
88
+ elsif @input_name.match(/\.scss/)
89
+ @sass = ::Sass::Engine.new(content, { :cache => false, :read_cache => true, :syntax => :scss }).to_tree.send("to_sass")
90
+
91
+ #if sass keep as it
92
+ elsif @input_name.match(/\.sass/)
93
+ @sass = content
94
+
95
+ #if nothing then put error
96
+ else
97
+ puts "Hum only works with .scss, .sass and .css files.".red
98
+ exit 1
99
+ end
105
100
  end
106
101
 
107
- def _clean_sass
102
+ def clean_sass
108
103
  #remove all property: value; pairs
109
104
  @sass.gsub!((/.*: .*/), "")
105
+
110
106
  #remove duplicate new lines
111
107
  @sass.gsub!((/\n+/), "\n")
112
108
  end
113
109
 
114
- def _build_hashes
110
+ def build_hashes
111
+
115
112
  i = 1
113
+
116
114
  #parse into an array of hashes
117
115
  @sass.each do |code|
118
116
  hash = {
119
117
  :line => i,
120
118
  :select => _grab_select(code),
121
- :tab => _grab_tab(code)
119
+ :tab => _grab_tab(code),
120
+ :parent => nil,
121
+ :kids => []
122
122
  }
123
123
  @tree << hash
124
124
  i += 1
125
125
  end
126
+
127
+ #mark all parent selectors
126
128
  _check_for_parents
129
+
130
+ #collect all kids
131
+ _collect_kids
132
+
133
+ #process all tags of parent selectors
134
+ _process_parents
135
+
136
+ #process all tabs
137
+ _process_tabs
138
+
127
139
  @tree
128
140
  end
129
141
 
142
+ def render_haml_tags
143
+ #in each line
144
+ @tree.each do |hash|
145
+ hash[:haml] = []
146
+
147
+ #for each selector
148
+ hash[:select].each do |tag|
149
+
150
+ #convert the tag to a HAML tag
151
+ hash[:haml].push(_grab_haml_tag(tag))
152
+ end
153
+ end
154
+ @tree
155
+ end
156
+
157
+ def output_haml
158
+ return _output_haml
159
+ end
160
+
161
+ def output_html
162
+ #convert HAML to HAML
163
+ @html = Haml::Engine.new(@haml).render
164
+ @html
165
+ end
166
+
167
+ private
168
+
130
169
  def _check_for_parents
131
170
  #in each line
132
171
  @tree.each do |hash|
@@ -138,88 +177,76 @@ module Hum
138
177
  if code.match("&")
139
178
 
140
179
  #find the parent
141
- hash[:parent] = @tree.find_parent(hash)[:line]
142
-
143
- #find all the kids
144
- _check_for_kids(hash)
180
+ hash[:parent] = @tree.find_parent(hash)
145
181
 
146
182
  end
147
- }#end of hash[:select]
148
-
149
- end #end of @tree.each
150
-
151
- _process_parents_and_kids
152
-
183
+ }
184
+ end
153
185
  end
154
186
 
155
- def _process_parents_and_kids
156
-
157
- #look for all parents & kids and modify them
187
+ def _collect_kids
188
+ #in each line
158
189
  @tree.each do |hash|
159
190
 
160
- #if the hash has a parent
161
- if hash[:parent]
191
+ #if hash has a parent
192
+ if !hash[:parent].nil?
193
+
194
+ #find all the kids
195
+ hash[:kids] = @tree.find_kids(hash)
196
+ end
197
+
198
+ end
199
+ end
200
+
201
+ def _process_parents
202
+ #in each line
203
+ @tree.each { |hash|
204
+
205
+ #if the hash has a parent
206
+ if !hash[:parent].nil?
162
207
 
163
- #find the parent
208
+ #find it
164
209
  parent = @tree.find_line(hash[:parent])
165
210
 
166
- #if the selector array is only one
167
211
  if parent[:select].length == 1
168
212
 
169
- #replace the & with the parent selector
170
- hash[:select].each do |elm|
213
+ #and replace the &
214
+ hash[:select].each { |elm|
171
215
  elm.gsub!("&", parent[:select].first)
172
- end
216
+ }
173
217
 
174
- #update the tab to the parent tab
175
- hash[:tab] = parent[:tab]
176
218
  end
177
219
 
178
- #if this hash has any kids
179
- if hash[:kids]
220
+ end
221
+ }
222
+ end
223
+
224
+ def _process_tabs
225
+ #in each line
226
+ @tree.each { |hash|
227
+
228
+ #if there is a parent
229
+ if !hash[:parent].nil?
230
+
231
+ #reduce tab by 1
232
+ hash[:tab] -= 1
233
+
234
+ #if there are kids
235
+ if !hash[:kids].empty?
180
236
 
181
- #loop through each kid
182
- hash[:kids].each do |kid|
237
+ #for each kid
238
+ hash[:kids].each { |kid|
183
239
 
184
- #find the kid
240
+ #find it
185
241
  child = @tree.find_line(kid)
186
242
 
187
- #and decrease the tab by one
243
+ #and reduce it by one
188
244
  child[:tab] -= 1
189
- end
245
+
246
+ }
190
247
  end
191
-
192
248
  end
193
- end
194
-
195
- end
196
-
197
- def _check_for_kids(of_this_hash)
198
-
199
- #target the line number
200
- line_number = of_this_hash[:line] + 1
201
-
202
- #find the line
203
- found = @tree.find_line(line_number)
204
-
205
- #finds the children
206
- until found.nil? or found[:tab] <= of_this_hash[:tab]
207
-
208
- #only create a kids hash if there are kids
209
- if of_this_hash[:kids].nil?
210
- of_this_hash[:kids] = []
211
- end
212
-
213
- #add the line to the kids array
214
- of_this_hash[:kids] << found[:line]
215
-
216
- #go up the tree
217
- line_number += 1
218
-
219
- #find the line
220
- found = @tree.find_line(line_number)
221
- end
222
-
249
+ }
223
250
  end
224
251
 
225
252
  def _grab_select(code)
@@ -241,16 +268,6 @@ module Hum
241
268
  end
242
269
  end
243
270
 
244
- def _render_haml_tags
245
- @tree.each do |code|
246
- code[:haml] = []
247
- code[:select].each do |tag|
248
- code[:haml].push(_grab_haml_tag(tag))
249
- end
250
- end
251
- @tree
252
- end
253
-
254
271
  def _grab_haml_tag(code)
255
272
  #give all classes that start with . or # a DIV element
256
273
  if code.match(/^\./) or code.match(/^\#/)
@@ -259,105 +276,115 @@ module Hum
259
276
  tag = "%" + code
260
277
  end
261
278
 
262
- #give all descending tags a %
279
+ #give all descending tags a %, there's probably a better way to do this
263
280
  if tag.match(" ")
264
281
  tag = tag.gsub(" ", " %")
265
282
  end
283
+
284
+ if tag.match("%.")
285
+ tag = tag.gsub("%.", "%div.")
286
+ end
287
+
288
+ if tag.match("%#")
289
+ tag = tag.gsub("%#", "%div#")
290
+ end
291
+
266
292
  tag
267
293
  end
268
294
 
269
295
  #Output the HAML
270
296
  def _output_haml
297
+
271
298
  #convert to HAML
272
299
  @haml = "%html\n"
273
300
  @haml += "\t%head\n"
274
- @haml += "\t\t%link{:type => 'text/css', :rel => 'stylesheet', :href => '#{@input_name}'}\n"
275
- #@haml += "\t\t:javascript\n"
276
- #@haml += "\t\t\tsetTimeout(function(){ parent.location.reload(true); }, 3000)\n"
301
+ @haml += "\t\t%link{:type => 'text/css', :rel => 'stylesheet', :href => '#{@input_name.gsub(/\..*/, ".css")}'}\n"
277
302
  @haml += "\t%body\n"
303
+
304
+ #time to build the HAML
278
305
  @tree.each do |hash|
306
+ extra = []
279
307
 
280
- #empty the kids
281
- kids = []
282
- tabs = "\t\t"
283
-
284
- #set the base tab
285
- if hash[:tab] > 0
286
- tabs += "\t" * hash[:tab]
287
- end
288
-
289
- #if this code was generated from a parent, find the kids
308
+ #if there's a parent, find the extra kids
290
309
  if !hash[:parent].nil?
291
- kids = @tree.find_all_kids(hash[:parent], hash[:line])
310
+ extra = @tree.find_extra_kids(hash)
292
311
  end
293
312
 
313
+ #for each generate the HAML line
294
314
  hash[:haml].each { |haml_tag|
295
315
 
296
- @haml += _generate_haml_line(tabs, haml_tag, hash)
316
+ #if no extra, just normal
317
+ if extra.empty?
318
+ @haml += _generate_haml_line(haml_tag, hash)
297
319
 
298
- #if there were kids
299
- if kids.length != 0
300
- kids.each { |hash|
320
+ #else extra
321
+ else
301
322
 
302
- #reset the base tab
303
- tabs = "\t\t"
304
-
305
- #set the base tab
306
- tabs += "\t" * hash[:tab]
307
-
308
- hash[:haml].each do |haml_tag|
309
- #generate the HAML
310
- @haml += _generate_haml_line(tabs, haml_tag, hash)
311
- end
323
+ #this hash has extra kids
324
+ hash[:extra] = true
325
+
326
+ @haml += _generate_haml_line(haml_tag, hash)
327
+
328
+ #for each kid
329
+ extra.each { |line|
312
330
 
331
+ #get the hash
332
+ extra_hash = @tree.find_line(line)
333
+
334
+ #for each generate the HAML line
335
+ extra_hash[:haml].each do |haml_tag|
336
+
337
+ #do it
338
+ @haml += _generate_haml_line(haml_tag, extra_hash)
339
+ end
313
340
  }
314
341
  end
342
+
315
343
  }
316
344
  end
317
345
  @haml
318
346
  end
319
347
 
320
- def _generate_haml_line(tabs, element, hash, haml = "")
348
+ def _generate_haml_line(element, hash, haml = "")
321
349
 
322
350
  #handle a string of descending selectors
323
351
  if element.match(" ")
352
+
353
+ tabs = "\t\t" + "\t" * hash[:tab]
354
+ count = 0
324
355
 
325
- #so we can give the right indent
326
- tabs = "\t"
327
- add_tab = 0
328
-
329
- #collect the descending selectors
356
+ #collect all tags
330
357
  nests = element.split(" ")
331
358
 
332
- #loop through them and generate the HAML
359
+ #for each tag
333
360
  nests.each do |nest|
334
361
 
335
- tabs += "\t"
362
+ if count != 0
363
+ tabs += "\t"
364
+ end
336
365
 
337
- #if this is the last descending selector, add content
338
- if add_tab == nests.length - 1
366
+ #if this is the last one, check for content
367
+ if count == nests.length - 1
339
368
  haml += tabs + nest + _grab_content(hash)
340
369
 
341
- #add a new line
370
+ #else add a new line
342
371
  else
343
372
  haml += tabs + nest + "\n"
344
373
  end
345
374
 
346
- add_tab += 1
375
+ count += 1
347
376
  end
348
377
 
349
378
  #otherwise per normal
350
379
  else
351
380
 
352
- #if the hash is from a parent
353
- if !hash[:parent].nil?
354
- tabs = "\t\t" + "\t" * @tree.find_line(hash[:parent])[:tab]
355
- end
381
+ #make tabs
382
+ tabs = "\t\t" + "\t" * hash[:tab]
356
383
 
384
+ #make HAML
357
385
  haml += tabs + element + _grab_content(hash)
358
386
  end
359
-
360
- #returns HAML
387
+
361
388
  haml
362
389
  end
363
390
 
@@ -367,35 +394,23 @@ module Hum
367
394
  #find the next hash
368
395
  next_hash = @tree.find_line(hash[:line] + 1)
369
396
 
370
- #pick the content
371
- if !next_hash.nil? && next_hash[:tab] > hash[:tab]
397
+ #if it has kids, add a new line
398
+ if !next_hash.nil? and next_hash[:tab] > hash[:tab]
372
399
  found = "\n"
400
+
401
+ #else put in content
373
402
  else
374
403
  found = " Inner content\n"
375
404
  end
376
-
377
- #if the hash has a parent
378
- if !hash[:parent].nil?
379
-
380
- #find the kids
381
- kids = @tree.find_all_kids(hash[:parent], hash[:line])
382
-
383
- #if there are no kids
384
- if !kids.empty?
385
- found = "\n"
386
- end
387
-
405
+
406
+ #if kids, it's a new line
407
+ if hash[:kids].length > 0 or hash[:extra] == true
408
+ found = "\n"
388
409
  end
389
410
 
390
411
  found
391
-
392
412
  end
393
413
 
394
- def _output_html
395
- #convert HAML to HAML
396
- @html = Haml::Engine.new(@haml).render
397
- @html
398
- end
399
414
  end
400
415
 
401
416
  end