Module: Vedeu::Templating::Helpers

Includes:
View
Included in:
ViewTemplate
Defined in:
lib/vedeu/templating/helpers.rb

Overview

Provide helpers to be used with your Vedeu templates.

Instance Method Summary collapse

Methods included from View

#time_now

Instance Method Details

#background(value, &block) ⇒ Vedeu::Views::Stream Also known as: bg

Parameters:

  • value (String)

    The HTML/CSS colour.

  • block (Proc)

Returns:

Raises:



17
18
19
# File 'lib/vedeu/templating/helpers.rb', line 17

def background(value, &block)
  define_stream(background: value, &block)
end

#colour(attributes = {}, &block) ⇒ Vedeu::Views::Stream

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:



30
31
32
# File 'lib/vedeu/templating/helpers.rb', line 30

def colour(attributes = {}, &block)
  define_stream(attributes, &block)
end

#define_stream(attributes = {}, &block) ⇒ Object (private)

Raises:

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/templating/helpers.rb', line 53

def define_stream(attributes = {}, &block)
  raise Vedeu::Error::RequiresBlock unless block_given?

  value = yield

  encode(
    Vedeu::Views::Stream.build(
      colour: Vedeu::Colours::Colour.new(attributes),
      style:  Vedeu::Presentation::Style.new(attributes[:style]),
      value:  value
    )
  )
end

#encode(data) ⇒ String (private)

Parameters:

  • data (String)

Returns:

  • (String)


69
70
71
# File 'lib/vedeu/templating/helpers.rb', line 69

def encode(data)
  Vedeu::Templating::Encoder.process(data)
end

#foreground(value, &block) ⇒ Vedeu::Views::Stream Also known as: fg

Parameters:

  • value (String)

    The HTML/CSS colour.

  • block (Proc)

Returns:

Raises:



38
39
40
# File 'lib/vedeu/templating/helpers.rb', line 38

def foreground(value, &block)
  define_stream(foreground: value, &block)
end

#style(value, &block) ⇒ Vedeu::Views::Stream

Parameters:

  • value (Symbol)
  • block (Proc)

Returns:



46
47
48
# File 'lib/vedeu/templating/helpers.rb', line 46

def style(value, &block)
  define_stream(style: value, &block)
end