Class: Vedeu::Templating::ViewTemplate
- Defined in:
- lib/vedeu/templating/view_template.rb
Overview
Extend Template to provide client application view specific parsing.
Instance Attribute Summary collapse
- #object ⇒ Class readonly protected
- #options ⇒ Hash readonly protected
Instance Method Summary collapse
-
#content ⇒ String
private
Return a string representing the template processed with ERB.
-
#default_colour ⇒ Vedeu::Colours::Colour|Hash<Symbol => Symbol>
private
Return the interface colours if a name option is set, otherwise use the default colours.
-
#default_style ⇒ Symbol
private
Return the interface style(s) if a name option is set, otherwise use the default style.
-
#interface ⇒ Vedeu::Models::Interface
(also: #interface?)
private
Fetch the interface by name.
-
#lines ⇒ Array<String>
private
Convert the content into an array of strings without the line ending character.
- #parse ⇒ Vedeu::Views::Lines
-
#streams_for(line) ⇒ Array<String>
private
Returns the stream directives for the line.
Methods included from Helpers
#background, #colour, #define_stream, #encode, #foreground, #style
Methods included from Common
#demodulize, #present?, #snake_case
Constructor Details
This class inherits a constructor from Vedeu::Templating::Template
Instance Attribute Details
#object ⇒ Class (readonly, protected)
44 45 46 |
# File 'lib/vedeu/templating/view_template.rb', line 44 def object @object end |
#options ⇒ Hash (readonly, protected)
48 49 50 |
# File 'lib/vedeu/templating/view_template.rb', line 48 def @options end |
Instance Method Details
#content ⇒ String (private)
Return a string representing the template processed with ERB.
110 111 112 |
# File 'lib/vedeu/templating/view_template.rb', line 110 def content ERB.new(load, nil, '-').result(binding) end |
#default_colour ⇒ Vedeu::Colours::Colour|Hash<Symbol => Symbol> (private)
Return the interface colours if a name option is set, otherwise use the default colours.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vedeu/templating/view_template.rb', line 56 def default_colour if [:name] interface.colour else { background: :default, foreground: :default, } end end |
#default_style ⇒ Symbol (private)
Return the interface style(s) if a name option is set, otherwise use the default style.
73 74 75 76 77 78 79 80 81 |
# File 'lib/vedeu/templating/view_template.rb', line 73 def default_style if [:name] interface.style else :normal end end |
#interface ⇒ Vedeu::Models::Interface (private) Also known as: interface?
Fetch the interface by name.
86 87 88 |
# File 'lib/vedeu/templating/view_template.rb', line 86 def interface Vedeu.interfaces.by_name([:name]) end |
#lines ⇒ Array<String> (private)
Convert the content into an array of strings without the line ending character.
103 104 105 |
# File 'lib/vedeu/templating/view_template.rb', line 103 def lines content.lines.map(&:chomp) end |
#parse ⇒ Vedeu::Views::Lines
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vedeu/templating/view_template.rb', line 14 def parse lines_collection = Vedeu::Views::Lines.new lines.each do |line| line_object = Vedeu::Views::Line.new streams_for(line).each do |stream| next unless present?(stream) line_object << if stream =~ /({{)|(}})/ Vedeu::Templating::Decoder.process(stream) else Vedeu::Views::Stream.new(colour: default_colour, style: default_style, value: stream) end end lines_collection << line_object end lines_collection end |
#streams_for(line) ⇒ Array<String> (private)
Returns the stream directives for the line.
95 96 97 |
# File 'lib/vedeu/templating/view_template.rb', line 95 def streams_for(line) line.split(/({{\s*[^}]+\s*}})/) end |