Class: Vedeu::Templating::ViewTemplate

Inherits:
Template
  • Object
show all
Includes:
Common, Helpers
Defined in:
lib/vedeu/templating/view_template.rb

Overview

Extend Template to provide client application view specific parsing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Vedeu::Templating::Template

Instance Attribute Details

#objectClass (readonly, protected)

Returns:

  • (Class)


44
45
46
# File 'lib/vedeu/templating/view_template.rb', line 44

def object
  @object
end

#optionsHash (readonly, protected)

Returns:

  • (Hash)


48
49
50
# File 'lib/vedeu/templating/view_template.rb', line 48

def options
  @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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#background(value, &block) ⇒ Vedeu::Views::Stream Also known as: bg Originally defined in module Helpers

Parameters:

  • value (String)

    The HTML/CSS colour.

  • block (Proc)

Returns:

Raises:

#colour(attributes = {}, &block) ⇒ Vedeu::Views::Stream Originally defined in module Helpers

Parameters:

  • attributes (Hash) (defaults to: {})
  • block (Proc)

Options Hash (attributes):

  • foreground (String)

    The HTML/CSS foreground colour.

  • background (String)

    The HTML/CSS background colour.

Returns:

Raises:

#contentString (private)

Return a string representing the template processed with ERB.

Returns:

  • (String)


102
103
104
# File 'lib/vedeu/templating/view_template.rb', line 102

def content
  ERB.new(load, nil, '-').result(binding)
end

#default_colourVedeu::Colours::Colour|Hash<Symbol => Symbol> (private)

Return the interface colours if a name option is set, otherwise use the default colours.

Returns:



56
57
58
59
60
61
62
63
# File 'lib/vedeu/templating/view_template.rb', line 56

def default_colour
  return interface.colour if options[:name]

  {
    background: :default,
    foreground: :default,
  }
end

#default_styleSymbol (private)

Return the interface style(s) if a name option is set, otherwise use the default style.

Returns:

  • (Symbol)


69
70
71
72
73
# File 'lib/vedeu/templating/view_template.rb', line 69

def default_style
  return interface.style if options[:name]

  :normal
end

#define_stream(attributes = {}, &block) ⇒ Object (private) Originally defined in module Helpers

See Also:

#demodulize(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.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#encode(data) ⇒ String (private) Originally defined in module Helpers

Parameters:

  • data (String)

Returns:

  • (String)

#foreground(value, &block) ⇒ Vedeu::Views::Stream Also known as: fg Originally defined in module Helpers

Parameters:

  • value (String)

    The HTML/CSS colour.

  • block (Proc)

Returns:

Raises:

#interfaceObject (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(options[:name])
end

#linesArray<String> (private)

Convert the content into an array of strings without the line ending character.

Returns:

  • (Array<String>)


95
96
97
# File 'lib/vedeu/templating/view_template.rb', line 95

def lines
  content.lines.map(&:chomp)
end

#parseVedeu::Views::Lines

Returns:



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

#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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#snake_case(name) ⇒ 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.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#streams_for(line) ⇒ Array<String> (private)

Returns the stream directives for the line.

Parameters:

  • line (String)

Returns:

  • (Array<String>)


87
88
89
# File 'lib/vedeu/templating/view_template.rb', line 87

def streams_for(line)
  line.split(/({{\s*[^}]+\s*}})/)
end

#style(value, &block) ⇒ Vedeu::Views::Stream Originally defined in module Helpers

Parameters:

  • value (Symbol)
  • block (Proc)

Returns:

#time_nowString Originally defined in module View

Returns the current local time.

Examples:

time_now # => Mon 29 Jun 19:26

Returns:

  • (String)