Module: Represent::NavigationHelper
- Defined in:
- lib/represent/navigation_helper.rb
Instance Method Summary collapse
- #breadcrumb(current_url, options, &block) ⇒ Object
- #breadcrumb_for(item, options = {}, &block) ⇒ Object
- #menu_for(item, options = {}, &block) ⇒ Object
-
#menu_tag(array, options = {}, &block) ⇒ Object
-
menu_tag(c(:menu)) do |attributes, node| - attributes = “one two” - node.
-
Instance Method Details
#breadcrumb(current_url, options, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/represent/navigation_helper.rb', line 50 def (current_url, , &block) item = site.find_by_url(current_url) return "" unless item haml_tag :a, .merge(:href => current_url) do if block_given? yield item else haml_concat item.title end end if [:to] != current_url haml_concat [:delimiter] || " » " next_node = [:to].gsub(/#{current_url}\/?/, "").split("/").first ("#{current_url}/#{next_node}", , &block) end end |
#breadcrumb_for(item, options = {}, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/represent/navigation_helper.rb', line 44 def (item, = {}, &block) [:from] ||= "/" + item.url.gsub(/^\//, "").split("/").first [:to] ||= item.url ([:from], , &block) end |
#menu_for(item, options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/represent/navigation_helper.rb', line 4 def (item, = {}, &block) if item.respond_to?(:children) && !item.children.blank? (item.children, , &block) else (item, , &block) end end |
#menu_tag(array, options = {}, &block) ⇒ Object
-
menu_tag(c(:menu)) do |attributes, node|
- attributes = “one two” - node
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/represent/navigation_helper.rb', line 15 def (array, = {}, &block) return "" if array.empty? = nil if .has_key?(:menu_attributes) = [:menu_attributes] .delete(:menu_attributes) end haml_tag :ul, do array.each_with_index do |node, i| attributes = .has_key?(:li_attributes) ? [:li_attributes] : {} attributes[:class] ||= "" if i == 0 and .has_key?(:first) attributes[:class] << " #{[:first]}" elsif i == array.length - 1 and .has_key?(:last) attributes[:class] << " #{[:last]}" end haml_tag :li, attributes do if block_given? yield node else haml_concat node.title end next unless (node.respond_to?(:children)) (node.children, , &block) end end end end |