Class: Middleman::Navigation::Tree
- Inherits:
-
Object
- Object
- Middleman::Navigation::Tree
- Defined in:
- lib/middleman-navigation/tree.rb
Class Method Summary collapse
- .add_navigation_node(node, level) ⇒ Object
- .build(sitemap) ⇒ Object
- .traverse(resource, navigation) ⇒ Object
- .visible_children(resource) ⇒ Object
- .with_defaults(navigation) ⇒ Object
Class Method Details
.add_navigation_node(node, level) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/middleman-navigation/tree.rb', line 41 def self.(node, level) = with_defaults(node.data.) title = [:title] || node.data.title url = [:destination] || node.url unless [:hidden] level.item node.destination_path, title, url, :highlights_on => %r(^#{url}(#{@app.index_file})?$) do || yield() if block_given? end end end |
.build(sitemap) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/middleman-navigation/tree.rb', line 4 def self.build(sitemap) @app = sitemap.app @root = sitemap.find_resource_by_destination_path @app.http_prefix+@app.index_file unless @root.blank? SimpleNavigation::Configuration.run do || .items do |level| traverse(@root, level) end end end end |
.traverse(resource, navigation) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/middleman-navigation/tree.rb', line 22 def self.traverse(resource, ) if resource == @root resource, end visible_children(resource).each do |child| child, do || traverse child, end end end |
.visible_children(resource) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/middleman-navigation/tree.rb', line 34 def self.visible_children(resource) visible = resource.children visible.select!{|child| !with_defaults(child.data.)[:hidden]} visible.sort! {|a, b| with_defaults(a.data.)[:weight] <=> with_defaults(b.data.)[:weight]} visible end |
.with_defaults(navigation) ⇒ Object
17 18 19 20 |
# File 'lib/middleman-navigation/tree.rb', line 17 def self.with_defaults() = {} if .blank? Middleman::Navigation::FRONTMATTER_DEFAULTS.merge end |