# coding: utf-8 require 'erb' require 'set' require 'category' require 'sitegen' class Page # Page is an abstract class. # # Implementors must implement several methods: # # def url => URI # def atom_title => String # def atom_author => Person # def atom_content => html | nil # def atom_rights => html | nil # # def page_categories => String | Enumerable # # def page_published => Time | nil # def page_updated => Time | nil # def page_years => Enumerable def initialize Sitegen::add(self) end def atom_categories # => Enumerable if @categories.nil? raw = page_categories if raw.is_a?(String) raw = raw.split end @categories = raw.map{|abbr|Category.new(abbr)} end @categories end def atom_published # => Time | nil if @published.nil? unless page_published.nil? @published = page_published else unless page_updated.nil? @published = page_updated end end # sanity check unless page_published.nil? or page_updated.nil? if page_updated < page_published @published = page_updated end end end @published end def atom_updated # => Time | nil if @updated.nil? unless page_updated.nil? @updated = page_updated else unless page_published.nil? @updated = page_published end end end @updated end def years # => Enumerable if @years.nil? if atom_published.nil? || atom_updated.nil? @years = Set[] else first = atom_published.year last = atom_updated.year years = page_years years.add(first) years.add(last) @years = Set[*years.select{|i|i >= first && i <= last}] end end @years end def index_class return '' end def index_link(cururl, depth) # FIXME: This code is super gross. ret = " * #{atom_title}" atom_categories.each do |t| ret += t.html end ret += "\n" end end ERB::new(File::read("tmpl/page.atom.erb")).def_method(Page, 'atom()', "tmpl/page.atom.erb") ERB::new(File::read("tmpl/page.html.erb")).def_method(Page, 'html()', "tmpl/page.html.erb")