Class: Ekylibre::Navigation::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/ekylibre/navigation/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree) ⇒ DSL

Returns a new instance of DSL.


10
11
12
# File 'lib/ekylibre/navigation/dsl.rb', line 10

def initialize(tree)
  @tree = tree
end

Class Method Details

.run!(tree, &block) ⇒ Object


4
5
6
7
8
# File 'lib/ekylibre/navigation/dsl.rb', line 4

def self.run!(tree, &block)
  dsl = new(tree)
  dsl.instance_exec(&block)
  tree.rebuild_index!
end

Instance Method Details

#group(name, options = {}, &block) ⇒ Object


22
23
24
25
26
27
28
29
30
31
# File 'lib/ekylibre/navigation/dsl.rb', line 22

def group(name, options = {}, &block)
  unless node = current_node
    raise 'group must be in a part' unless node.type == :part
  end
  unless child = node.index[name]
    child = Node.new(:group, name, options)
    node.add_child child
  end
  yield_in_node(child, &block)
end

#item(name, options = {}, &block) ⇒ Object


33
34
35
36
37
38
39
40
41
42
# File 'lib/ekylibre/navigation/dsl.rb', line 33

def item(name, options = {}, &block)
  unless node = current_node
    raise 'item must be in a group' unless node.type == :group
  end
  unless child = node.index[name]
    child = Node.new(:item, name, options)
    node.add_child child
  end
  yield_in_node(child, &block)
end

#page(to, options = {}, &_block) ⇒ Object


44
45
46
47
# File 'lib/ekylibre/navigation/dsl.rb', line 44

def page(to, options = {}, &_block)
  raise 'No part/group/item given' unless current_node
  current_node.add_page(to, options)
end

#part(name, options = {}, &block) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/ekylibre/navigation/dsl.rb', line 14

def part(name, options = {}, &block)
  unless child = @tree[name]
    child = Node.new(:part, name, options)
    @tree.add_child child
  end
  yield_in_node(child, &block)
end