From 7dfe32a597758bb485cc0104b01906781740d977 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 19 Oct 2008 19:35:43 -0700 Subject: [PATCH] read layout files into hash --- Rakefile | 16 ++++++++-------- lib/autoblog.rb | 20 +++++++++++++++++++- lib/autoblog/post.rb | 5 +++++ lib/autoblog/site.rb | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 lib/autoblog/post.rb create mode 100644 lib/autoblog/site.rb diff --git a/Rakefile b/Rakefile index c8186c00..eb18931e 100644 --- a/Rakefile +++ b/Rakefile @@ -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 \ No newline at end of file diff --git a/lib/autoblog.rb b/lib/autoblog.rb index 3f35f55e..01ca6193 100644 --- a/lib/autoblog.rb +++ b/lib/autoblog.rb @@ -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 \ No newline at end of file diff --git a/lib/autoblog/post.rb b/lib/autoblog/post.rb new file mode 100644 index 00000000..d6535503 --- /dev/null +++ b/lib/autoblog/post.rb @@ -0,0 +1,5 @@ +module AutoBlog + class Post + + end +end \ No newline at end of file diff --git a/lib/autoblog/site.rb b/lib/autoblog/site.rb new file mode 100644 index 00000000..d719ddea --- /dev/null +++ b/lib/autoblog/site.rb @@ -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 \ No newline at end of file