Class: Hyphae::SiteDir

Inherits:
SiteNode show all
Defined in:
lib/hyphae.rb

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

Methods inherited from SiteNode

#cmp, #root

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, options={})
  @children.each { |child| child.build(build_dir, template, options) }
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='', options={})
  page_html = template.gsub('{{navbar}}', menu_items([], options)).gsub("{{content}}", index_content).gsub('{{index_class}}', ' index_page')
  File.open("#{build_dir}/index.html", 'w') { |f| f << page_html }
end

Returns the html for each child’s nav menu link



93
94
95
# File 'lib/hyphae.rb', line 93

def menu_items(open_path=[], options={})
  @children.map { |x| x.nav_link(open_path, options) }.join
end

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=[], options={})
  return "" if @hidden
  link = Hyphae::make_tag('span', @name, {'class' => 'nav_menu_link'})
  menu_attrs = { 'class' => 'nav_menu_items' }
  menu_attrs['class'] += ' open' if open_path.first == @slug
  menu = Hyphae::make_tag('div', menu_items(open_path[1..-1] || [], options), menu_attrs)
  Hyphae::make_tag('div', link + menu, {'class' => 'nav_menu'})
end