read layout files into hash

This commit is contained in:
Tom Preston-Werner 2008-10-19 19:35:43 -07:00
parent d189e05d23
commit 7dfe32a597
4 changed files with 64 additions and 9 deletions

View File

@ -1,12 +1,12 @@
# -*- ruby -*-
require 'rubygems'
require 'hoe'
require './lib/autoblog.rb'
Hoe.new('autoblog', Autoblog::VERSION) do |p|
# p.rubyforge_name = 'autoblogx' # if different than lowercase project name
# p.developer('FIX', 'FIX@example.com')
end
# Hoe.new('autoblog', Autoblog::VERSION) do |p|
# # p.rubyforge_name = 'autoblogx' # if different than lowercase project name
# # p.developer('FIX', 'FIX@example.com')
# end
# vim: syntax=Ruby
desc "Open an irb session preloaded with this library"
task :console do
sh "irb -rubygems -r ./lib/autoblog.rb"
end

View File

@ -1,3 +1,21 @@
class Autoblog
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
# rubygems
require 'rubygems'
# core
require 'fileutils'
# stdlib
# internal requires
require 'autoblog/site'
require 'autoblog/post'
module AutoBlog
VERSION = '1.0.0'
def self.process(repo_path)
AutoBlog::Site.new(repo_path)
end
end

5
lib/autoblog/post.rb Normal file
View File

@ -0,0 +1,5 @@
module AutoBlog
class Post
end
end

32
lib/autoblog/site.rb Normal file
View File

@ -0,0 +1,32 @@
module AutoBlog
class Site
attr_accessor :root, :layouts
def initialize(root)
self.root = root
self.layouts = {}
self.read_layouts
end
def read_layouts
base = File.join(self.root, "_layouts")
dir = Dir.new(base)
dir.each do |f|
unless %w{. ..}.include?(f)
name = f.split(".")[0..-2].join(".")
self.layouts[name] = File.read(File.join(base, f))
end
end
rescue Errno::ENOENT => e
# ignore missing layout dir
end
def process
end
end
end