Class: Trenni::Template::Assembler
- Inherits:
-
Object
- Object
- Trenni::Template::Assembler
- Defined in:
- lib/trenni/template.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
-
#expression(text) ⇒ Object
Output a string interpolation.
-
#initialize(encoding: Encoding::UTF_8) ⇒ Assembler
constructor
A new instance of Assembler.
-
#instruction(text, postfix = nil) ⇒ Object
Output a ruby expression (or part of).
-
#text(text) ⇒ Object
Output raw text to the template.
Constructor Details
#initialize(encoding: Encoding::UTF_8) ⇒ Assembler
Returns a new instance of Assembler.
62 63 64 |
# File 'lib/trenni/template.rb', line 62 def initialize(encoding: Encoding::UTF_8) @code = String.new.force_encoding(encoding) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
66 67 68 |
# File 'lib/trenni/template.rb', line 66 def code @code end |
Instance Method Details
#expression(text) ⇒ Object
Output a string interpolation.
83 84 85 86 |
# File 'lib/trenni/template.rb', line 83 def expression(text) # Double brackets are required here to handle expressions like #{foo rescue "bar"}. @code << "#{OUT}<<String(#{text});" end |
#instruction(text, postfix = nil) ⇒ Object
Output a ruby expression (or part of).
78 79 80 |
# File 'lib/trenni/template.rb', line 78 def instruction(text, postfix = nil) @code << text << (postfix || ';') end |
#text(text) ⇒ Object
Output raw text to the template.
69 70 71 72 73 74 75 |
# File 'lib/trenni/template.rb', line 69 def text(text) text = text.gsub("'", "\\\\'") @code << "#{OUT}<<'#{text}';" # This is an interesting approach, but it doens't preserve newlines or tabs as raw characters, so template line numbers don't match up. # @parts << "#{OUT}<<#{text.dump};" end |