Skip to content

Commit

Permalink
add boards
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed Aug 3, 2013
1 parent 1d580da commit 3639646
Show file tree
Hide file tree
Showing 32 changed files with 346 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tmp/**/*
.sass-cache/
public/assets/
tags
public/system/**/*
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ group :test do
gem 'factory_girl_rails'
gem 'capybara'
end

group :development, :test do
gem 'byebug'
end
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ GEM
xml-simple
bcrypt-ruby (3.1.1)
builder (3.1.4)
byebug (1.6.1)
columnize (~> 0.3.6)
debugger-linecache (~> 1.2.0)
capybara (2.1.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand All @@ -53,6 +56,8 @@ GEM
activesupport (>= 3.0)
cocaine (0.5.1)
climate_control (>= 0.0.3, < 1.0)
columnize (0.3.6)
debugger-linecache (1.2.0)
diff-lcs (1.2.4)
erubis (2.7.0)
escape_utils (0.3.2)
Expand Down Expand Up @@ -177,6 +182,7 @@ PLATFORMS
DEPENDENCIES
aws-s3
bcrypt-ruby
byebug
capybara
factory_girl_rails
github-linguist
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/boards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/boards.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the boards controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
33 changes: 33 additions & 0 deletions app/controllers/boards_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class BoardsController < ApplicationController
before_filter :check_password, except: [:show, :index]

def index
@boards = Board.all
end
def new

end
def create
end
def show
board = Board.find(params[:id]) || DEFAULT_BOARD || Board.first
branch = Branch.new
leaf = Leaf.new
@new_post = NewPost.new board, branch, leaf
@branches = board.branches.paginate(page: params[:page])
end
def edit

end
def update

end
def destroy
end

private

def board_params
params.require(:board).permit(:name, :config)
end
end
84 changes: 84 additions & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class PostsController < ApplicationController
before_filter :check_password, :only => [:destroy]
def index
board_id = DEFAULT_BOARD || Board.first.id
respond_to do |format|
if board_id
format.html { redirect_to post_path Board.find(board_id) }
else
format.html
end
end
end
def new
@board = Board.find(params[:id])
@post_form = PostForm.new @board
@branches = @board.branches.paginate(page: params[:page])
respond_to do |format|
format.html
end
end
def create
board = Board.find(params[:id])
@post_form = PostForm.new board, Branch.new, Leaf.new(leaf_params)
respond_to do |format|
if @post_form.save!
flash[:success] = "Branch created!"
format.html { redirect_to post_path }
else
flash[:error] = "Couldn't create branch for some reason!"
format.html { redirect_to post_path }
end
end
end
def edit
@board = Board.find(params[:board_id])
@branch = Branch.find(params[:id])
@post_form = PostForm.new @board, @branch, Leaf.new
end
def update
board = Board.find(params[:board_id])
branch = Branch.find(params[:id])
@post_form = PostForm.new board, branch, Leaf.new(leaf_params)
respond_to do |format|
if @post_form.save!
flash[:success] = "Leaf created!"
format.html { redirect_to post_path(board) }
else
flash[:error] = "Couldn't create leaf for some reason!"
format.html { redirect_to post_path(board) }
end
end
end
def destroy
params[:delete].each do |id|
@leaf = Leaf.find(id)
@branch = Branch.find(@leaf.branch_id)
if @branch.leafs.count <= 1
if @branch.destroy
flash[:success] = "Branch pruned!"
end
elsif @leaf.destroy
flash[:success] = "Leaf pruned!"
end
end

respond_to do |format|
format.html { redirect_to post_path }
end
end

private
def leaf_params
params.require(:leaf).permit(:name, :content, :photo)
end
def check_password
unless Admin.authenticate(params[:password])
flash[:error] = "Incorrect password for deletion"
redirect_to post_path
return false
else
return true
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/boards_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BoardsHelper
end
2 changes: 1 addition & 1 deletion app/helpers/leafs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def display_content(leaf)
def reply_link(leaf)
if !reply_mode? && (leaf == leaf.branch.leafs.first)
content_tag :div, class: 'replylink' do
link_to 'Reply', "/leafs/new/#{leaf.branch_id}"
link_to 'Reply', posts_path(leaf.branch.board.id, leaf.branch.id)
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/board.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Board < ActiveRecord::Base
has_many :branches
end
1 change: 1 addition & 0 deletions app/models/branch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Branch < ActiveRecord::Base
has_many :leafs, :dependent => :destroy
belongs_to :board

accepts_nested_attributes_for :leafs, :allow_destroy => true

Expand Down
35 changes: 35 additions & 0 deletions app/models/post_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class PostForm
include ActiveModel::Model

attr_reader :branch, :leaf, :board
delegate :name, :name=, :content, :content=, :photo, :photo=, to: :leaf

def persisted?
@branch.persisted?
end

def self.model_name
ActiveModel::Name.new(self, nil, "Post")
end

def id
if persisted?
"#{@board.id}/branch/#{@branch.id}"
else
@board.id
end
end

def initialize board=Board.new, branch=Branch.new, leaf=Leaf.new
@board = board
@branch = branch
@leaf = leaf
end

def save!
@branch.board_id = @board.id
@branch.save!
@leaf.branch_id = @branch.id
@leaf.save!
end
end
Empty file added app/views/boards/index.html.erb
Empty file.
27 changes: 27 additions & 0 deletions app/views/boards/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= render :partial => "layouts/form", :locals => { :new_post => @new_post } %>
<%= form_for :branch, :html => { :method => :delete } do |del| %>
<div class="loader" style="display:none">
<img src="/images/spinner.gif"/>
</div>
<div id="page">
<div id="branches">
<%= will_paginate @branches %>
<%= render @branches, :action => :show %>
<%= will_paginate @branches %>
</div>
</div>
<div class="loader" style="display:none">
<img src="/images/spinner.gif"/>
</div>
<table class="deleteform">
<tbody>
<tr>
<td>
<%= password_field_tag :password %>
<%= del.submit(:class => 'submitbutton', :value => 'Delete') %>
</td>
</tr>
</tbody>
</table>
<% end %>
18 changes: 4 additions & 14 deletions app/views/layouts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= form_for newpost, :html => { :multipart => true, :honeypot => true } do |f| %>
<% if leaf.errors.any? %>
<% url = post_form.persisted? ? posts_path(post_form.board.id, post_form.branch.id) : post_path %>
<%= form_for post_form, url: url, html: { :multipart => true, :honeypot => true } do |f| %>
<% if post_form.errors.any? %>
<div id="error_explanation">
<h2><%="Uh oh, you got" + pluralize(leaf.errors.count, "error!")%></h2>
<ul>
Expand All @@ -9,20 +10,9 @@
</ul>
</div>
<% end %>
<% if branch.errors.any? %>
<div id="error_explanation">
<h2><%="Uh oh, you got" + pluralize(branch.errors.count, "error!")%></h2>
<ul>
<% branch.errors.full_messages.each do |msg| %>
<li><%=msg%></li>
<% end %>
</ul>
</div>
<% end %>
<div class="postarea_container">
<%= fields_for leaf do |l| %>
<%= fields_for :leaf do |l| %>
<div class="postarea">
<%= hidden_field_tag("branch_id", branch.id) %>
<table>
<tr>
<td class="fieldlabel">Name</td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<%= link_to t, "#", class: 'set-theme', data: { theme: "#{t}" } %>
<% end %>
</div>
<h1><%= link_to BOARDTITLE, new_branch_path %></h1>
<h1><%= link_to BOARDTITLE, "/" %></h1>
<% flash.each do |key, value| %>
<div class="flash_#{key}">
<h2><%=value%></h2>
Expand Down
1 change: 1 addition & 0 deletions app/views/leafs/_leaf.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% logger.info "LEAF#{leaf.id}" %>
<%= link_to_file(leaf) %>
<span class="thumbnailmsg">Thumbnail displayed, click image for full size.</span>
<br/>
Expand Down
10 changes: 10 additions & 0 deletions app/views/posts/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>New leaf</h1>
<p>
<b>Last post in this thread:</b>
<%= @branch.last_post_at %>
</p>

<div class="replyheader">Posting mode: Reply</div>

<%= render :partial => "layouts/form", :locals => { :post_form => @post_form } %>
<%= render @branch %>
1 change: 1 addition & 0 deletions app/views/posts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No board has been created yet!
27 changes: 27 additions & 0 deletions app/views/posts/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= render :partial => "layouts/form", :locals => { :post_form => @post_form } %>
<%= form_for :post, :html => { :method => :delete } do |del| %>
<div class="loader" style="display:none">
<img src="/images/spinner.gif"/>
</div>
<div id="page">
<div id="branches">
<%= will_paginate @branches %>
<%= render @branches, :action => :show %>
<%= will_paginate @branches %>
</div>
</div>
<div class="loader" style="display:none">
<img src="/images/spinner.gif"/>
</div>
<table class="deleteform">
<tbody>
<tr>
<td>
<%= password_field_tag :password %>
<%= del.submit(:class => 'submitbutton', :value => 'Delete') %>
</td>
</tr>
</tbody>
</table>
<% end %>
1 change: 1 addition & 0 deletions config/initializers/fortconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
S3_KEY = ENV['S3_KEY']
S3_SECRET = ENV['S3_SECRET']
PHOTO_PATH = ':rails_root/public:url'
DEFAULT_BOARD = ENV['DEFAULT_BOARD']
Loading

0 comments on commit 3639646

Please sign in to comment.