Class: Hyphae::SitePage
Overview
A SitePage represents a markdown document
Instance Attribute Summary
Attributes inherited from SiteNode
#date, #name, #order, #parent, #path, #slug
Instance Method Summary collapse
-
#build(build_dir, template, options = {}) ⇒ Object
Builds html page.
-
#initialize(filename, parent) ⇒ SitePage
constructor
A new instance of SitePage.
-
#nav_link(open_path = [], options = {}) ⇒ Object
Builds the nav menu tag for this page.
Methods inherited from SiteNode
Constructor Details
#initialize(filename, parent) ⇒ SitePage
Returns a new instance of SitePage.
122 123 124 125 126 |
# File 'lib/hyphae.rb', line 122 def initialize(filename, parent) super markdown = File.read filename @html = Kramdown::Document.new(markdown).to_html end |
Instance Method Details
#build(build_dir, template, options = {}) ⇒ Object
Builds html page
138 139 140 141 142 143 144 145 |
# File 'lib/hyphae.rb', line 138 def build(build_dir, template, ={}) nav = root.(@path, ) page_html = template.gsub('{{navbar}}', nav).gsub("{{content}}", @html).gsub('{{index_class}}', '') page_dir_path = "#{build_dir}/#{@parent.path.join('/')}" file_ext = [:no_file_ext] ? '' : '.html' FileUtils.mkdir_p page_dir_path File.open("#{page_dir_path}/#{@slug}#{file_ext}", 'w') { |f| f << page_html } end |
#nav_link(open_path = [], options = {}) ⇒ Object
Builds the nav menu tag for this page
129 130 131 132 133 134 135 |
# File 'lib/hyphae.rb', line 129 def nav_link(open_path=[], ={}) return "" if @hidden file_ext = [:no_file_ext] ? '' : '.html' attrs = { 'class' => 'nav_page', 'href' => "/#{@path.join('/')}#{file_ext}" } attrs['class'] += ' current_page' if @slug == open_path.first Hyphae::make_tag('a', @name, attrs) end |