lib/spandex/page.rb in spandex-0.0.5 vs lib/spandex/page.rb in spandex-0.0.6

- old
+ new

@@ -1,6 +1,7 @@ require 'time' +require 'date' require 'pathname' require 'tilt' require 'atom' module Spandex @@ -15,42 +16,47 @@ metadata, content = parse_file(filename) Page.new(path, content, pathname.extname, metadata, render_options) end - def self.file_from_path(path, base_path) - path = fix_path path - paths = Pathname.glob(File.join(base_path, "#{path}.*")) - pathname = paths.select{|path| registered?(path)}.first - end - def self.path_from_file(pathname, base_path) pathname = pathify pathname pathify pathname.relative_path_from(pathify(base_path)).sub_ext('') end def self.registered?(pathname) pathname = pathify(pathname) Tilt.registered?(pathname.extname.sub(/^./, '')) end + def metadata(*keys) + keys.each do |key| + key = key.to_s + return @metadata[key] if @metadata.has_key? key + end + nil + end def title - metadata("title") || "(Unknown Title)" + metadata(:title) || "(Unknown Title)" end def date - @date ||= metadata("date") ? DateTime.parse(metadata("date")) : nil + @date ||= metadata(:date) ? DateTime.parse(metadata(:date)) : nil end def body @rendered_body ||= Tilt[@extension].new(nil, 1, @render_options){@content}.render end def tags - @tags ||= metadata("tags", "categories") ? metadata("tags", "categories").split(",").map{|tag| tag.strip} : [] + @tags ||= metadata(:tags, :categories) ? metadata(:tags, :categories).split(",").map{|tag| tag.strip} : [] end + + def draft? + metadata(:draft) ? true : false + end def to_atom_entry(root) unless date raise "Must have a date" end @@ -71,16 +77,9 @@ @content = content @metadata = metadata @extension = extension.sub(/^./, '') @mtime = Time.now @render_options = render_options - end - - def metadata(*keys) - keys.each do |key| - return @metadata[key] if @metadata.has_key? key - end - nil end def self.pathify(path_or_string) fix_path path_or_string.is_a?(String) ? Pathname.new(path_or_string) : path_or_string end