Skip to content

Commit

Permalink
first import
Browse files Browse the repository at this point in the history
  • Loading branch information
shayarnett committed Mar 22, 2008
0 parents commit c537374
Show file tree
Hide file tree
Showing 101 changed files with 2,819 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
schema/schema.rb
log/*
Empty file added README
Empty file.
29 changes: 29 additions & 0 deletions Rakefile
@@ -0,0 +1,29 @@
require 'rubygems'
Gem.clear_paths
Gem.path.unshift(File.join(File.dirname(__FILE__), "gems"))

require 'rake'
require 'rake/rdoctask'
require 'rake/testtask'
require 'spec/rake/spectask'
require 'fileutils'
require 'merb-core'
require 'rubigen'
include FileUtils

# Load the basic runtime dependencies; this will include
# any plugins and therefore plugin rake tasks.
init_env = ENV['MERB_ENV'] || 'rake'
Merb.load_dependencies(:environment => init_env)

# Get Merb plugins and dependencies
Merb::Plugins.rakefiles.each { |r| require r }

desc "start runner environment"
task :merb_env do
Merb.start_environment(:environment => init_env, :adapter => 'runner')
end

##############################################################################
# ADD YOUR CUSTOM TASKS BELOW
##############################################################################
3 changes: 3 additions & 0 deletions app/controllers/application.rb
@@ -0,0 +1,3 @@
require File.join(File.dirname(__FILE__), '..', '..', "lib", "authenticated_system", "authenticated_dependencies")
class Application < Merb::Controller
end
13 changes: 13 additions & 0 deletions app/controllers/exceptions.rb
@@ -0,0 +1,13 @@
class Exceptions < Application

# handle NotFound exceptions (404)
def not_found
render :format => :html
end

# handle NotAcceptable exceptions (406)
def not_acceptable
render :format => :html
end

end
58 changes: 58 additions & 0 deletions app/controllers/forums.rb
@@ -0,0 +1,58 @@
class Forums < Application
# provides :xml, :yaml, :js
before :login_required, :exclude => [:index, :show]

def index
@forums = Forum.find(:all)
display @forums
end

def show
@forum = Forum.find_by_id(params[:id], :include => :topics)
raise NotFound unless @forum
display @forum
end

def new
only_provides :html
@forum = Forum.new(params[:forum])
render
end

def create
@forum = Forum.new(params[:forum])
if @forum.save
redirect url(:forum, @forum)
else
render :new
end
end

def edit
only_provides :html
@forum = Forum.find_by_id(params[:id])
raise NotFound unless @forum
render
end

def update
@forum = Forum.find_by_id(params[:id])
raise NotFound unless @forum
if @forum.update_attributes(params[:forum])
redirect url(:forum, @forum)
else
raise BadRequest
end
end

def destroy
@forum = Forum.find_by_id(params[:id])
raise NotFound unless @forum
if @forum.destroy
redirect url(:forums)
else
raise BadRequest
end
end

end
64 changes: 64 additions & 0 deletions app/controllers/posts.rb
@@ -0,0 +1,64 @@
class Posts < Application
# provides :xml, :yaml, :js
before :login_required, :exclude => [:index, :show]
before :find_forum_and_topic

def find_forum_and_topic
@forum = Forum.find(params[:forum_id])
@topic = Topic.find(params[:topic_id])
end

def index
@posts = Post.find(:all)
display @posts
end

def show
@post = Post.find_by_id(params[:id])
raise NotFound unless @post
display @post
end

def new
only_provides :html
@post = Post.new(params[:post])
render
end

def create
@post = Post.new(params[:post].merge({:user => current_user,:forum => @forum,:topic => @topic}))
if @post.save
redirect url(:forum_topic, @topic)
else
render :new
end
end

def edit
only_provides :html
@post = Post.find_by_id(params[:id])
raise NotFound unless @post
render
end

def update
@post = Post.find_by_id(params[:id])
raise NotFound unless @post
if @post.update_attributes(params[:post])
redirect url(:post, @post)
else
raise BadRequest
end
end

def destroy
@post = Post.find_by_id(params[:id])
raise NotFound unless @post
if @post.destroy
redirect url(:posts)
else
raise BadRequest
end
end

end
29 changes: 29 additions & 0 deletions app/controllers/sessions.rb
@@ -0,0 +1,29 @@
class Sessions < Application

skip_before :login_required

def new
render
end

def create
self.current_user = User.authenticate(params[:login], params[:password])
if logged_in?
if params[:remember_me] == "1"
self.current_user.remember_me
cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
end
redirect_back_or_default('/')
else
render :new
end
end

def destroy
self.current_user.forget_me if logged_in?
cookies.delete :auth_token
reset_session
redirect_back_or_default('/')
end

end
65 changes: 65 additions & 0 deletions app/controllers/topics.rb
@@ -0,0 +1,65 @@
class Topics < Application
# provides :xml, :yaml, :js

before :login_required, :exclude => [:index, :show]
before :find_forum

def find_forum
@forum ||= Forum.find(params[:forum_id])
end

def index
@topics = Topic.find(:all)
display @topics
end

def show
@topic = Topic.find_by_id(params[:id])
@post = Post.new
raise NotFound unless @topic
display @topic
end

def new
only_provides :html
@topic = Topic.new(params[:topic])
render
end

def create
@topic = @forum.topics.new(params[:topic].merge(:user => current_user))
if @topic.save
redirect url(:forum_topic, @topic)
else
render :new
end
end

def edit
only_provides :html
@topic = Topic.find_by_id(params[:id])
raise NotFound unless @topic
render
end

def update
@topic = Topic.find_by_id(params[:id])
raise NotFound unless @topic
if @topic.update_attributes(params[:topic])
redirect url(:topic, @topic)
else
raise BadRequest
end
end

def destroy
@topic = Topic.find_by_id(params[:id])
raise NotFound unless @topic
if @topic.destroy
redirect url(:topics)
else
raise BadRequest
end
end

end
23 changes: 23 additions & 0 deletions app/controllers/users.rb
@@ -0,0 +1,23 @@
class Users < Application
provides :xml

skip_before :login_required

def new
only_provides :html
@user = User.new(params[:user] || {})
display @user
end

def create
cookies.delete :auth_token

@user = User.new(params[:user])
if @user.save
redirect_back_or_default('/')
else
render :new
end
end

end
5 changes: 5 additions & 0 deletions app/helpers/forums_helper.rb
@@ -0,0 +1,5 @@
module Merb
module ForumsHelper

end
end
5 changes: 5 additions & 0 deletions app/helpers/global_helpers.rb
@@ -0,0 +1,5 @@
module Merb
module GlobalHelpers
# helpers defined here available to all views.
end
end
5 changes: 5 additions & 0 deletions app/helpers/posts_helper.rb
@@ -0,0 +1,5 @@
module Merb
module PostsHelper

end
end
5 changes: 5 additions & 0 deletions app/helpers/topics_helper.rb
@@ -0,0 +1,5 @@
module Merb
module TopicsHelper

end
end
12 changes: 12 additions & 0 deletions app/models/forum.rb
@@ -0,0 +1,12 @@
class Forum < ActiveRecord::Base

has_many :topics
has_many :posts

before_save :formatted_description

def formatted_description
write_attribute(:description_html, RedCloth.new(description).to_html )
end

end
18 changes: 18 additions & 0 deletions app/models/post.rb
@@ -0,0 +1,18 @@
class Post < ActiveRecord::Base

before_save :formatted_body

has_one :user
belongs_to :forum, :counter_cache => true
belongs_to :topic, :counter_cache => true
belongs_to :user, :counter_cache => true

def body_to_html
#textilize body and save as body_html
end

def formatted_body
write_attribute(:body_html, RedCloth.new(body).to_html )
end

end
19 changes: 19 additions & 0 deletions app/models/topic.rb
@@ -0,0 +1,19 @@
class Topic < ActiveRecord::Base
has_many :posts
belongs_to :forum, :counter_cache => true
belongs_to :user, :counter_cache => true

validates_presence_of :title,:body

after_create :add_first_post

attr_accessor :body

def add_first_post
self.posts.create({ :user_id => user.id,
:body => body,
:topic_id => id,
:forum_id => forum.id})
end

end

0 comments on commit c537374

Please sign in to comment.