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.
61 62 63 |
# File 'lib/trenni/template.rb', line 61 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.
65 66 67 |
# File 'lib/trenni/template.rb', line 65 def code @code end |
Instance Method Details
#expression(text) ⇒ Object
Output a string interpolation.
82 83 84 85 |
# File 'lib/trenni/template.rb', line 82 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).
77 78 79 |
# File 'lib/trenni/template.rb', line 77 def instruction(text, postfix = nil) @code << text << (postfix || ';') end |
#text(text) ⇒ Object
Output raw text to the template.
68 69 70 71 72 73 74 |
# File 'lib/trenni/template.rb', line 68 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 |