Class: Vedeu::Borders::DSL

Inherits:
Object
  • Object
show all
Includes:
DSL, DSL::Presentation, DSL::Use
Defined in:
lib/vedeu/borders/dsl.rb

Overview

Provides a mechanism to help configure borders in Vedeu.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Attribute Details

#clientObject (readonly, protected) Originally defined in module DSL

Returns The object instance where the DSL is being used.

Returns:

  • (Object)

    The object instance where the DSL is being used.

#modelvoid (readonly, protected) Originally defined in module DSL

This method returns an undefined value.

Returns The new model object which the DSL is constructing.

Class Method Details

.border(name, &block) ⇒ Vedeu::Borders::Border

Specify the border of an interface or view with a simple DSL.

Vedeu.border :some_interface do
  # ...
end

Parameters:

  • name (String|Symbol)

    The name of the interface or view to which this border belongs.

  • block (Proc)

Returns:

Raises:



24
25
26
27
28
# File 'lib/vedeu/borders/dsl.rb', line 24

def self.border(name, &block)
  fail Vedeu::Error::RequiresBlock unless block_given?

  Vedeu::Borders::Border.build(enabled: true, name: name, &block).store
end

Instance Method Details

#attributesHash<Symbol => void> (private) Originally defined in module DSL

Note:

Specific DSL classes may be overriding this method.

Returns the default attributes for the new model.

Returns:

  • (Hash<Symbol => void>)

#background(value = '') ⇒ String Also known as: bg, bgcolor, background=, bg=, bgcolor= Originally defined in module DSL::Presentation

Note:

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.

Examples:

interface 'my_interface' do
  background '#0022ff' # /or/ (blue)
  bgcolor    '#22ff00' # /or/ (blue is overridden to green)
  bg         '#ff0022' #      (green is overridden to red)
  # ...

  lines do
    background '#2200ff'
    # ...

    stream do
      background '#22ff00'
      # ...
    end
  end
end

Parameters:

  • value (String) (defaults to: '')

    A HTML/CSS value.

Returns:

  • (String)

#bottom(value) ⇒ Boolean Also known as: show_bottom, bottom=

Enable/disable the bottom border.

Vedeu.border :border_demo do
  bottom true  # or...
  bottom false # or...
  hide_bottom! # or...
  show_bottom!
  # ... some code
end

and false.

Parameters:

  • value (Boolean)

    All values evaluate as true except nil

Returns:

  • (Boolean)


131
132
133
134
135
# File 'lib/vedeu/borders/dsl.rb', line 131

def bottom(value)
  boolean = value ? true : false

  model.show_bottom = boolean
end

#bottom_left(char) ⇒ String Also known as: bottom_left=

Set the character to be used to draw the bottom left corner of the border.

Vedeu.border :border_demo do
  bottom_left '+'
  # ... some code
end

Parameters:

  • char (String)

    Character to be used as the bottom left border character.

Returns:

  • (String)


41
42
43
# File 'lib/vedeu/borders/dsl.rb', line 41

def bottom_left(char)
  model.bottom_left = char
end

#bottom_right(char) ⇒ String Also known as: bottom_right=

Set the character to be used to draw the bottom right corner of the border.

Vedeu.border :border_demo do
  bottom_right '+'
  # ... some code
end

Parameters:

  • char (String)

    Character to be used as the bottom right border character.

Returns:

  • (String)


57
58
59
# File 'lib/vedeu/borders/dsl.rb', line 57

def bottom_right(char)
  model.bottom_right = char
end

#caption(value) ⇒ String Also known as: caption=

If you have you are showing a bottom border, you could add a caption.

Vedeu.border :border_demo do
  caption 'My Cool Caption'
  # ... some code
end

produces, depending on other customisations:

+------------------------------ My Cool Caption -+

Parameters:

  • value (String)

    The caption.

Returns:

  • (String)


256
257
258
# File 'lib/vedeu/borders/dsl.rb', line 256

def caption(value)
  model.caption = value
end

