Module: Mariner::Helper
- Defined in:
- lib/mariner/helper.rb
Overview
Public: Gets included in controllers (see the Railtie)
Instance Method Summary collapse
-
#render_navigation(config_path = nil, renderer = nil) ⇒ Object
Public: A shortcut for rendering navigation.
-
#render_navigations(*args) ⇒ Object
Public: For when you want to render multiple specific nav trees.
-
#render_sub_navigations(config_path = nil, renderer = nil) ⇒ Object
Public: For when you want to render all the configurations under a given group but you don’t want to render the group itself.
Instance Method Details
#render_navigation(config_path = nil, renderer = nil) ⇒ Object
Public: A shortcut for rendering navigation. Made available to both controllers and views.
config_path - A symbol or slash-separated string path to the configuration group you want to render.
renderer - The rendering strategy to use. Can be a symbol or actual rendering stragey. When a symbol, looks in the ‘Mariner.rendering_strategies` hash using the given symbol as the key. Raises an error if not found. When a rendering strategy, passes the strategy on to the target group’s #render method.
Examples:
Mariner.configure do
a_group do
root_path "Home"
a_sub_group do
users_path "Manage Users"
end
end
end
#=> renders the entire nav tree
:a_group
#=> renders the `a_group` nav tree
"a_group/a_sub_group"
#=> renders the nav tree of `a_sub_group` under `a_group`
:a_group, FakeRenderingStrategy.new
#=> renders `a_group` with a FakeRenderingStrategy instance
:a_group, :other_strategy
#=> renders `a_group` with Mariner.rendering_strategies[:other_strategy]
49 50 51 52 53 54 |
# File 'lib/mariner/helper.rb', line 49 def (config_path=nil, renderer=nil) target = target_from_path(config_path) strategy = rendering_strategy_from(renderer) strategy ? target.render(strategy) : target.render end |
#render_navigations(*args) ⇒ Object
Public: For when you want to render multiple specific nav trees
*args - A comma separated list of groups to render. The last argument may be an options hash. Options:
-
:rendering_strategy - A symbol, class, or object to use for rendering.
See #render_navigation for details.
Examples:
Mariner.configure do
group_a do
root_path "Home"
sub_group do
products_path "Products"
end
end
group_b do
users_path "Manage Users"
end
end
'group_a/sub_group', :group_b
:group_a, :group_b, :rendering_strategy => :different_strategy
111 112 113 114 |
# File 'lib/mariner/helper.rb', line 111 def (*args) renderer = args.[:rendering_strategy] args.map { |target_path| (*[target_path, renderer].compact) }.join end |
#render_sub_navigations(config_path = nil, renderer = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/mariner/helper.rb', line 74 def (config_path=nil, renderer=nil) target = target_from_path(config_path) strategy = rendering_strategy_from(renderer) target.configurations.map do |c| _, entity = c strategy ? entity.render(strategy) : entity.render end.join end |