lib/shinmun/blog.rb in georgi-shinmun-0.3.9 vs lib/shinmun/blog.rb in georgi-shinmun-0.3.10

- old
+ new

@@ -4,13 +4,13 @@ EXAMPLE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../example') include Helpers - attr_reader :aggregations, :categories, :comments, :repo + attr_reader :aggregations, :categories, :comments, :repo, :store - %w[ assets comments config posts pages ].each do |name| + %w[ assets comments config posts pages templates ].each do |name| define_method(name) { store.root.tree(name) } end %w[ title description language author url base_path categories ].each do |name| define_method(name) { config['blog.yml'][name] } @@ -20,10 +20,18 @@ def initialize(path) super @aggregations = {} + if ENV['RACK_ENV'] == 'production' + @store = GitStore.new(path) + else + @store = GitStore::FileStore.new(path) + end + + @store.load + @repo = Grit::Repo.new(path) if defined?(Grit) Thread.start do loop do load_aggregations @@ -39,10 +47,23 @@ `git init` `git add .` `git commit -m 'init'` end + def load_template(file) + templates[file] or raise "template #{file} not found" + end + + def render(name, vars = {}) + super(name, vars.merge(:blog => self)) + end + + def call(env) + store.refresh! + super + end + def load_aggregations config['aggregations.yml'].to_a.each do |c| aggregations[c['name']] = Object.const_get(c['class']).new(c['url']) end end @@ -141,18 +162,9 @@ file = "public/#{base_path}/#{file}" FileUtils.mkdir_p(File.dirname(file)) open(file, 'wb') do |io| io << render(template, vars) end - end - - def render(name, vars = {}) - super(name, vars.merge(:blog => self)) - end - - def call(env) - templates['helpers.rb'] - super end end end