Class: Blogeen::Page
- Inherits:
-
Object
- Object
- Blogeen::Page
- Defined in:
- lib/blogeen/page.rb
Overview
A single Blogeen page - handles the text, YAML and HTML content
Instance Method Summary collapse
-
#data ⇒ Object
The intermediate Page’s data, from the YAML file.
-
#html ⇒ Object
The HTML for this Page.
-
#htmlfile ⇒ Object
Where the HTML is written.
-
#initialize(textfile, options = {}) ⇒ Page
constructor
A new instance of Page.
-
#out_of_date? ⇒ Boolean
Determines whether something needs to be done to update any of the Page’s files.
-
#publish ⇒ Object
Writes this Page’s HTML to its HTML file.
-
#template ⇒ Object
The ERB template which is used for the Page’s layout.
-
#textfile ⇒ Object
Where the text comes from.
-
#yamlfile ⇒ Object
Where the YAML is written and edited.
Constructor Details
#initialize(textfile, options = {}) ⇒ Page
Returns a new instance of Page.
9 10 11 12 13 14 15 16 |
# File 'lib/blogeen/page.rb', line 9 def initialize(textfile, = {}) @heading = [:heading] @subheading = [:subheading] @textfile = textfile @basename = File.basename(textfile, '.txt') @yamlfile = "#{@basename}.yml" @htmlfile = File.join(output_directory, "#{@basename}.html") end |
Instance Method Details
#data ⇒ Object
The intermediate Page’s data, from the YAML file
49 50 51 |
# File 'lib/blogeen/page.rb', line 49 def data @data ||= YAML.load(yaml) end |
#html ⇒ Object
The HTML for this Page
39 40 41 |
# File 'lib/blogeen/page.rb', line 39 def html @html ||= ERB.new(File.read(template)).result(binding) end |
#htmlfile ⇒ Object
Where the HTML is written
54 55 56 |
# File 'lib/blogeen/page.rb', line 54 def htmlfile @htmlfile end |
#out_of_date? ⇒ Boolean
Determines whether something needs to be done to update any of the Page’s files
20 21 22 23 24 25 26 |
# File 'lib/blogeen/page.rb', line 20 def out_of_date? return true unless File.exists?(htmlfile) return true unless File.mtime(htmlfile) > File.mtime(yamlfile) return true unless File.mtime(htmlfile) > File.mtime(template) return true unless File.exists?(yamlfile) return true unless File.mtime(yamlfile) > File.mtime(textfile) end |
#publish ⇒ Object
Writes this Page’s HTML to its HTML file
29 30 31 32 33 34 35 36 |
# File 'lib/blogeen/page.rb', line 29 def publish File.open(@htmlfile, 'w') do |f| f.print(html) end rescue File.unlink(@htmlfile) if File.exists?(@htmlfile) raise $! end |
#template ⇒ Object
The ERB template which is used for the Page’s layout
44 45 46 |
# File 'lib/blogeen/page.rb', line 44 def template "page.html.erb" end |
#textfile ⇒ Object
Where the text comes from
64 65 66 |
# File 'lib/blogeen/page.rb', line 64 def textfile @textfile end |
#yamlfile ⇒ Object
Where the YAML is written and edited
59 60 61 |
# File 'lib/blogeen/page.rb', line 59 def yamlfile @yamlfile end |