Module: NavigationTags
- Includes:
- ActionView::Helpers::TagHelper, Radiant::Taggable
- Defined in:
- lib/navigation_tags.rb
Defined Under Namespace
Classes: NavTagError
Instance Method Summary collapse
- #external_link(link, label) ⇒ Object
- #label_for_page(page) ⇒ Object
- #li_attrs_for_current_page_vs_navigation_item(current_page, child_page) ⇒ Object
- #li_attrs_for_external_link(link, label) ⇒ Object
- #li_for_current_page_vs_navigation_item(current_page, child_page) ⇒ Object
- #li_for_external_link(link) ⇒ Object
- #link_for_page(page) ⇒ Object
Instance Method Details
#external_link(link, label) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/navigation_tags.rb', line 153 def external_link link, label if @ids_for_links "<a href=\"#{link}\" id=\"link_#{ label.slugify }\">#{label}</a>" else "<a href=\"#{link}\">#{label}</a>" end end |
#label_for_page(page) ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/navigation_tags.rb', line 169 def label_for_page page # labels="/:Home,/portfolio:Our work" if @labels && matched_label = @labels.split(',').select{|l| l.split(':').first == page.path}.first.try(:split, ':').try(:last) escape_once(matched_label) else escape_once(page.) end end |
#li_attrs_for_current_page_vs_navigation_item(current_page, child_page) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/navigation_tags.rb', line 114 def current_page, child_page classes = [] classes << "current" if current_page == child_page classes << "has_children" if child_page.children.size > 0 classes << "parent_of_current" if !child_page.parent.nil? and current_page.url.starts_with?(child_page.url) and current_page != child_page (classes << "first" && @first_set = true) unless @first_set result = "" if classes.any? result = " class=\"#{classes.compact.join(" ")}\"" end if @ids_for_lis result << " id=\"nav_" + child_page.slug + "\"" end result end |
#li_attrs_for_external_link(link, label) ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/navigation_tags.rb', line 135 def li_attrs_for_external_link link, label classes = ["external"] (classes << "first" && @first_set = true) unless @first_set result = " class=\"#{classes.compact.join(" ")}\"" if @ids_for_lis result << " id=\"nav_" + label.slugify + "\"" end end |
#li_for_current_page_vs_navigation_item(current_page, child_page) ⇒ Object
131 132 133 |
# File 'lib/navigation_tags.rb', line 131 def current_page, child_page "<li#{(current_page, child_page)}>#{link_for_page(child_page)}</li>" end |
#li_for_external_link(link) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/navigation_tags.rb', line 144 def li_for_external_link link if @labels && matched_label = @labels.split(',').map{|l| l[0..6] == 'http://' ? l[7..-1] : l }.select{|l| l.split(':').first == link}.first.try(:split, ':').try(:last) else matched_label = link[0..6] == 'http://' ? link[7..-1] : link end "<li#{li_attrs_for_external_link(link, matched_label)}>#{external_link(link, matched_label)}</li>" end |
#link_for_page(page) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/navigation_tags.rb', line 161 def link_for_page page if @ids_for_links "<a href=\"#{page.path}\" id=\"#{("link_" + (page.slug == "/" ? 'home' : page.slug))}\">#{label_for_page(page)}</a>" else "<a href=\"#{page.path}\">#{label_for_page(page)}</a>" end end |