Module: Fluffery::Helpers::Navigation
- Defined in:
- lib/fluffery/helpers/navigation.rb
Instance Method Summary collapse
-
#nav_link_to(txt, path, attrs = {}, wrapper = :li) ⇒ Object
Creates a navigation link (by default a list item) that has the class ‘on’ if we are on that particular page or a page beneath it.
-
#navigation(txt, path, attrs = {}, options = {}, &block) ⇒ Object
Creates a nested navigation block, generally used for lists/nested lists.
Instance Method Details
#nav_link_to(txt, path, attrs = {}, wrapper = :li) ⇒ Object
Creates a navigation link (by default a list item) that has the class ‘on’ if we are on that particular page or a page beneath it. Example: nav_link_to(‘Blog’, ‘blog’) will have the class of ‘on’ should we be on /blog or /blog/some_path
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fluffery/helpers/navigation.rb', line 9 def nav_link_to(txt, path, attrs = {}, wrapper = :li) path_validation = false path_validation = attrs.has_key?(:proc) ? attrs[:proc].call(path) : (request.path == path || request.path.match(/#{path}\/.*/i)) path_validation = request.path.match(/#{attrs[:matcher].gsub("_path", path)}/i) if attrs.has_key?(:matcher) attrs.delete(:proc) attrs.delete(:matcher) wrapper_attrs = attrs.delete(:wrapper) attrs, wrapper_attrs = merge_html_classes(attrs, path_validation), merge_html_classes(wrapper_attrs, path_validation) return_val = link_to_unless(path_validation, txt, path, attrs) do link_to(txt, path, attrs) end (wrapper.eql? false) ? return_val : content_tag(wrapper, return_val, wrapper_attrs) end |
#navigation(txt, path, attrs = {}, options = {}, &block) ⇒ Object
Creates a nested navigation block, generally used for lists/nested lists.
29 30 31 32 33 34 35 |
# File 'lib/fluffery/helpers/navigation.rb', line 29 def (txt, path, attrs = {}, = {}, &block) .reverse_merge!(:container => :ol, :wrapper => :li) = content_tag([:container], capture(&block)) wrapper_attrs = attrs.delete(:wrapper) parent_link = nav_link_to(txt, path, attrs, false) content_tag([:wrapper], "#{parent_link}\n#{}".html_safe, (wrapper_attrs || {})) end |