require 'rubygems' require 'sinatra/base' require 'haml' require 'yaml' module Rblosxom # Version number. module Version unless defined? MAJOR STRING = Gem::Specification.load(File.expand_path("../../rblosxom.gemspec", File.dirname(__FILE__))).version.to_s MAJOR, MINOR, PATCH = STRING.split(".").map { |i| i.to_i } end end module Helpers def set_common_variables require 'ftools' require 'logger' @config = options.config @log = Proc.new { if options.log_file begin unless File.exist?(options.log_file) File.makedirs(File.dirname(options.log_file)) File.new(options.log_file, "w") end log = File.writable?(options.log_file) ? Logger.new(options.log_file) : Logger.new(STDOUT) rescue log = Logger.new(STDOUT) end else log = Logger.new(STDOUT) end log.progname = "#{::Rblosxom.name}" log.level = Logger::INFO log.datetime_format = "%Y-%m-%d %H:%M:%S %Z " log }.call require 'date' @footer = { :year => %/#{DateTime.now.year}/, :copyright => %/#{options.config["copyright"]}/, :generator => %/rblosxom #{::Rblosxom::Version::STRING}/ } end # all category list def category_list list = [] Dir["#{options.config["datadir"]}/**/*"].each do |path| list.push([path, Dir["#{path}/*.#{options.config["file_extension"]}"].length]) if File.directory? path end list end # this year archive list def archive_list list = [] now = DateTime.now this_year = now.year this_month = now.month 1.upto(now.month) { |m| list.push(DateTime.new(this_year, m)) } list end end class Base < Sinatra::Base include Helpers unless defined? CONFIG CONFIG = YAML.load(<<-END) title: Rblosxom slogan: a blosxom program. keywords: ruby, blosxom. description: Rblosxom is a blosxom program. language: en datadir: /data url: http://rblosxom.heroku.com/ depth: 0 num_entries: 40 file_extension: mkd default_flavour: html show_future_entries: 0 theme: default copyright: Rblosxom END end class << self attr_accessor :config_file attr_accessor :log_file attr_reader :config end set :config, Proc.new { config_file ? YAML::load(File.read(config_file)) : CONFIG } set :root, File.expand_path("../../", File.dirname(__FILE__)) set :static, true enable :sessions end end # vim: ft=ruby:fenc=utf-8:sw=4:ts=4:sts=4:et: # base.rb end here