Class: Hyphae::SitePage

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

Overview

A SitePage represents a markdown document

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) ⇒ 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, options={})
  nav = root.menu_items(@path, options)
  page_html = template.gsub('{{navbar}}', nav).gsub("{{content}}", @html).gsub('{{index_class}}', '')
  page_dir_path = "#{build_dir}/#{@parent.path.join('/')}"
  file_ext = options[:no_file_ext] ? '' : '.html'
  FileUtils.mkdir_p page_dir_path
  File.open("#{page_dir_path}/#{@slug}#{file_ext}", 'w') { |f| f << page_html }
end

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=[], options={})
  return "" if @hidden
  file_ext = options[: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