Class: Hyphae::SiteDir
Overview
A SiteDir represents a directory containing nested SiteNodes
Instance Attribute Summary
Attributes inherited from SiteNode
#date, #name, #order, #parent, #path, #slug
Instance Method Summary collapse
-
#build(build_dir, template, options = {}) ⇒ Object
Recursively builds pages for all children.
-
#build_index(build_dir, template, index_content = '', options = {}) ⇒ Object
Builds an index page for this SiteDir.
-
#initialize(filename, parent = nil) ⇒ SiteDir
constructor
A new instance of SiteDir.
-
#menu_items(open_path = [], options = {}) ⇒ Object
Returns the html for each child’s nav menu link.
-
#nav_link(open_path = [], options = {}) ⇒ Object
Returns the html for this SiteDir’s nav menu link.
Methods inherited from SiteNode
Constructor Details
#initialize(filename, parent = nil) ⇒ SiteDir
Returns a new instance of SiteDir.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/hyphae.rb', line 76 def initialize(filename, parent=nil) super @children = [] Dir.glob(filename + '/*').each do |f| if File.directory? f then @children.push SiteDir.new(f, self) elsif File.extname(f) == '.md' then @children.push SitePage.new(f, self) elsif File.extname(f) == '.link' then @children.push SiteLink.new(f, self) end end @children.sort! { |x, y| x.cmp(y) } return self end |
Instance Method Details
#build(build_dir, template, options = {}) ⇒ Object
Recursively builds pages for all children
108 109 110 |
# File 'lib/hyphae.rb', line 108 def build(build_dir, template, ={}) @children.each { |child| child.build(build_dir, template, ) } end |
#build_index(build_dir, template, index_content = '', options = {}) ⇒ Object
Builds an index page for this SiteDir
113 114 115 116 |
# File 'lib/hyphae.rb', line 113 def build_index(build_dir, template, index_content='', ={}) page_html = template.gsub('{{navbar}}', ([], )).gsub("{{content}}", index_content).gsub('{{index_class}}', ' index_page') File.open("#{build_dir}/index.html", 'w') { |f| f << page_html } end |
#menu_items(open_path = [], options = {}) ⇒ Object
Returns the html for each child’s nav menu link
93 94 95 |
# File 'lib/hyphae.rb', line 93 def (open_path=[], ={}) @children.map { |x| x.nav_link(open_path, ) }.join end |
#nav_link(open_path = [], options = {}) ⇒ Object
Returns the html for this SiteDir’s nav menu link
98 99 100 101 102 103 104 105 |
# File 'lib/hyphae.rb', line 98 def nav_link(open_path=[], ={}) return "" if @hidden link = Hyphae::make_tag('span', @name, {'class' => 'nav_menu_link'}) = { 'class' => 'nav_menu_items' } ['class'] += ' open' if open_path.first == @slug = Hyphae::make_tag('div', (open_path[1..-1] || [], ), ) Hyphae::make_tag('div', link + , {'class' => 'nav_menu'}) end |