#colour(attrs = {}) ⇒ Vedeu::Colours::Colour Also known as: colour= Originally defined in module DSL::Presentation

Note:

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.

Examples:

interface 'my_interface' do
  colour background: '#ff00ff', foreground: '#ffff00'
  # ...

  lines do
    colour background: '#000000', foreground: '#ffffff'
    # ...

    stream do
      colour background: '#000000', foreground: '#ffffff'
      # ...
    end
  end
end

Parameters:

Returns:

#colour_attributesHash<Symbol => String> (private) Originally defined in module DSL::Presentation

Returns:

  • (Hash<Symbol => String>)

#disable!Boolean

Disable the border:

Vedeu.border :border_demo do
  disable!
  # ... some other code (will be ignored)
end

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
# File 'lib/vedeu/borders/dsl.rb', line 70

def disable!
  model.enabled = false

  hide_bottom!
  hide_left!
  hide_right!
  hide_top!

  model.enabled
end

#enable!Boolean

Enable the border: (Borders are enabled by default when defined for an interface).

Vedeu.border :border_demo do
  enable!
  # ... some code
end

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
# File 'lib/vedeu/borders/dsl.rb', line 91

def enable!
  model.enabled = true

  show_bottom!
  show_left!
  show_right!
  show_top!

  model.enabled
end

#foreground(value = '') ⇒ Object Also known as: fg, fgcolor, foreground=, fg=, fgcolor= Originally defined in module DSL::Presentation

See Also:

#hide_bottom!Object

Disable the bottom border.

See Also:



142
143
144
# File 'lib/vedeu/borders/dsl.rb', line 142

def hide_bottom!
  bottom(false)
end

#hide_left!Object

Disable the left border.

See Also:



177
178
179
# File 'lib/vedeu/borders/dsl.rb', line 177

def hide_left!
  left(false)
end

#hide_right!Object

Disable the right border.

See Also:



212
213
214
# File 'lib/vedeu/borders/dsl.rb', line 212

def hide_right!
  right(false)
end

#hide_top!Object

Disable the top border.

See Also:



285
286
287
# File 'lib/vedeu/borders/dsl.rb', line 285

def hide_top!
  top(false)
end

#horizontal(char) ⇒ String Also known as: horizontal=

Set the character to be used to draw a horizontal part of the border.

Vedeu.border :border_demo do
  horizontal '-'
  # ... some code
end

Parameters:

  • char (String)

    Character to be used as the horizontal border character.

Returns:

  • (String)


113
114
115
# File 'lib/vedeu/borders/dsl.rb', line 113

def horizontal(char)
  model.horizontal = char
end

#initialize(model, client = nil) ⇒ void Originally defined in module DSL

Returns an instance of the DSL class including Vedeu::DSL.

Parameters:

  • model (void)

    The model class which the DSL class is wrapping.

  • client (void) (defaults to: nil)

    The class where the DSL methods are being used.

#left(value) ⇒ Boolean Also known as: show_left, left=

Enable/disable the left border.

Vedeu.border :border_demo do
  left true  # or...
  left false # or...
  hide_left! # or...
  show_left!
  # ... some code
end

Parameters:

  • value (Boolean)

    All values evaluate as true except nil and false.

Returns:

  • (Boolean)


166
167
168
169
170
# File 'lib/vedeu/borders/dsl.rb', line 166

def left(value)
  boolean = value ? true : false

  model.show_left = boolean
end

#right(value) ⇒ Boolean Also known as: show_right, right=

Enable/disable the right border.

Vedeu.border :border_demo do
  right true  # or...
  right false # or...
  hide_right! # or...
  show_right!
  # ... some code
end

Parameters:

  • value (Boolean)

    All values evaluate as true except nil and false.

Returns:

  • (Boolean)


201
202
203
204
205
# File 'lib/vedeu/borders/dsl.rb', line 201

def right(value)
  boolean = value ? true : false

  model.show_right = boolean
end

#show_bottom!Object

Enable the bottom border.

See Also:



149
150
151
# File 'lib/vedeu/borders/dsl.rb', line 149

