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.



78
79
80
81
# File 'lib/super/navigation.rb', line 78

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

Instance Method Details

#allObject



125
126
127
128
# File 'lib/super/navigation.rb', line 125

def all
  @links.push(ALL)
  self
end

#buildObject



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

def build
  @links
end


87
88
89
90
91
92
93
# File 'lib/super/navigation.rb', line 87

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


95
96
97
98
# File 'lib/super/navigation.rb', line 95

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


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

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



120
121
122
123
# File 'lib/super/navigation.rb', line 120

def rest
  @links.push(REST)
  self
end