Class: Buttonize::ButtonSet

Inherits:
Object
  • Object
show all
Defined in:
lib/buttonize/button_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ButtonSet

Returns a new instance of ButtonSet.



26
27
28
29
30
31
32
33
# File 'lib/buttonize/button_set.rb', line 26

def initialize(options)
  defaults = {:style_set => :default}
  @options = defaults.update(options)
  @buttons = []
  @groups = []
  @path = ""
  @parent = nil
end

Instance Attribute Details

#buttonsObject (readonly)

Returns the value of attribute buttons.



23
24
25
# File 'lib/buttonize/button_set.rb', line 23

def buttons
  @buttons
end

#groupsObject (readonly)

Returns the value of attribute groups.



23
24
25
# File 'lib/buttonize/button_set.rb', line 23

def groups
  @groups
end

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/buttonize/button_set.rb', line 23

def options
  @options
end

#pathObject

Returns the value of attribute path.



24
25
26
# File 'lib/buttonize/button_set.rb', line 24

def path
  @path
end

Class Method Details

.currentObject



18
19
20
# File 'lib/buttonize/button_set.rb', line 18

def current
  @@set
end

.define(options = {}) {|@@set| ... } ⇒ Object

Define a buttonset

Options

:style_file

The style definition file to load

:style_set

The styleset to use, defaults to :default

:target_path

The output directory

Yields:

  • (@@set)


12
13
14
15
16
# File 'lib/buttonize/button_set.rb', line 12

def define(options={},&block)
  @@set = self.new(options)
  yield @@set
  @@set
end

Instance Method Details

#button(text, *opts) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/buttonize/button_set.rb', line 43

def button(text,*opts)
  button = {:text => text, :options => {}}
  button[:options] = opts.pop if opts.last.kind_of?(Hash)
  button[:filename] = opts.pop if opts.last.kind_of?(String)
  @buttons << button
  button
end

#generate(options) ⇒ Object

Generate all buttons recursively, all options set in define can be overruled here. –



54
55
56
57
58
# File 'lib/buttonize/button_set.rb', line 54

def generate(options)
  # Don't run this when we're in cli mode
  return if Buttonize.cli?
  generate_buttons(options)
end

#group(name, options = {}) {|group| ... } ⇒ Object

Yields:



35
36
37
38
39
40
41
# File 'lib/buttonize/button_set.rb', line 35

def group(name,options={})
  group = self.class.new({}.update(self.options).update(options))
  group.path = File.join(self.path,name)
  yield group
  @groups << group
  group
end