Class: FolderTemplate::TemplateString
- Inherits:
-
Object
- Object
- FolderTemplate::TemplateString
- Defined in:
- lib/folder_template/template_string.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
- #expand(env) ⇒ Object
-
#initialize(template) ⇒ TemplateString
constructor
A new instance of TemplateString.
- #to_s ⇒ Object
- #variables ⇒ Object
Constructor Details
#initialize(template) ⇒ TemplateString
Returns a new instance of TemplateString.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/folder_template/template_string.rb', line 14 def initialize( template ) case template when String @content = _parse( template ) when Array @content = template.select do |fragment| !fragment.nil? && !fragment.to_s.empty? end when TemplateString @content = template.content end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/folder_template/template_string.rb', line 12 def content @content end |
Instance Method Details
#expand(env) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/folder_template/template_string.rb', line 31 def ( env ) fragments = content.map do |fragment| case fragment when Symbol env[fragment] || (yield fragment if block_given?)|| fragment else fragment end end.select { |fragment| !fragment.nil? && !fragment.to_s.empty? } TemplateString.new( fragments ) end |
#to_s ⇒ Object
43 44 45 46 47 |
# File 'lib/folder_template/template_string.rb', line 43 def to_s @content.map do |fragment| ("{{#{fragment}}}" if Symbol === fragment) || fragment end.join end |
#variables ⇒ Object
27 28 29 |
# File 'lib/folder_template/template_string.rb', line 27 def variables @variables ||= _extract_variables( @content ) end |