require 'tangerine' require 'nukumi2/rewritelinks' class Tangerine def content_type @taglib.resolve("content-type").strip end end module Nukumi2 class Page def initialize(view, flavor) @view = view @path = view.path @entries = view.entries @flavor = flavor end attr_reader :entries attr_reader :path attr_reader :flavor attr_reader :view inject :engine inject :blog def content_type # 'text/html; charset=utf-8' engine(flavor).content_type rescue 'text/plain' end def render engine(flavor).expand(self) end # DONT TOUCH THIS. BRITTLE. def to_root if path.count('/') < 2 '.' else (['..'] * (path.count('/') - 1)).join('/') end end def title blog.topictree.name(path) || path end def breadcumbs a = [] path.split('/').each { |e| a << a.last.to_s + e + '/' } a = ["/"] if a.empty? r = a.map { |path| title = (blog.topictree.name(path) rescue path) || path.split('/').last linkpath = path.gsub(/\/$/, '') Struct.new(:link, :title, :to_root, :page).new( linkpath, title, to_root, path) } r end def topictree topics '/' end def topics(root, depth=1) return "" if blog.topictree.subtopics(root).empty? output = " 2 ? " class='compact'" : ''}>\n" blog.topictree.subtopics(root).sort_by { |t| (blog.topictree.name(File.join(root, t)) || t) rescue t }.each { |s| sub = (root + '/' + s).squeeze('/') output << "
" output << (blog.topictree.name(sub + "/") || s) output << "" output << "
" unless blog.hidden.any? { |t| sub =~ Topical::TopicTree.path2regexp(t) } output << "
" << topics(sub, depth+1) << "
" end } output << "\n" output end def last_change unless view.entries.empty? view.entries.map { |e| e.change_time }.max else # XXX Empty page? if view.respond_to? :subtopics view.subtopics.map { |topic, name| blog.topictree[topic] }.flatten.map { |e| e.change_time }.max || Time.now else Time.now end end end def version Nukumi2::VERSION end end class FlavorTagLib def initialize(flavor) @flavor = flavor end def roots ["templates", File.join($NUKUMI2_ROOT, "data", "nukumi2", "templates"), File.join($NUKUMI2_ROOT, "share", "nukumi2", "templates")] end def resolve(tag) roots.each { |root| if File.readable? File.join(root, @flavor, tag) return File.read(File.join(root, @flavor, tag)) end } raise Blog::NotFound.new("Unknown flavor #{@flavor.inspect}") end end end