Module: Staticpress::Plugins::Menu
- Defined in:
- lib/staticpress/plugins/menu.rb
Defined Under Namespace
Classes: MenuItem
Instance Method Summary collapse
- #convert_to_menu_item(page) ⇒ Object
- #menu(max_depth, menu_items = root_menu_items, menu_options = {}) ⇒ Object
- #menu_depth(position) ⇒ Object
- #menu_pages ⇒ Object
- #root_menu ⇒ Object
- #root_menu_items ⇒ Object
- #sub_menu_for(page) ⇒ Object
Instance Method Details
#convert_to_menu_item(page) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/staticpress/plugins/menu.rb', line 36 def (page) parent_position = page...position.to_s matcher = /^#{parent_position.gsub('.', '\.')}\.(?<sub_position>-?\d{1,})$/ sub_items = .select do |sub_page| matcher.match sub_page...position.to_s end.map do |sub_page| sub_page end MenuItem.new parent_position.split('.').last, page...text || page.title, page.url_path, sub_items end |
#menu(max_depth, menu_items = root_menu_items, menu_options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/staticpress/plugins/menu.rb', line 7 def (max_depth, = , = {}) if (.count > 0) && !max_depth.zero? tag :menu, { :type => :toolbar }.merge() do .sort.map do |item| tag :li do a = tag :a, :href => item.url_path do item.text end remaining_depth = (max_depth < 0) ? max_depth : max_depth - 1 sub = (remaining_depth, item.sub_items, ) || '' a + sub end end.join end end end |
#menu_depth(position) ⇒ Object
47 48 49 |
# File 'lib/staticpress/plugins/menu.rb', line 47 def (position) position.split('.').count - 1 end |
#menu_pages ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/staticpress/plugins/menu.rb', line 28 def @menu_pages ||= lambda do Staticpress::Content::Page.published.reject do |page| page...nil? end end.call end |
#root_menu ⇒ Object
3 4 5 |
# File 'lib/staticpress/plugins/menu.rb', line 3 def 1 end |
#root_menu_items ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/staticpress/plugins/menu.rb', line 51 def .select do |page| (page...position.to_s).zero? end.map do |page| page end end |
#sub_menu_for(page) ⇒ Object
24 25 26 |
# File 'lib/staticpress/plugins/menu.rb', line 24 def (page) (page).sub_items end |