Module: Vedeu::DSL::Elements
- Includes:
- Common, Presentation
- Included in:
- Views, Views::Line::DSL, Views::Stream::DSL, Views::View::DSL
- Defined in:
- lib/vedeu/dsl/elements.rb
Overview
This documentation needs editing and is out of date.
(GL: 2015-12-25)
Provides methods to be used to define views.
Vedeu.renders do
view :my_interface do
lines do
background '#000000'
foreground '#ffffff'
line 'This is white text on a black background.'
line 'Next is a blank line:'
line ''
streams { stream 'We can define ' }
streams do
foreground '#ff0000'
stream 'parts of a line '
end
streams { stream 'independently using ' }
streams do
foreground '#00ff00'
stream 'streams.'
end
end
end
end
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#background(value = '') ⇒ String
(also: #bg, #bgcolor, #background=, #bg=, #bgcolor=)
included
from Presentation
Define the background colour for an interface, line, or a stream.
-
#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.
- #centre(value = '', opts = {}) ⇒ void (also: #center)
-
#colour(attrs = {}) ⇒ Vedeu::Colours::Colour
(also: #colour=)
included
from Presentation
Define either or both foreground and background colours for an interface, line or a stream.
- #colour_attributes ⇒ Hash<Symbol => String> included from Presentation 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 = '') ⇒ Object (also: #fg, #fgcolor, #foreground=, #fg=, #fgcolor=) included from Presentation
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
- #left(value = '', opts = {}) ⇒ void
-
#line(value = '', opts = {}, &block) ⇒ void
Specify a single line in a view.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#lines(opts = {}, &block) ⇒ void
(also: #streams)
Specify multiple lines in a view.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- #requires_block!(&block) ⇒ NilClass private
- #requires_model! ⇒ NilClass private
- #right(value = '', opts = {}) ⇒ void
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
- #stream(value = '', opts = {}, &block) ⇒ void
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#style(value) ⇒ Vedeu::Presentation::Style
(also: #style=, #styles, #styles=)
included
from Presentation
Define a style or styles for an interface, line or a stream.
-
#text(value = '', opts = {}) ⇒ void
Specify the content for a view.
-
#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.
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 = '') ⇒ String Also known as: bg, bgcolor, background=, bg=, bgcolor= Originally defined in module Presentation
The last defined background colour for a particular interface, line or stream overrides previously defined entries in the same block.
Define the background colour for an interface, line, or a stream. When called with a block, will create a new stream with the background colour specified. When the block terminates, the background will return to that of the parent.
#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.
#centre(value = '', opts = {}) ⇒ void Also known as: center
This method returns an undefined value.
274 275 276 277 278 |
# File 'lib/vedeu/dsl/elements.rb', line 274 def centre(value = '', opts = {}) opts[:align] = :centre text(value, opts) end |
#colour(attrs = {}) ⇒ Vedeu::Colours::Colour Also known as: colour= Originally defined in module Presentation
Rejects invalid keys and empty/nil attributes. Also, the last defined colour for a particular interface, line or stream overrides previously defined entries in the same block.
Define either or both foreground and background colours for an interface, line or a stream. At least one attribute is required.
#colour_attributes ⇒ Hash<Symbol => String> (private) Originally defined in module Presentation
#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 = '') ⇒ Object Also known as: fg, fgcolor, foreground=, fg=, fgcolor= Originally defined in module Presentation
#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.
#left(value = '', opts = {}) ⇒ void
This method returns an undefined value.
283 284 285 286 287 |
# File 'lib/vedeu/dsl/elements.rb', line 283 def left(value = '', opts = {}) opts[:align] = :left text(value, opts) end |
#line(value = '', opts = {}, &block) ⇒ void
This documentation needs editing. (GL: 2015-12-17)
This method returns an undefined value.
Specify a single line in a view.
Vedeu.renders do
view :my_interface do
lines do
line 'some text...'
# ... some code
line 'some more text...'
# ... some code
end
end
end
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/vedeu/dsl/elements.rb', line 118 def line(value = '', opts = {}, &block) requires_model! attrs = Vedeu::DSL::Attributes.build(self, model, value, opts, &block) l = if block_given? Vedeu::Views::Line.build(attrs, &block) else s = Vedeu::Views::Stream.new(attrs) ss = Vedeu::Views::Streams.coerce([s]) Vedeu::Views::Line.new(attrs.merge!(value: ss)) end if view_model? model.add(l) elsif line_model? model.add(l.value) else fail Vedeu::Error::Fatal, "Cannot add line to '#{model.class.name}' model." end 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(opts = {}, &block) ⇒ void Also known as: streams
This documentation needs editing. (GL: 2015-12-17)
This method returns an undefined value.
Specify multiple lines in a view.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vedeu/dsl/elements.rb', line 66 def lines(opts = {}, &block) requires_block!(&block) requires_model! attrs = Vedeu::DSL::Attributes.build(self, model, nil, opts, &block) if view_model? if model.lines? l = Vedeu::Views::Line.build(attrs, &block) model.add(l) else l = Vedeu::Views::View.build(attrs, &block) model.value = l.value end elsif line_model? l = Vedeu::Views::Line.build(attrs, &block) model.value = l.value else l = Vedeu::Views::View.build(attrs, &block) model.value = l.value end 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.
#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.
#requires_block!(&block) ⇒ NilClass (private)
302 303 304 |
# File 'lib/vedeu/dsl/elements.rb', line 302 def requires_block!(&block) fail Vedeu::Error::RequiresBlock unless block_given? end |
#requires_model! ⇒ NilClass (private)
309 310 311 312 |
# File 'lib/vedeu/dsl/elements.rb', line 309 def requires_model! fail Vedeu::Error::Fatal, 'No model, cannot continue.' unless present?(model) end |
#right(value = '', opts = {}) ⇒ void
This method returns an undefined value.
291 292 293 294 295 |
# File 'lib/vedeu/dsl/elements.rb', line 291 def right(value = '', opts = {}) opts[:align] = :right text(value, opts) end |
#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(value = '', opts = {}, &block) ⇒ void
This method returns an undefined value.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/vedeu/dsl/elements.rb', line 153 def stream(value = '', opts = {}, &block) requires_model! attrs = Vedeu::DSL::Attributes.build(self, model, value, opts, &block) l = if block_given? if view_model? Vedeu::Views::Line.build(attrs, &block) else Vedeu::Views::Stream.build(attrs, &block) end else s = Vedeu::Views::Stream.new(attrs) ss = Vedeu::Views::Streams.coerce([s]) Vedeu::Views::Line.new(attrs.merge!(value: ss)) end if view_model? model.add(l) elsif line_model? || stream_model? model.add([l]) else fail Vedeu::Error::Fatal, "Cannot add stream to '#{model.class.name}' model." end 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.
#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) ⇒ Vedeu::Presentation::Style Also known as: style=, styles, styles= Originally defined in module Presentation
Define a style or styles for an interface, line or a stream.
#text(value = '', opts = {}) ⇒ void
This documentation needs editing. (GL: 2015-12-17)
If using the convenience methods; left, centre, center or right, then a specified align option will be ignored.
This method returns an undefined value.
Specify the content for a view. Provides the means to align a string (or object responding to ‘to_s`), and add it as a Line or to the Stream.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/vedeu/dsl/elements.rb', line 247 def text(value = '', opts = {}) requires_model! attrs = Vedeu::DSL::Attributes.build(self, model, value, opts) stream = Vedeu::Views::Stream.new(attrs) if view_model? ss = Vedeu::Views::Streams.coerce([stream]) l = Vedeu::Views::Line.new(attrs.merge!(value: ss)) model.add(l) elsif line_model? model.add(stream) elsif stream_model? model.add(stream.value) else fail Vedeu::Error::Fatal, "Cannot add text to '#{model.class.name}' model." end end |
#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.