Class: Blogeen::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/blogeen/page.rb

Overview

A single Blogeen page - handles the text, YAML and HTML content

Instance Method Summary collapse

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, options = {})
  @heading = options[:heading]
  @subheading = options[:subheading]
  @textfile = textfile
  @basename = File.basename(textfile, '.txt')
  @yamlfile = "#{@basename}.yml"
  @htmlfile = File.join(output_directory, "#{@basename}.html")
end

Instance Method Details

#dataObject

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

#htmlObject

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

#htmlfileObject

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

Returns:

  • (Boolean)


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

#publishObject

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

#templateObject

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

#textfileObject

Where the text comes from



64
65
66
# File 'lib/blogeen/page.rb', line 64

def textfile
  @textfile
end

#yamlfileObject

Where the YAML is written and edited



59
60
61
# File 'lib/blogeen/page.rb', line 59

def yamlfile
  @yamlfile
end