Skip to content

Instantly share code, notes, and snippets.

@jsmestad
Created December 9, 2008 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmestad/33738 to your computer and use it in GitHub Desktop.
Save jsmestad/33738 to your computer and use it in GitHub Desktop.
require "rubygems"
require "sinatra"
require "dm-core"
require "dm-timestamps"
require "dm-aggregates"
require "syntaxi"
require "bb-ruby"
@db_info = {
:host => 'localhost',
:adapter => 'mysql',
:database => 'vbulletin_dev',
:username => 'root',
:password => 'password'
}
DataMapper.setup(:default, @db_info)
class Post
include DataMapper::Resource
storage_names[:default] = 'vb_post'
property :id, Serial, :field => 'postid', :writer => :private
property :parent, Integer, :field => 'parentid', :writer => :private
property :username, String, :writer => :private
property :title, String, :writer => :private
property :content, Text, :field => 'pagetext', :lazy => false, :writer => :private
belongs_to :topic, :child_key => [:threadid]
end
class Topic
include DataMapper::Resource
storage_names[:default] = 'vb_thread'
property :id, Serial, :field => 'threadid', :writer => :private
property :title, String, :writer => :private
property :first_post, Integer, :field => 'firstpostid', :writer => :private
property :forum, Integer, :field => 'forumid', :writer => :private
property :author, String, :field => 'postusername', :writer => :private
property :replies, Integer, :field => 'replycount', :writer => :private
has n, :posts, :child_key => [:threadid]
end
get '/' do
@topics = Topic.all(:limit => 30)
haml :index
end
%h2
News
- @topics.each do |topic|
%table
%tr
%td
= topic.title
%tr
%td= item = topic.posts.first; p item.content
%hr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment