Class: Dimples::Page
Overview
A single page on a site.
Constant Summary
Constants included from Frontable
Frontable::FRONT_MATTER_PATTERN
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #extension ⇒ Object
- #filename ⇒ Object
-
#initialize(site, path = nil) ⇒ Page
constructor
A new instance of Page.
- #render(context = {}) ⇒ Object
- #write(output_directory, context = {}) ⇒ Object
Methods included from Frontable
Constructor Details
#initialize(site, path = nil) ⇒ Page
Returns a new instance of Page.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dimples/page.rb', line 12 def initialize(site, path = nil) @site = site @path = path if @path @contents, = read_with_front_matter(@path) else @contents = '' = {} end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (private)
56 57 58 59 60 61 62 63 64 |
# File 'lib/dimples/page.rb', line 56 def method_missing(method_name, *args, &block) if .key?(method_name) [method_name] elsif (matches = method_name.match(/([a-z_]+)=/)) [matches[1].to_sym] = args[0] else super end end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
8 9 10 |
# File 'lib/dimples/page.rb', line 8 def contents @contents end |
#metadata ⇒ Object
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/dimples/page.rb', line 9 def end |
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/dimples/page.rb', line 10 def path @path end |
Instance Method Details
#extension ⇒ Object
28 29 30 |
# File 'lib/dimples/page.rb', line 28 def extension [:extension] || 'html' end |
#filename ⇒ Object
24 25 26 |
# File 'lib/dimples/page.rb', line 24 def filename [:filename] || 'index' end |
#render(context = {}) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/dimples/page.rb', line 32 def render(context = {}) = .dup .merge!(context[:page]) if context[:page] context[:page] = Hashie::Mash.new() renderer.render(context) end |
#write(output_directory, context = {}) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dimples/page.rb', line 41 def write(output_directory, context = {}) FileUtils.mkdir_p(output_directory) unless Dir.exist?(output_directory) output_path = File.join(output_directory, "#{filename}.#{extension}") File.write(output_path, render(context)) rescue SystemCallError => e raise PublishingError, "Failed to publish file at #{output_path} (#{e})" end |