class Hyde::Page
Attributes
name[RW]
original[RW]
Public Class Methods
new(location, destination)
click to toggle source
# File lib/hyde/page.rb, line 6 def initialize(location, destination) @original = File.absolute_path(location) @dest_dir = destination @name = File.basename(location) end
Public Instance Methods
data()
click to toggle source
# File lib/hyde/page.rb, line 13 def data read_yaml(original) end
dest_dir()
click to toggle source
# File lib/hyde/page.rb, line 32 def dest_dir @dest_dir end
dest_filename()
click to toggle source
# File lib/hyde/page.rb, line 28 def dest_filename name end
destination()
click to toggle source
# File lib/hyde/page.rb, line 36 def destination File.join(dest_dir, dest_filename) end
time()
click to toggle source
# File lib/hyde/page.rb, line 17 def time data = self.data if data['hyde_date'] Time.parse(data['hyde_date']) elsif data['date'] Time.parse(data['date']) else File.mtime(original) end end
write()
click to toggle source
# File lib/hyde/page.rb, line 40 def write FileUtils.cp(original, destination) end
Private Instance Methods
read_yaml(file)
click to toggle source
Read the YAML frontmatter.
base - The String path to the dir containing the file. name - The String filename of the file. opts - optional parameter to File.read, default at site configs
Returns nothing.
# File lib/hyde/page.rb, line 53 def read_yaml(file) data = nil begin content = File.read_with_options(file, {}) if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m data = YAML.safe_load($1) end rescue SyntaxError => e puts "YAML Exception reading #{File.join(base, name)}: #{e.message}" rescue Exception => e puts "Error reading file #{File.join(base, name)}: #{e.message}" end data ||= {} end