def show_bottom!
  bottom(true)
end

#show_left!Object

Enable the left border.

See Also:



184
185
186
# File 'lib/vedeu/borders/dsl.rb', line 184

def show_left!
  left(true)
end

#show_right!Object

Enable the right border.

See Also:



219
220
221
# File 'lib/vedeu/borders/dsl.rb', line 219

def show_right!
  right(true)
end

#show_top!Object

Enable the top border.

See Also:



292
293
294
# File 'lib/vedeu/borders/dsl.rb', line 292

def show_top!
  top(true)
end

#style(value) ⇒ Vedeu::Presentation::Style Also known as: style=, styles, styles= Originally defined in module DSL::Presentation

Define a style or styles for an interface, line or a stream.

Examples:

interface 'my_interface' do
  style 'normal'
  # ...
end

lines do
  style ['bold', 'underline']
  # ...
end

stream do
  style 'blink'
  # ...
end

Parameters:

  • value (Array<Symbol>|Array<String>|Symbol|String)

Returns:

#title(value) ⇒ String Also known as: title=

If you have you are showing a top border, you could add a title.

Vedeu.border :border_demo do
  title 'My Cool Title'
  # ... some code
end

produces, depending on other customisations:

+- My Cool Title --------------------------------+

Parameters:

  • value (String)

    The title.

Returns:

  • (String)


237
238
239
# File 'lib/vedeu/borders/dsl.rb', line 237

def title(value)
  model.title = value
end

#top(value) ⇒ Boolean Also known as: show_top, top=

Enable/disable the top border.

Vedeu.border :border_demo do
  top true  # or...
  top false # or...
  hide_top! # or...
  show_top!
  # ... some code
end

Parameters:

  • value (Boolean)

    All values evaluate as true except nil and false.

Returns:

  • (Boolean)


274
275
276
277
278
# File 'lib/vedeu/borders/dsl.rb', line 274

def top(value)
  boolean = value ? true : false

  model.show_top = boolean
end

#top_left(char) ⇒ String Also known as: top_left=

Set the character to be used to draw the top left corner of the border.

Vedeu.border :border_demo do
  top_left '+'
  # ... some code
end

Parameters:

  • char (String)

    Character to be used as the top left border character.

Returns:

  • (String)


307
308
309
# File 'lib/vedeu/borders/dsl.rb', line 307

def top_left(char)
  model.top_left = char
end

#top_right(char) ⇒ String Also known as: top_right=

Set the character to be used to draw the top right corner of the border.

Vedeu.border :border_demo do
  top_right '+'
  # ... some code
end

Parameters:

  • char (String)

    Character to be used as the top right border character.

Returns:

  • (String)


323
324
325
# File 'lib/vedeu/borders/dsl.rb', line 323

def top_right(char)
  model.top_right = char
end

#use(name) ⇒ void Originally defined in module DSL::Use

Note:
  • Only models of the same repository can be used in this way.

  • If the stored model cannot be found, a ModelNotFound exception may be raised, or the request for an attribute may raise a NoMethodError exception.

This method returns an undefined value.

Use the attribute of stored model.

This DSL method provides access to a stored model by name. You can then request an attribute of that model for use within the current model. The models which current support this are Border, Geometry and Interface.

Examples:

# Here the character used for :my_border is used in
# :my_other_border.
Vedeu.border :my_other_border do
  top_right use(:my_border).top_right
end

Parameters:

  • name (String|Symbol)

    The name of the model with the value you wish to use.

Raises:

  • Vedeu::Error::ModelNotFound|Vedeu::Error::NoMethodError

    The model or attribute cannot be found.

#vertical(char) ⇒ String Also known as: vertical=

Set the character to be used to draw a vertical part of the border.

Vedeu.border :border_demo do
  vertical '|'
  # ... some code
end

Parameters:

  • char (String)

    Character to be used as the vertical border character.

Returns:

  • (String)


339
340
341
# File 'lib/vedeu/borders/dsl.rb', line 339

def vertical(char)
  model.vertical = char
end