Class: Middleman::Navigation::Tree
- Inherits:
-
Object
- Object
- Middleman::Navigation::Tree
- Defined in:
- lib/middleman-navigation/tree.rb
Class Method Summary collapse
- .build(sitemap) ⇒ Object
- .traverse(resource, navigation) ⇒ Object
- .visible_children(resource) ⇒ Object
Class Method Details
.build(sitemap) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/middleman-navigation/tree.rb', line 4 def self.build(sitemap) @app = sitemap.app root_path = @app.http_prefix + @app.index_file root = sitemap.find_resource_by_destination_path root_path unless root.blank? SimpleNavigation::Configuration.run do || traverse(root, ) end end end |
.traverse(resource, navigation) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/middleman-navigation/tree.rb', line 16 def self.traverse(resource, ) children = visible_children(resource) unless children.blank? .items do |level| children.each do |child| title = child.data.[:title] || child.data.title url = child.data.[:destination] || child.url level.item child.destination_path, title, url, :highlights_on => %r(#{url}(#{@app.index_file})?) traverse child, level end end end end |
.visible_children(resource) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/middleman-navigation/tree.rb', line 32 def self.visible_children(resource) visible = resource.children.select {|child| child.data..present?} visible.select!{|child| !child.data.[:hidden]} visible.sort! {|a, b| a.data.[:weight] <=> b.data.[:weight]} visible end |