Class: Super::Navigation::Builder
- Inherits:
-
Object
- Object
- Super::Navigation::Builder
- Defined in:
- lib/super/navigation.rb
Instance Method Summary collapse
- #all ⇒ Object
- #build ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #link(model, **kwargs) ⇒ Object
- #link_to(*args, **kwargs) ⇒ Object
- #menu(title) ⇒ Object
- #rest ⇒ Object
Constructor Details
#initialize ⇒ Builder
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
#all ⇒ Object
128 129 130 131 |
# File 'lib/super/navigation.rb', line 128 def all @links.push(ALL) self end |
#build ⇒ Object
86 87 88 |
# File 'lib/super/navigation.rb', line 86 def build @links end |
#link(model, **kwargs) ⇒ Object
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 |
#link_to(*args, **kwargs) ⇒ Object
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 |
#menu(title) ⇒ Object
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 (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 = @links ensure @links = original_links @menu_level -= 1 end @links.push(Menu.new(title, )) self end |
#rest ⇒ Object
123 124 125 126 |
# File 'lib/super/navigation.rb', line 123 def rest @links.push(REST) self end |