Top Level Namespace
Constant Summary collapse
- DEBUG_MODE =
false
Instance Method Summary collapse
- #alter_lines(lines, altered_lines) ⇒ Object
- #block_end?(line) ⇒ Boolean
- #block_start?(line) ⇒ Boolean
- #comment_line?(line) ⇒ Boolean
-
#get_indent(line) ⇒ Object
REPLACABLE1 START.
- #ie_block_end?(line) ⇒ Boolean
- #ie_block_start?(line) ⇒ Boolean
- #indent(line, steps = 0) ⇒ Object
- #indent_lines(lines, indented_lines) ⇒ Object
- #remove_lines(lines, goner_lines) ⇒ Object
Instance Method Details
#alter_lines(lines, altered_lines) ⇒ Object
52 53 54 55 56 57 58 |
# File 'bin/hamlify', line 52 def alter_lines(lines, altered_lines) altered_lines.each do |pair| line_number, text = pair lines[line_number] = text end lines end |
#block_end?(line) ⇒ Boolean
22 23 24 25 |
# File 'bin/hamlify', line 22 def block_end?(line) line = line.to_s line.strip =~ /^-\send$/ end |
#block_start?(line) ⇒ Boolean
13 14 15 16 17 18 19 20 |
# File 'bin/hamlify', line 13 def block_start?(line) block_starters = [/\s+do/, /^-\s+while/, /^-\s+module/, /^-\s+begin/, /^-\s+case/, /^-\s+class/, /^-\s+unless/, /^-\s+for/, /^-\s+until/, /^-\s*if/] line = line.to_s line.strip =~ /^-/ && block_starters.any?{|bs| line.strip =~ bs} end |
#comment_line?(line) ⇒ Boolean
37 38 39 40 |
# File 'bin/hamlify', line 37 def comment_line?(line) line = line.to_s line.strip =~ /^\// end |
#get_indent(line) ⇒ Object
REPLACABLE1 START
7 8 9 10 11 |
# File 'bin/hamlify', line 7 def get_indent(line) line = line.to_s space_areas = line.scan(/^\s+/) space_areas.empty? ? 0 : (space_areas.first.size / 2) end |
#ie_block_end?(line) ⇒ Boolean
32 33 34 35 |
# File 'bin/hamlify', line 32 def ie_block_end?(line) line = line.to_s line =~ /<!\[endif\]/i end |
#ie_block_start?(line) ⇒ Boolean
27 28 29 30 |
# File 'bin/hamlify', line 27 def ie_block_start?(line) line = line.to_s line =~ /\[if/i && line =~ /IE/ && line.strip =~ /\]>$/ end |
#indent(line, steps = 0) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'bin/hamlify', line 42 def indent(line, steps = 0) line = line.to_s exceptions = [/\s+else\W/, /^-\s+elsif/, /^-\s+when/, /^-\s+ensure/, /^-\s+rescue/] return if exceptions.any?{|ex| line.strip =~ ex} steps ||= 0 line = line.to_s (" " * steps) + line end |
#indent_lines(lines, indented_lines) ⇒ Object
60 61 62 63 64 65 66 |
# File 'bin/hamlify', line 60 def indent_lines(lines, indented_lines) indented_lines.each do |pair| line_number, indent_by = pair lines[line_number] = indent(lines[line_number], indent_by) end lines end |
#remove_lines(lines, goner_lines) ⇒ Object
68 69 70 71 72 73 |
# File 'bin/hamlify', line 68 def remove_lines(lines, goner_lines) goner_lines.each do |i| lines[i] = nil end lines.compact end |