# Ramaise Amrita, the Ramaze version of Reprise, a minimal hAtom blog # with Amrita2 # # http://redflavor.com/reprise.rb # http://www.rubyinside.com/reprise-a-ruby-powered-blogging-app-in- # 100-lines-including-templates-646.html # # Usage: # # 1. gem install ramaze bluecloth rubypants amrita2 -y # 2. mkdir entries # 3. vi entries/YYYY.MM.DD.Title.Goes.Here # 4. ruby ramaise_amrita2.rb %w(rubygems ramaze bluecloth rubypants amrita2).each{|lib| require lib } class BlogPost include Amrita2::DictionaryData DIR = __DIR__/:entries def initialize filename raise 'Invalid BlogPost filename' unless File.exists?(filename) @filename, filename = filename, File.basename(filename) @date = Date.strptime(filename, '%Y.%m.%d').to_s @title = filename[11..-1].tr('.', ' ') end def body RubyPants.new(BlueCloth.new(File.read(@filename)).to_html).to_html end def slug @slug ||= title.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase end attr_reader :date, :title class << self include Enumerable def each Dir[DIR/'*'].sort.reverse.each do |file| yield BlogPost.new(file) end end def [] key BlogPost.find{|post| post.slug == key } end end end class MainController < Ramaze::Controller include Amrita2 TITLE = 'Ramaise with Amrita2 BLOG' AUTHOR = { :name => 'Taku Nakajima', :url => 'http://retro.brain-tokyo.net' } engine :Amrita2 def index slug = nil title = nil if slug.nil? @posts = BlogPost.collect raise Ramaze::Error::NoAction, 'No blog posts found, create entries/YYYY.MM.DD.My.First.Blog.Post' unless @posts.any? else raise Ramaze::Error::NoAction, 'Invalid blog post' unless post = BlogPost[slug] post = BlogPost[slug] title = post.title @posts = [ post ] end title_hook = Amrita2::Core::Hook.new do if title render_child(:post_title, :href=>'/', :text=>title) else render_child(:index_title, :text=>TITLE) end end @data = binding %( <