#!/usr/bin/ruby ENV['GEM_PATH'] = '/home/efarrar/.gems:/usr/lib/ruby/gems/1.8' require 'rubygems' require 'camping' require 'hpricot' require 'open-uri' require 'camping/db' require 'cgi' require '/home/efarrar/mindsplatter.net/cissaby/lib/cissaby.rb' Camping.goes :MindSplatter module MindSplatter::Models class Entry < Base; end class CreateEntries < V 1.0 def self.up create_table :mindsplatter_entries do |t| t.column :id, :integer t.column :text, :text t.column :entry_type, :string t.column :time, :datetime t.column :created_at, :datetime t.column :title, :string end end def self.down drop_table :mindsplatter_entries end end end module MindSplatter::Controllers class Index < R '/' def get if Time.now-Entry.find(:first).created_at < 15*60 @entries = Entry.find(:all) else last_svn = Entry.minimum(:time).strftime('%Y-%m-%d') h = Hpricot(`svn -rHEAD:{#{last_svn}} -v log --xml http://www.ternimal.com/svn/`) svn_commits = (h/:logentry).map do |e| {:text => ((e/:msg).inner_html), :entry_type => "svn commit", :time => Time.parse((e/:date).inner_html), :title => /^\/([^\/]*)\/?/.match((e/:paths/:path).first.inner_html)[1]} end h = Hpricot(open('http://ternimal.com/feed/')) blog_entries = (h/:feed/:entry).map do |e| {:text => CGI.unescapeHTML((e/:content).inner_html), :entry_type => "blog entry", :time => Time.parse((e/:published).inner_html), :title => (e/:title).inner_html} end h = Hpricot(open("http://del.icio.us/rss/evanfarrar")) bookmarks = (h/:item).map do |e| {:text => "\ #{(e/:title).inner_html} #{e/:description}", :entry_type => "link", :time => Time.parse((e/"dc:date").inner_html), :title => (e/"dc:subject").inner_html} end @entries = svn_commits + blog_entries + bookmarks @entries = (@entries.sort_by{|entry| entry[:time]}).reverse Entry.destroy_all @entries = @entries[0..30].map{|e| Entry.create(e)} end render :index end end class Page < R '/(\w+)' def get(page_name) render page_name end end class Static < R '/static/(.+)' MIME_TYPES = {'.png' => 'image/png'} PATH = File.expand_path(File.dirname(__FILE__)) def get(path) @headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || "text/plain" unless path.include? ".." @headers['X-Sendfile'] = "#{PATH}/static/#{path}" else @status = "403" "403 - Invalid path" end end end end module MindSplatter::Views def layout html do head do style(:type => 'text/css') do (Cissaby::Builder.new{ span({:color => "navy"}) div({:padding => "0.5em", :margin => "1em" }) body({ :"font-family" => "Verdana, Arial, Helvetica, sans-serif", :"font-size" => "12pt", :margin => "0 auto", :background => "url('/static/splatter.png') no-repeat fixed 2em -0.5em", :"text-align" => "center" }) wrap!({:width => "40em", :"padding-left" => "5em", :"text-align" => "left"}) body.title({:color => "blue", :float => "right"}) body.msg({:"background-color" => "#8dd3df", :opacity => '.8'}) pre({:overflow => "auto"}) body.meta({:float => "left"}) }).to_s end end title { 'MindSplatter: smear it around' } body { div(:id => "wrap"){ self << yield } } end end def index @entries.each do |msg| div(:class => "msg"){ span(:class => 'meta'){ msg[:entry_type] + " at " + msg[:time].strftime('%H:%M on %D') } span(:class => 'title'){ msg[:title][0..40] } div(:class => 'text'){ msg[:text] } } end end end def MindSplatter.create MindSplatter::Models.create_schema MindSplatter::Models::Entry.create(:time => '2000-01-01',:created_at => Time.now-1000,:entry_type=>'foo',:title=>'bar') end if __FILE__ == $0 MindSplatter::Models::Base.establish_connection :adapter => 'sqlite3', :database => './mindsplatter.db' MindSplatter.create unless MindSplatter::Models::Entry.table_exists? puts MindSplatter.run end