# code: # * George Moschovitis # # (c) 2004 Navel, all rights reserved. # $Id: blog.rb 185 2004-12-10 13:29:09Z gmosx $ require 'nitro/service' require 'nitro/builders/rss' require 'nitro/ui/pager' $blog_username = 'George Moschovitis' $blog_password = 'mypassword' module N # = Common # # Common properties/methods for the other classes. # class Common prop :create_time, Time prop_accessor :author, String prop_accessor :body, String, :form => :textarea def initialize @create_time = Time.now end end class Comment < Common; end # = BlogEntry # class BlogEntry < Common prop_accessor :title, String has_many :comments, N::Comment, :linkback => 'entry_oid' # Play a bit with the text the user enters. # def body=(str) if str str.gsub!(//, '>') str.gsub!(/"/, '"') str.gsub!(/'/, ''') str.gsub!(/\r\n/, '
') @body = str end end end # = Comment # class Comment < Common belongs_to :entry, N::BlogEntry end # = BlogService # class BlogService < N::Service SOURCE_FILE = __FILE__ before_filter :audit after_filter :cache scaffold N::BlogEntry, :name => 'entry', :index => true scaffold N::Comment def list_entry @pager = N::UI::Pager.new('entries', @request, 3) @entries = N::BlogEntry.all("ORDER BY oid DESC #{@pager.sql_limit}") @pager.set(N::BlogEntry.count) end def new_entry entry = request.fill(N::BlogEntry.new) entry.author = session['username'] entry.save! end # example of generated view def list_entry__xml @out << N::RssBuilder.render(@entries) end def new_comment comment = request.fill(N::Comment.new) comment.save! end # example of generated view def list_comment__xml @out << N::RssBuilder.render(@comments) end def login if password = params['password'] if password == $blog_password session['owner'] = true session['username'] = $blog_username redirect '/' else @error = 'Invalid password' end end end def logout session['owner'] = session['username'] = nil end private def audit puts "audit (before filter example)" end def cache puts "cache (after filter example)" end end end # module