Class: Vedeu::DSL::Composition

Inherits:
Object
  • Object
show all
Includes:
Vedeu::DSL
Defined in:
lib/vedeu/dsl/composition.rb

Overview

  • A view (‘Composition`) is made up of one or more interfaces.

  • An interface is an area on the screen where you can take input or direct output. You will define it’s colour and style, its dimensions, including position and give it a name. You can then direct the output of a command, or event, to this interface and Vedeu will ensure the content is placed there.

  • Interfaces (‘Interface`) are made up of lines (`Line`), their length being the width of the interface and their number being the height of the interface.

  • An interface with ‘width: 12, height: 5` will have five lines, each made of 12 characters- providing 60 cells. Colours and styles are handled by terminal escape sequences and therefore do not consume a cell.

  • Lines are made up of zero, one or multiple streams which are basically subsets of the line.

  • An interface, line or stream can have a colour attribute.

  • An interface, line or stream can have a style attribute.

  • Interfaces have a position (‘y`, `x`) on the screen, and a size. (`width`, `height`)

  • Interfaces can be placed relative to each other based on their attributes.

    • An interface has a ‘top`, `right`, `bottom`, `left`.

    • An interface also has a ‘north` and `west` (`top` and `left` minus 1 respectively).

    • An interface also has a ‘south` and `east` (`bottom` and `right` plus 1 respectively).

  • Colours are defined in CSS-style values, i.e. ‘#ff0000` would be red.

  • Styles are named. See the table below for supported styles.

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Attribute Details

#clientObject (readonly, protected) Originally defined in module Vedeu::DSL

Returns The object instance where the DSL is being used.

Returns:

  • (Object)

    The object instance where the DSL is being used.

#modelvoid (readonly, protected) Originally defined in module Vedeu::DSL

This method returns an undefined value.

Returns The new model object which the DSL is constructing.

Instance Method Details

#attributesHash<Symbol => void> (private) Originally defined in module Vedeu::DSL

Note:

Specific DSL classes may be overriding this method.

Returns the default attributes for the new model.

Returns:

  • (Hash<Symbol => void>)

#existing_attributes(name) ⇒ Hash<Symbol => void> (private)

Retrieve the attributes of the interface by name.

Parameters:

  • name (String|Symbol)

    The name of the interface.

Returns:

  • (Hash<Symbol => void>)


137
138
139
# File 'lib/vedeu/dsl/composition.rb', line 137

def existing_attributes(name)
  Vedeu.interfaces.by_name(name).attributes
end

#initialize(model, client = nil) ⇒ void Originally defined in module Vedeu::DSL

Returns an instance of the DSL class including Vedeu::DSL.

Parameters:

  • model (void)

    The model class which the DSL class is wrapping.

  • client (void) (defaults to: nil)

    The class where the DSL methods are being used.

#new_attributes(name) ⇒ Hash<Symbol => void> (private)

Return the current attributes combined with the existing interface attributes defined by the interface.

Parameters:

  • name (String|Symbol)

    The name of the interface.

Returns:

  • (Hash<Symbol => void>)


129
130
131
# File 'lib/vedeu/dsl/composition.rb', line 129

def new_attributes(name)
  existing_attributes(name).merge!(attributes)
end

#template_attributes(name, lines) ⇒ Hash<Symbol => void> (private)

Parameters:

Returns:

  • (Hash<Symbol => void>)


120
121
122
# File 'lib/vedeu/dsl/composition.rb', line 120

def template_attributes(name, lines)
  new_attributes(name).merge!(value: lines)
end

#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Views::Views<Vedeu::Views::View>

TODO:

More documentation required.

Load content from an ERb template.

Examples:

Vedeu.renders do
  template_for(:my_interface,
               '/path/to/template.erb',
               @some_object, options)
end

Parameters:

  • name (String|Symbol)

    The name of interface for which this template’s content belongs to.

  • filename (String)

    The filename (including path) to the template to be used. Yoy can use ‘File.dirname(__FILE__)` to use relative paths.

  • object (Object) (defaults to: nil)

    The object for which the values of template’s variables can be obtained.

  • options (Hash<Symbol => void>) (defaults to: {})

Returns:

Raises:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vedeu/dsl/composition.rb', line 95

def template_for(name, filename, object = nil, options = {})
  fail Vedeu::Error::MissingRequired,
       'Cannot render template without the name of the ' \
       'view.'.freeze unless name
  fail Vedeu::Error::MissingRequired,
       'Cannot render template without a filename.'.freeze unless filename

  options.merge!(name: name)

  content = Vedeu::Templating::ViewTemplate.parse(object,
                                                  filename,
                                                  options)

  # lines     = Vedeu::Output::Wordwrap.for(content, options)

  new_model = model.member.build(template_attributes(name, content))

  model.add(new_model)
end

#view(name = '', &block) ⇒ Vedeu::Views::Views<Vedeu::Views::View>

TODO:

More documentation required.

Define a view.

A view is just an Interface object.

When a view already exists, we take its attributes and use them as the basis for the newly defined view. This way we don’t need to specify everything again.

Examples:

view :my_interface do
  # ...
end

Parameters:

  • name (String|Symbol) (defaults to: '')

    The name of the interface you are targetting for this view.

  • block (Proc)

    The directives you wish to send to this interface.

Returns:

Raises:



66
67
68
69
70
71
72
# File 'lib/vedeu/dsl/composition.rb', line 66

def view(name = '', &block)
  fail Vedeu::Error::RequiresBlock unless block_given?

  new_model = model.member.build(new_attributes(name), &block)

  model.add(new_model)
end