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
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
- #background(value, &block) ⇒ Vedeu::Views::Stream (also: #bg) included from Helpers
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
- #colour(attributes = {}, &block) ⇒ Vedeu::Views::Stream included from Helpers
-
#content ⇒ String
private
Return a string representing the template processed with ERB.
- #default ⇒ Hash<Symbol => Hash<Symbol => Symbol>,Symbol> private
- #define_stream(attributes = {}, &block) ⇒ Object included from Helpers private
- #encode(data) ⇒ String included from Helpers private
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
- #foreground(value, &block) ⇒ Vedeu::Views::Stream (also: #fg) included from Helpers
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#interface ⇒ Object
(also: #interface?)
private
Returns the interface by name.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#lines ⇒ Array<String>
private
Convert the content into an array of strings without the line ending character.
- #name ⇒ String|Symbol private
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #parse ⇒ Vedeu::Views::Lines
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#stream_colour ⇒ Vedeu::Colours::Colour|Hash<Symbol => NilClass,String,Symbol>
private
Return the interface colours if a name option is set, otherwise use the default colours.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#stream_style ⇒ Symbol
private
Return the interface style(s) if a name option is set, otherwise use the default style.
-
#streams_for(line) ⇒ Array<String>
private
Returns the stream directives for the line.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #style(value, &block) ⇒ Vedeu::Views::Stream included from Helpers
-
#time_now ⇒ String
included
from View
Returns the current local time.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
Constructor Details
This class inherits a constructor from Vedeu::Templating::Template
Instance Attribute Details
#object ⇒ Class (readonly, protected)
46 47 48 |
# File 'lib/vedeu/templating/view_template.rb', line 46 def object @object end |
#options ⇒ Hash (readonly, protected)
50 51 52 |
# File 'lib/vedeu/templating/view_template.rb', line 50 def @options end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#background(value, &block) ⇒ Vedeu::Views::Stream Also known as: bg Originally defined in module Helpers
#become(klass, attributes) ⇒ Class Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts one class into another.
#boolean(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the value was a boolean.
#boolean?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Boolean.
#colour(attributes = {}, &block) ⇒ Vedeu::Views::Stream Originally defined in module Helpers
#content ⇒ String (private)
Return a string representing the template processed with ERB.
117 118 119 |
# File 'lib/vedeu/templating/view_template.rb', line 117 def content ERB.new(load, nil, '-').result(binding) end |
#default ⇒ Hash<Symbol => Hash<Symbol => Symbol>,Symbol> (private)
65 66 67 68 69 70 71 72 73 |
# File 'lib/vedeu/templating/view_template.rb', line 65 def default { colour: { background: :default, foreground: :default, }, style: :normal, } end |
#define_stream(attributes = {}, &block) ⇒ Object (private) Originally defined in module Helpers
#encode(data) ⇒ String (private) Originally defined in module Helpers
#escape?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered false.
#foreground(value, &block) ⇒ Vedeu::Views::Stream Also known as: fg Originally defined in module Helpers
#hash?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Hash.
#interface ⇒ Object (private) Also known as: interface?
Returns the interface by name.
78 79 80 |
# File 'lib/vedeu/templating/view_template.rb', line 78 def interface Vedeu.interfaces.by_name(name) end |
#line_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Line.
#lines ⇒ Array<String> (private)
Convert the content into an array of strings without the line ending character.
110 111 112 |
# File 'lib/vedeu/templating/view_template.rb', line 110 def lines content.lines.map(&:chomp) end |
#name ⇒ String|Symbol (private)
84 85 86 |
# File 'lib/vedeu/templating/view_template.rb', line 84 def name [:name] end |
#numeric?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#parse ⇒ Vedeu::Views::Lines
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vedeu/templating/view_template.rb', line 16 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: stream_colour, style: stream_style, value: stream) end end lines_collection << line_object end lines_collection end |
#present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
#snake_case(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
#stream_colour ⇒ Vedeu::Colours::Colour|Hash<Symbol => NilClass,String,Symbol> (private)
Return the interface colours if a name option is set, otherwise use the default colours.
58 59 60 61 62 |
# File 'lib/vedeu/templating/view_template.rb', line 58 def stream_colour return interface.colour if name default[:colour] end |
#stream_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Stream.
#stream_style ⇒ Symbol (private)
Return the interface style(s) if a name option is set, otherwise use the default style.
100 101 102 103 104 |
# File 'lib/vedeu/templating/view_template.rb', line 100 def stream_style return interface.style if name default[:style] end |
#streams_for(line) ⇒ Array<String> (private)
Returns the stream directives for the line.
92 93 94 |
# File 'lib/vedeu/templating/view_template.rb', line 92 def streams_for(line) line.split(/({{\s*[^}]+\s*}})/) end |
#string?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#style(value, &block) ⇒ Vedeu::Views::Stream Originally defined in module Helpers
#time_now ⇒ String Originally defined in module View
Returns the current local time.
#truthy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered true.
#view_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::View.