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

Attributes included from DSL

#client, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL::Use

#use

Methods included from DSL::Presentation

#background, #colour, #colour_attributes, #foreground, #style

Methods included from DSL

#attributes, #method_missing

Constructor Details

#initialize(model, client = nil) ⇒ Vedeu::Borders::DSL

Returns an instance of Borders::DSL.



36
37
38
39
# File 'lib/vedeu/borders/dsl.rb', line 36

def initialize(model, client = nil)
  @model  = model
  @client = client
end

Dynamic Method Handling

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

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

Raises:



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

def self.border(name, &block)
  fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?

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

Instance Method Details

#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.



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

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


52
53
54
# File 'lib/vedeu/borders/dsl.rb', line 52

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


68
69
70
# File 'lib/vedeu/borders/dsl.rb', line 68

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 -+


267
268
269
# File 'lib/vedeu/borders/dsl.rb', line 267

def caption(value)
  model.caption = value
end

#disable!Boolean

Disable the border:

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


81
82
83
84
85
86
87
88
89
90
# File 'lib/vedeu/borders/dsl.rb', line 81

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


102
103
104
105
106
107
108
109
110
111
# File 'lib/vedeu/borders/dsl.rb', line 102

def enable!
  model.enabled = true

  show_bottom!
  show_left!
  show_right!
  show_top!

  model.enabled
end

#hide_bottom!Object

Disable the bottom border.

See Also:



153
154
155
# File 'lib/vedeu/borders/dsl.rb', line 153

def hide_bottom!
  bottom(false)
end

#hide_left!Object

Disable the left border.

See Also:



188
189
190
# File 'lib/vedeu/borders/dsl.rb', line 188

def hide_left!
  left(false)
end

#hide_right!Object

Disable the right border.

See Also:



223
224
225
# File 'lib/vedeu/borders/dsl.rb', line 223

def hide_right!
  right(false)
end

#hide_top!Object

Disable the top border.

See Also:



296
297
298
# File 'lib/vedeu/borders/dsl.rb', line 296

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


124
125
126
# File 'lib/vedeu/borders/dsl.rb', line 124

def horizontal(char)
  model.horizontal = char
end

#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


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

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


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

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

  model.show_right = boolean
end

#show_bottom!Object

Enable the bottom border.

See Also:



160
161
162
# File 'lib/vedeu/borders/dsl.rb', line 160

def show_bottom!
  bottom(true)
end

#show_left!Object

Enable the left border.

See Also:



195
196
197
# File 'lib/vedeu/borders/dsl.rb', line 195

def show_left!
  left(true)
end

#show_right!Object

Enable the right border.

See Also:



230
231
232
# File 'lib/vedeu/borders/dsl.rb', line 230

def show_right!
  right(true)
end

#show_top!Object

Enable the top border.

See Also:



303
304
305
# File 'lib/vedeu/borders/dsl.rb', line 303

def show_top!
  top(true)
end

#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 --------------------------------+


248
249
250
# File 'lib/vedeu/borders/dsl.rb', line 248

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


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

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


318
319
320
# File 'lib/vedeu/borders/dsl.rb', line 318

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


334
335
336
# File 'lib/vedeu/borders/dsl.rb', line 334

def top_right(char)
  model.top_right = char
end

#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


350
351
352
# File 'lib/vedeu/borders/dsl.rb', line 350

def vertical(char)
  model.vertical = char
end