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
- #centre(value = '', opts = {}) ⇒ void (also: #center)
- #left(value = '', opts = {}) ⇒ void
-
#line(value = '', opts = {}, &block) ⇒ void
Specify a single line in a view.
-
#lines(opts = {}, &block) ⇒ void
(also: #streams)
Specify multiple lines in a view.
- #requires_block!(&block) ⇒ NilClass private
- #requires_model! ⇒ NilClass private
- #right(value = '', opts = {}) ⇒ void
- #stream(value = '', opts = {}, &block) ⇒ void
-
#text(value = '', opts = {}) ⇒ void
Specify the content for a view.
Methods included from Presentation
#background, #colour, #colour_attributes, #foreground, #no_wordwrap!, #style, #wordwrap
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Instance Method Details
#centre(value = '', opts = {}) ⇒ void Also known as: center
This method returns an undefined value.
273 274 275 276 277 |
# File 'lib/vedeu/dsl/elements.rb', line 273 def centre(value = '', opts = {}) opts[:align] = :centre text(value, opts) end |
#left(value = '', opts = {}) ⇒ void
This method returns an undefined value.
282 283 284 285 286 |
# File 'lib/vedeu/dsl/elements.rb', line 282 def left(value = '', opts = {}) opts[:align] = :left text(value, opts) end |
#line(value = '', opts = {}, &block) ⇒ void
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 raise Vedeu::Error::Fatal, "Cannot add line to '#{model.class.name}' model." end end |
#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 |
#requires_block!(&block) ⇒ NilClass (private)
301 302 303 |
# File 'lib/vedeu/dsl/elements.rb', line 301 def requires_block!(&block) raise Vedeu::Error::RequiresBlock unless block_given? end |
#requires_model! ⇒ NilClass (private)
307 308 309 310 |
# File 'lib/vedeu/dsl/elements.rb', line 307 def requires_model! raise Vedeu::Error::Fatal, 'No model, cannot continue.' unless present?(model) end |
#right(value = '', opts = {}) ⇒ void
This method returns an undefined value.
290 291 292 293 294 |
# File 'lib/vedeu/dsl/elements.rb', line 290 def right(value = '', opts = {}) opts[:align] = :right text(value, opts) end |
#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 |
# 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 raise Vedeu::Error::Fatal, "Cannot add stream to '#{model.class.name}' model." end end |
#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.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/vedeu/dsl/elements.rb', line 246 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 raise Vedeu::Error::Fatal, "Cannot add text to '#{model.class.name}' model." end end |