Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c537374
Showing
101 changed files
with
2,819 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
schema/schema.rb | ||
log/* |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
############################################################################## |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require File.join(File.dirname(__FILE__), '..', '..', "lib", "authenticated_system", "authenticated_dependencies") | ||
class Application < Merb::Controller | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Merb | ||
module ForumsHelper | ||
|
||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Merb | ||
module GlobalHelpers | ||
# helpers defined here available to all views. | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Merb | ||
module PostsHelper | ||
|
||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Merb | ||
module TopicsHelper | ||
|
||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.