Class: Dimples::Page
- Inherits:
-
Object
- Object
- Dimples::Page
- Includes:
- Frontable, Renderable
- Defined in:
- lib/dimples/page.rb
Overview
A class that models a single site page.
Direct Known Subclasses
Constant Summary
Constants included from Frontable
Frontable::SKIPPED_METADATA_KEYS
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#output_directory ⇒ Object
Returns the value of attribute output_directory.
-
#path ⇒ Object
Returns the value of attribute path.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes included from Renderable
Instance Method Summary collapse
-
#initialize(site, path = nil) ⇒ Page
constructor
A new instance of Page.
- #inspect ⇒ Object
- #output_path ⇒ Object
- #write(context = {}) ⇒ Object
Methods included from Renderable
Methods included from Frontable
Constructor Details
#initialize(site, path = nil) ⇒ Page
Returns a new instance of Page.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dimples/page.rb', line 17 def initialize(site, path = nil) @site = site @extension = 'html' @path = path if @path @filename = File.basename(@path, File.extname(@path)) @output_directory = File.dirname(@path).gsub( @site.source_paths[:pages], @site.output_paths[:site] ) read_with_front_matter else @filename = 'index' @contents = '' @output_directory = @site.output_paths[:site] end end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
14 15 16 |
# File 'lib/dimples/page.rb', line 14 def contents @contents end |
#extension ⇒ Object
Returns the value of attribute extension.
12 13 14 |
# File 'lib/dimples/page.rb', line 12 def extension @extension end |
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/dimples/page.rb', line 11 def filename @filename end |
#layout ⇒ Object
Returns the value of attribute layout.
13 14 15 |
# File 'lib/dimples/page.rb', line 13 def layout @layout end |
#output_directory ⇒ Object
Returns the value of attribute output_directory.
15 16 17 |
# File 'lib/dimples/page.rb', line 15 def output_directory @output_directory end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/dimples/page.rb', line 9 def path @path end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'lib/dimples/page.rb', line 10 def title @title end |
Instance Method Details
#inspect ⇒ Object
52 53 54 |
# File 'lib/dimples/page.rb', line 52 def inspect "#<Dimples::Page @output_path=#{output_path}>" end |
#output_path ⇒ Object
37 38 39 |
# File 'lib/dimples/page.rb', line 37 def output_path File.join(@output_directory, "#{@filename}.#{@extension}") end |
#write(context = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dimples/page.rb', line 41 def write(context = {}) FileUtils.mkdir_p(@output_directory) unless Dir.exist?(@output_directory) File.open(output_path, 'w+') do |file| file.write(context ? render(context) : contents) end rescue SystemCallError => e = "Failed to write #{path} (#{e.})" raise Errors::PublishingError, end |