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
- #build_attributes(value = '', opts = {}, &block) ⇒ Vedeu::DSL::Attributes private
- #build_line(attrs, &block) ⇒ Vedeu::Views::Line private
- #build_stream(attrs, &block) ⇒ Vedeu::Views::Stream private
- #build_view(attrs, &block) ⇒ Vedeu::Views::View private
- #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.
- #new_line(attrs) ⇒ Vedeu::Views::Line private
- #new_stream(attrs) ⇒ Vedeu::Views::Stream private
- #new_streams(attrs) ⇒ Vedeu::Views::Streams private
- #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
#build_attributes(value = '', opts = {}, &block) ⇒ Vedeu::DSL::Attributes (private)
282 283 284 |
# File 'lib/vedeu/dsl/elements.rb', line 282 def build_attributes(value = '', opts = {}, &block) Vedeu::DSL::Attributes.build(self, model, value, opts, &block) end |
#build_line(attrs, &block) ⇒ Vedeu::Views::Line (private)
289 290 291 |
# File 'lib/vedeu/dsl/elements.rb', line 289 def build_line(attrs, &block) Vedeu::Views::Line.build(attrs, &block) end |
#build_stream(attrs, &block) ⇒ Vedeu::Views::Stream (private)
296 297 298 |
# File 'lib/vedeu/dsl/elements.rb', line 296 def build_stream(attrs, &block) Vedeu::Views::Stream.build(attrs, &block) end |
#build_view(attrs, &block) ⇒ Vedeu::Views::View (private)
303 304 305 |
# File 'lib/vedeu/dsl/elements.rb', line 303 def build_view(attrs, &block) Vedeu::Views::View.build(attrs, &block) end |
#centre(value = '', opts = {}) ⇒ void Also known as: center
This method returns an undefined value.
258 259 260 |
# File 'lib/vedeu/dsl/elements.rb', line 258 def centre(value = '', opts = {}) text(value, opts.merge(align: :centre)) end |
#left(value = '', opts = {}) ⇒ void
This method returns an undefined value.
265 266 267 |
# File 'lib/vedeu/dsl/elements.rb', line 265 def left(value = '', opts = {}) text(value, opts.merge(align: :left)) end |
#line(value = '', opts = {}, &block) ⇒ void
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/vedeu/dsl/elements.rb', line 114 def line(value = '', opts = {}, &block) requires_model! attrs = build_attributes(value, opts, &block) l = if block_given? build_line(attrs, &block) else new_line(attrs) 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 |
# File 'lib/vedeu/dsl/elements.rb', line 66 def lines(opts = {}, &block) requires_block!(&block) requires_model! attrs = build_attributes(nil, opts, &block) if view_model? if model.lines? model.add(build_line(attrs, &block)) else model.value = build_view(attrs, &block).value end elsif line_model? model.value = build_line(attrs, &block).value else model.value = build_view(attrs, &block).value end end |
#new_line(attrs) ⇒ Vedeu::Views::Line (private)
309 310 311 |
# File 'lib/vedeu/dsl/elements.rb', line 309 def new_line(attrs) Vedeu::Views::Line.new(attrs.merge(value: new_streams(attrs))) end |
#new_stream(attrs) ⇒ Vedeu::Views::Stream (private)
315 316 317 |
# File 'lib/vedeu/dsl/elements.rb', line 315 def new_stream(attrs) Vedeu::Views::Stream.new(attrs) end |
#new_streams(attrs) ⇒ Vedeu::Views::Streams (private)
321 322 323 |
# File 'lib/vedeu/dsl/elements.rb', line 321 def new_streams(attrs) Vedeu::Views::Streams.coerce([new_stream(attrs)]) end |
#requires_block!(&block) ⇒ NilClass (private)
328 329 330 |
# File 'lib/vedeu/dsl/elements.rb', line 328 def requires_block!(&block) raise Vedeu::Error::RequiresBlock unless block_given? end |
#requires_model! ⇒ NilClass (private)
334 335 336 337 |
# File 'lib/vedeu/dsl/elements.rb', line 334 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.
271 272 273 |
# File 'lib/vedeu/dsl/elements.rb', line 271 def right(value = '', opts = {}) text(value, opts.merge(align: :right)) end |
#stream(value = '', opts = {}, &block) ⇒ void
This method returns an undefined value.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/vedeu/dsl/elements.rb', line 147 def stream(value = '', opts = {}, &block) requires_model! attrs = build_attributes(value, opts, &block) m = if block_given? if view_model? build_line(attrs, &block) else build_stream(attrs, &block) end else new_line(attrs) end if view_model? || line_model? || stream_model? model.add(m) 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.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/vedeu/dsl/elements.rb', line 235 def text(value = '', opts = {}) requires_model! attrs = build_attributes(value, opts) if view_model? model.add(new_line(attrs)) elsif line_model? model.add(new_stream(attrs)) elsif stream_model? model.add(new_stream(attrs).value) else raise Vedeu::Error::Fatal, "Cannot add text to '#{model.class.name}' model." end end |