Class: Bread::ControllerLayoutCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/bread/commands/controller_layout_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ControllerLayoutCommand

Returns a new instance of ControllerLayoutCommand.



6
7
8
9
10
11
12
13
14
# File 'lib/bread/commands/controller_layout_command.rb', line 6

def initialize(controller)
  IvarsCommand.new(controller).ivars.each do |key, ivar|
    self.instance_variable_set(key, ivar)
  end
  
  @controller = controller
  @actions = {}
  @keys = []
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



4
5
6
# File 'lib/bread/commands/controller_layout_command.rb', line 4

def keys
  @keys
end

Instance Method Details

#actions(*action_names, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bread/commands/controller_layout_command.rb', line 16

def actions(*action_names, &block)
  action_names.each do |action_name|
    @actions[action_name] = block
    is_current_action = action_name.to_s == @controller.action_name

    if is_current_action
      self.instance_eval(&block)
      # teria que ter um break aqui, que tambem pare todos os registros de proximas actions =D
    end
  end
end

#crumbs(*keys) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bread/commands/controller_layout_command.rb', line 28

def crumbs(*keys)
  parent = nil
  if keys.last.is_a? Hash
    options = keys.last
    keys.delete(options)
    #raise "Unexpected options: #{}"
    parent = options[:parent]
  end
  @keys = keys + @keys
  if parent
    blk = @actions[parent]
    instance_eval(&blk)
  end
end