Created
February 7, 2010 22:55
-
-
Save ethnt/297743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
### | |
# Marvin | |
# A ridiculously-simple blogging platform. | |
# by Ethan Turkeltaub [http://ethan.luffle.com] | |
# Revision 0.1 alpha beta | |
# | |
# marvin.rb | |
### | |
### Dependencies | |
require 'rubygems' | |
require 'sinatra' | |
require 'ostruct' | |
require 'datamapper' | |
require 'haml' | |
### Configuration | |
CONFIG = YAML::load(File.read('configuration.yml')) | |
NAME = CONFIG['configuration']['name'] | |
DESC = CONFIG['configuration']['description'] | |
USER = CONFIG['configuration']['username'] | |
PASS = CONFIG['configuration']['password'] | |
THEME = CONFIG['configuration']['theme'] | |
configure do | |
Site = OpenStruct.new( | |
:name => NAME, | |
:description => DESC, | |
:theme => THEME | |
) | |
end | |
### Models | |
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/marvin.db") | |
class Post | |
include DataMapper::Resource | |
property :id, Serial | |
property :title, String | |
property :body, Text | |
property :created_at, DateTime | |
property :slug, String | |
end | |
class Page | |
include DataMapper::Resource | |
property :id, Serial | |
property :title, String | |
property :body, Text | |
property :slug, String | |
end | |
class Comment | |
include DataMapper::Resource | |
property :id, Serial | |
property :attributed_to, Integer | |
property :name, String | |
property :email, String | |
property :url, String | |
property :body, Text | |
end | |
DataMapper.auto_upgrade! | |
### Controllers | |
get '/' do | |
@testpost = Post.new(:title => 'Lorem ipsum.', :body => 'Lorem ipsum dolor sit amet.', :created_at => '#{Time.now}', :slug => 'lorem-ipsum') | |
@testpost.save | |
@posts = Post.get(:order => [ :id.desc ]) | |
if @posts | |
haml :"themes/#{Site.theme}/index" | |
else | |
haml :"themes/#{Site.theme}/errors/204" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment