Class: Super::Navigation::Builder

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

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



81
82
83
84
# File 'lib/super/navigation.rb', line 81

def initialize
  @links = []
  @menu_level = 0
end

Instance Method Details

#allObject



128
129
130
131
# File 'lib/super/navigation.rb', line 128

def all
  @links.push(ALL)
  self
end

#buildObject



86
87
88
# File 'lib/super/navigation.rb', line 86

def build
  @links
end


90
91
92
93
94
95
96
# File 'lib/super/navigation.rb', line 90

def link(model, **kwargs)
  text = model.model_name.human.pluralize
  parts = Super::Link.polymorphic_parts(model)

  @links.push(Super::Link.new(text, parts, **kwargs))
  self
end


98
99
100
101
# File 'lib/super/navigation.rb', line 98

def link_to(*args, **kwargs)
  @links.push(Super::Link.new(*args, **kwargs))
  self
end


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/super/navigation.rb', line 103

def menu(title)
  if @menu_level > 0
    raise Super::Error::ArgumentError, "Navigation menus can't be nested"
  end

  begin
    @menu_level += 1
    original_links = @links
    @links = []
    yield
    menu_links = @links
  ensure
    @links = original_links
    @menu_level -= 1
  end

  @links.push(Menu.new(title, menu_links))
  self
end

#restObject



123
124
125
126
# File 'lib/super/navigation.rb', line 123

def rest
  @links.push(REST)
  self
end