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.
268 269 270 271 272 |
# File 'lib/vedeu/dsl/elements.rb', line 268 def centre(value = '', opts = {}) opts[:align] = :centre text(value, opts) end |
#left(value = '', opts = {}) ⇒ void
This method returns an undefined value.
277 278 279 280 281 |
# File 'lib/vedeu/dsl/elements.rb', line 277 def left(value = '', opts = {}) opts[:align] = :left text(value, opts) end |
#line(value = '', opts = {}, &block) ⇒ void
116 117 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 |
# File 'lib/vedeu/dsl/elements.rb', line 116 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 |
# 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) l = Vedeu::Views::Line.build(attrs, &block) v = Vedeu::Views::View.build(attrs, &block) if view_model? if model.lines? model.add(l) else model.value = v.value end elsif line_model? model.value = l.value else model.value = v.value end end |
#requires_block!(&block) ⇒ NilClass (private)
296 297 298 |
# File 'lib/vedeu/dsl/elements.rb', line 296 def requires_block!(&block) raise Vedeu::Error::RequiresBlock unless block_given? end |
#requires_model! ⇒ NilClass (private)
302 303 304 305 |
# File 'lib/vedeu/dsl/elements.rb', line 302 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.
285 286 287 288 289 |
# File 'lib/vedeu/dsl/elements.rb', line 285 def right(value = '', opts = {}) opts[:align] = :right text(value, opts) end |
#stream(value = '', opts = {}, &block) ⇒ void
This method returns an undefined value.
151 152 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 |
# File 'lib/vedeu/dsl/elements.rb', line 151 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? || 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.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/vedeu/dsl/elements.rb', line 241 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 |