Class: Twofold::Indentation
- Defined in:
- lib/twofold/indentation.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Indentation
constructor
A new instance of Indentation.
- #on_dynamic(ruby) ⇒ Object
- #on_static(string) ⇒ Object
- #on_twofold_indented(indent, inner) ⇒ Object
- #on_twofold_newline ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Indentation
Returns a new instance of Indentation.
6 7 8 9 10 |
# File 'lib/twofold/indentation.rb', line 6 def initialize(opts = {}) super @indent = [:indent] @indented = [:indented] end |
Instance Method Details
#on_dynamic(ruby) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/twofold/indentation.rb', line 38 def on_dynamic(ruby) [:multi, [:capture, 'tmp', [:dynamic, ruby]], [:if, 'not tmp.nil? and not tmp.empty?', [:block, 'tmp.split(/(?<=\n)/).each do |line|', [:multi, ensure_indent, [:dynamic, "line"], [:if, "line[-1] == #{'"\n"'}", [:code, "#{@indented} = false"] ] ] ] ] ] end |
#on_static(string) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/twofold/indentation.rb', line 27 def on_static(string) if string.empty? [:static, string] else [:multi, ensure_indent, [:static, string] ] end end |
#on_twofold_indented(indent, inner) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/twofold/indentation.rb', line 12 def on_twofold_indented(indent, inner) block = [:multi] block << [:code, "(#{@indent} ||= []) << '#{indent}'"] block << compile(inner) block << [:code, "#{@indent}.pop"] block end |
#on_twofold_newline ⇒ Object
20 21 22 23 24 25 |
# File 'lib/twofold/indentation.rb', line 20 def on_twofold_newline [:multi, [:code, "#{@indented} = false"], [:static, "\n"] ] end |