-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
1d580da
commit 3639646
Showing
32 changed files
with
346 additions
and
78 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ tmp/**/* | |
.sass-cache/ | ||
public/assets/ | ||
tags | ||
public/system/**/* |
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 |
---|---|---|
|
@@ -31,3 +31,7 @@ group :test do | |
gem 'factory_girl_rails' | ||
gem 'capybara' | ||
end | ||
|
||
group :development, :test do | ||
gem 'byebug' | ||
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
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,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
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 @@ | ||
// 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/ |
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,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 |
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,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 |
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,2 @@ | ||
module BoardsHelper | ||
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
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 @@ | ||
class Board < ActiveRecord::Base | ||
has_many :branches | ||
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
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,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.
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,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 %> |
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
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
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
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,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 %> |
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 @@ | ||
No board has been created yet! |
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,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 %> |
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
Oops, something went wrong.