Class: Trenni::Template::Assembler
- Inherits:
-
Object
- Object
- Trenni::Template::Assembler
- Defined in:
- lib/trenni/template.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #code ⇒ Object
-
#expression(text) ⇒ Object
Output a ruby expression (or part of).
-
#initialize ⇒ Assembler
constructor
A new instance of Assembler.
-
#interpolation(text) ⇒ Object
Output a string interpolation.
-
#text(text) ⇒ Object
Output raw text to the template.
Constructor Details
#initialize ⇒ Assembler
Returns a new instance of Assembler.
44 45 46 |
# File 'lib/trenni/template.rb', line 44 def initialize @parts = [] end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
48 49 50 |
# File 'lib/trenni/template.rb', line 48 def parts @parts end |
Instance Method Details
#code ⇒ Object
72 73 74 |
# File 'lib/trenni/template.rb', line 72 def code return [CODE_PREFIX, *@parts, CODE_POSTFIX].join end |
#expression(text) ⇒ Object
Output a ruby expression (or part of).
60 61 62 |
# File 'lib/trenni/template.rb', line 60 def expression(text) @parts << "#{text};" end |
#interpolation(text) ⇒ Object
Output a string interpolation.
65 66 67 |
# File 'lib/trenni/template.rb', line 65 def interpolation(text) @parts << "#{OUT}<<(#{text});" end |
#text(text) ⇒ Object
Output raw text to the template.
51 52 53 54 55 56 57 |
# File 'lib/trenni/template.rb', line 51 def text(text) text = text.gsub("'", "\\\\'") @parts << "#{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 |