Class: Vedeu::DSL::Composition
- Inherits:
-
Object
- Object
- Vedeu::DSL::Composition
- 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 (‘Stream`) which are basically subsets of the line.
-
An interface, line or stream can have a colour (‘colour`) attribute.
-
An interface, line or stream can have a style (‘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
Attributes included from Vedeu::DSL
Instance Method Summary collapse
-
#existing_attributes(name) ⇒ Hash
private
Retrieve the attributes of the interface by name.
-
#initialize(model, client = nil) ⇒ Vedeu::DSL::Composition
constructor
Returns an instance of DSL::Composition.
-
#new_attributes(name) ⇒ Hash
private
Return the current attributes combined with the existing interface attributes defined by the interface.
- #template_attributes(name, lines) ⇒ Hash private
-
#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Views::Views<Vedeu::Views::View>
Load content from an ERb template.
-
#view(name = '', &block) ⇒ Vedeu::Views::Views<Vedeu::Views::View>
Define a view.
Methods included from Vedeu::DSL
Constructor Details
#initialize(model, client = nil) ⇒ Vedeu::DSL::Composition
Returns an instance of DSL::Composition.
48 49 50 51 |
# File 'lib/vedeu/dsl/composition.rb', line 48 def initialize(model, client = nil) @model = model @client = client end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Method Details
#existing_attributes(name) ⇒ Hash (private)
Retrieve the attributes of the interface by name.
144 145 146 |
# File 'lib/vedeu/dsl/composition.rb', line 144 def existing_attributes(name) Vedeu.interfaces.by_name(name).attributes end |
#new_attributes(name) ⇒ Hash (private)
Return the current attributes combined with the existing interface attributes defined by the interface.
136 137 138 |
# File 'lib/vedeu/dsl/composition.rb', line 136 def new_attributes(name) attributes.merge!(existing_attributes(name)) end |
#template_attributes(name, lines) ⇒ Hash (private)
127 128 129 |
# File 'lib/vedeu/dsl/composition.rb', line 127 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>
More documentation required.
Load content from an ERb template.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vedeu/dsl/composition.rb', line 103 def template_for(name, filename, object = nil, = {}) fail Vedeu::Error::MissingRequired, 'Cannot render template without the name of the view.' unless name fail Vedeu::Error::MissingRequired, 'Cannot render template without a filename.' unless filename .merge!(name: name) content = Vedeu::Templating::ViewTemplate.parse(object, filename, ) # 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>
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.
74 75 76 77 78 79 80 |
# File 'lib/vedeu/dsl/composition.rb', line 74 def view(name = '', &block) fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given? new_model = model.member.build(new_attributes(name), &block) model.add(new_model) end |