# # Nukumi2 -- a flexible Ruby blogging system # Copyright (C) 2004, 2005 Christian Neukirchen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Written by Christian Neukirchen . # # Add vendor libraries to load path. $: << File.join(File.dirname(__FILE__), "nukumi2", "vendor") require 'dissident' require 'topical' require 'yaml' require 'ostruct' require 'nukumi2/view' require 'nukumi2/page' require 'nukumi2/filebackend' require 'nukumi2/entry' require 'nukumi2/topictree-extensions' require 'nukumi2/config-parser' require 'nukumi2/plugin' require 'nukumi2/default-registry' module Nukumi2 VERSION = "0.5" class Blog attr_reader :categories attr_reader :hidden inject :all_backends inject :topictree inject :config inject :page inject :registry inject :config inject :topictree inject :default_flavor def initialize end def get_entries @entries = all_backends.map { |b| b.get }.flatten.uniq end def get_config @categories = config.get_topics end def get_categories @publishable = {} @hidden = [] config.get_topics.each { |topic, options| if options.title && topic !~ /\*/ topictree.create(topic, options.title, options.description) end if options.view @publishable[topic] = View.const_get(options.view) end @hidden << topic if options.hidden == true } end def load! get_config get_categories get_entries insert_entries end def reload! topictree.clear! load! end def insert_entries @entries.each { |entry| entry.insert_into_topictree topictree } end def fetch(path) flavor = default_flavor path.gsub!(/\/index\b/, '/') path = path.gsub(/\.(.*?)$/) { flavor = $1; '' } find_view(path).new(registry, path).to_page(flavor) end def find_view(path) path = path + "/" if path[-1] != ?/ best_topic = topictree.find_most_specific path, @publishable.keys raise NotFound unless best_topic @publishable[best_topic] end class NotFound < StandardError; end end end