Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ gem 'railties'
gem 'coffee-rails'
gem 'bootstrap-sass', "2.3.2.0"
gem 'uglifier'

gem 'thin'
gem 'devise', '3.0.0.rc'
gem 'jquery-rails'
gem 'acts-as-taggable-on'
gem 'rails-jquery-tokeninput'
gem 'protected_attributes'

source 'https://rails-assets.org' do
gem 'rails-assets-chosen'
end

# Language detection
gem "github-linguist", "~> 2.3.4" , require: "linguist"

# Syntax highlighter
gem "pygments.rb", git: "https://github.com/tmm1/pygments.rb", branch: "master"
gem 'diffy'
gem 'jquery-rails'
gem 'devise', '3.0.0.rc'

14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GIT

GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
specs:
actionmailer (4.0.1)
actionpack (= 4.0.1)
Expand All @@ -34,6 +35,8 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
acts-as-taggable-on (3.5.0)
activerecord (>= 3.2, < 5)
arel (4.0.1)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
Expand Down Expand Up @@ -79,6 +82,8 @@ GEM
orm_adapter (0.4.0)
polyglot (0.3.3)
posix-spawn (0.3.6)
protected_attributes (1.1.3)
activemodel (>= 4.0.1, < 5.0)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
Expand All @@ -90,6 +95,11 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.1)
sprockets-rails (~> 2.0.0)
rails-assets-chosen (1.6.1)
rails-assets-jquery (>= 1.4.4)
rails-assets-jquery (3.1.0)
rails-jquery-tokeninput (0.2.6)
jquery-rails (>= 2)
railties (4.0.1)
actionpack (= 4.0.1)
activesupport (= 4.0.1)
Expand Down Expand Up @@ -135,14 +145,18 @@ PLATFORMS
ruby

DEPENDENCIES
acts-as-taggable-on
bootstrap-sass (= 2.3.2.0)
coffee-rails
devise (= 3.0.0.rc)
diffy
github-linguist (~> 2.3.4)
jquery-rails
protected_attributes
pygments.rb!
rails (~> 4.0.1)
rails-assets-chosen!
rails-jquery-tokeninput
railties
redcarpet
sass-rails
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.tokeninput
//= require_tree .

// Loads all Bootstrap javascripts
//= require bootstrap
//

//Needed for tag auto completition
//= require chosen
//
7 changes: 7 additions & 0 deletions app/assets/javascripts/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,11 @@ $(document).ready(function() {
}, 100);
});

$('#post_tags').tokenInput("/posts/tags.json", {
tokenValue: "name",
allowFreeTagging: true,
preventDuplicates: true,
prePopulate: $("#post_tags").data("pre")
});
});

2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require token-input
*= require_tree .
*= require chosen
*/

/* compensate the overlap caused by bootstrap top navigation, min. 40px at the top! */
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/posts.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
padding-bottom: 20px;
}

.set-lower-25 {
padding-top: 25px;
}

input.input-sm {
height: 12px;
width: 32px;
Expand Down
17 changes: 14 additions & 3 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def show
@post = Post.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.text { render :text => @post.content }
end
format.html # show.html.erb
format.text { render :text => @post.content }
end
end

# GET /posts/new
Expand Down Expand Up @@ -252,6 +252,17 @@ def parentlist
end
end

def tags
@tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:q]}%")
respond_to do |format|
format.json {render :json => @tags.map{|t| {:id => t.name, :name => t.name }}}
end
end

def search_by_tag
@posts = Post.tagged_with(params[:tag_name])
end

private

def post_params
Expand Down
44 changes: 38 additions & 6 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Post < ActiveRecord::Base
require 'tempfile'
#require 'acts-as-taggable-on'

def self.MaxUploadSize
102400 # 100kb
Expand All @@ -22,6 +23,10 @@ def self.MaxUploadSize
:foreign_key => :parent_id, :dependent => :destroy
belongs_to :parent, :class_name => "Post"

acts_as_taggable

attr_accessible :tag_list, :title, :author, :content_type, :content

attr_accessor :uploaded_file

def self.file_extensions
Expand Down Expand Up @@ -63,11 +68,28 @@ def all_comments
end

def create_version(params)
child = self.class.new(params)
child.parent_id = self.id
self.newest = false
self.save
return child
if self.newest != true
children_ids = self.children.map{|x| x.id}
newest_post = Post.where(:id => children_ids, "newest" => true).first
former_newest_params = newest_post.serializable_hash
former_newest_params.delete("id")
former_newest_params["newest"] = false
former_newest = self.class.new(former_newest_params)
former_newest.save
newest_post.update_attributes(params)
newest_post.parent_id = former_newest.id
return newest_post
else
old_params = self.serializable_hash
old_params.delete("id")
parent = self.class.new(old_params)
parent.newest = false
self.newest = true
parent.save
self.parent_id = parent.id
self.update_attributes(params)
return self
end
end

def self.new_from_file(params, data)
Expand Down Expand Up @@ -136,8 +158,18 @@ def diff_to_parent(post_id = nil)
end
end

def children
child = Post.where(:parent_id => self.id).first
return [] if child.nil?
return child.children + [child]
end

def parents
return [] if parent_id.nil?
return parent.parents + [parent]
return [parent] + parent.parents
end

def tag_list_tokens=(tokens)
self.tag_list = tokens.gsub("'", "")
end
end
20 changes: 16 additions & 4 deletions app/views/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
:id => "inputContentType")%>
</div>
</div>
</div>
</div>


<div class="row">
<div class="span12">
Expand All @@ -60,7 +61,7 @@
</div>

<div class="row">
<div class="span9">
<div class="span6">
<label class="control-label" for="inputContent">
<%= f.label "And/Or Upload a File (Max-Size: " +
"#{Post.MaxUploadSize / 1024}kb)" %>
Expand All @@ -69,9 +70,20 @@
<%= f.file_field :upload_file, { :id => "inputUploadFile",
:class => "input-xxlarge" } %>
</div>
</div>
</div>

<div class="span3">
<%= f.submit :class => "btn pull-right" %>
<label class="control-label" for "inputTokens">
<%= f.label :tag_list_tokens, "Tags" %>
</label>
<div class="controls">
<%= f.text_field :tag_list, :id => "post_tags",
"data-pre" => @post.tags.map(&:attributes).to_json %>
</div>
</div>

<div class="span3 set-lower-25">
<%= f.submit :class => "btn pull-right" %>
</div>
</div>
</div>
Expand Down
22 changes: 15 additions & 7 deletions app/views/posts/_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
<% end %>
<% end %>

<% if @post.parent.present? &&
!current_page?(root_url) && !current_page?(posts_path) %>
<% if !current_page?(root_url) && !current_page?(posts_path) %>
<%= !@post.parent.nil? ? parent_placeholder =
@post.parent.id.to_s : parent_placeholder = "" %>
<%= text_field_tag(:diff_id, nil, :class => "input-sm",
:placeholder => @post.parent.id.to_s) %>
:placeholder => parent_placeholder) %>
<%= button_tag(:type => "submit", :class => "btn btn-mini",
:title => "Diff") do %>
<i class="icon-plus"></i>
Expand All @@ -30,13 +31,20 @@
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><%= link_to(parentlist_post_path(@post)){"Parentlist"} %></li>
<li><%= link_to(parentlist_post_path(@post)){"all Versions"} %></li>
<li class="divider"></li>
<% children = @post.children %>
<% parents = @post.parents %>
<% parents.reverse.take(5).each.with_index(0) do |parent, id| %>
<% children.each.with_index(0) do |child, id| %>
<li><%= link_to(diff_post_path(@post,
:diff_id => child.id)){"Version: #{parents.size + 1 + children.size - id}"} %></li>
<% end %>
<li><%= link_to(diff_post_path(@post, :diff_id => @post.id)) { "Version: #{parents.size + 1} (self)"} %> </li>
<% parents.each.with_index(0) do |parent, id| %>
<li><%= link_to(diff_post_path(@post,
:diff_id => parent.id)){"Version: #{parents.size - id}"} %></li>
<% end %>

</ul>
</div>
<% end %>
Expand All @@ -58,8 +66,8 @@
<% end %>
<% end %>

<%= link_to post_path(@post, :format => :json),
:method => :delete, :remote => true,
<%= link_to post_path(@post),
:method => :delete,
data: { confirm: 'Are you sure?' }, :class => "btn btn-mini",
:id => "delete_trigger", :title => "Delete" do %>
<i class="icon-trash"></i>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_post.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<small class="date"> - <%= @post.updated_at.strftime('%a, %d %b %Y %H:%M:%S') %>
</small>

<%= render 'options' %>
<%= render 'posts/options' %>

<br />
<br />
Expand Down
13 changes: 11 additions & 2 deletions app/views/posts/parentlist.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<div class="parentlist">
<% @post.parents.each.with_index(1) do |parent, id| %>
<li><%= link_to(diff_post_path(@post, :diff_id => parent.id)){"Version: #{id}"} %></li>
<% children = @post.children %>
<% parents = @post.parents %>
<% children.each.with_index(0) do |child, id| %>
<li><%= link_to(diff_post_path(@post,
:diff_id => child.id)){"Version: #{parents.size + 1 + children.size - id}"} %></li>
<% end %>
<li><%= link_to(diff_post_path(@post,
:diff_id => @post.id)) { "Version: #{parents.size + 1} (self)"} %> </li>
<% parents.each.with_index(0) do |parent, id| %>
<li><%= link_to(diff_post_path(@post,
:diff_id => parent.id)){"Version: #{parents.size - id}"} %></li>
<% end %>
</div>

5 changes: 5 additions & 0 deletions app/views/posts/search_by_tag.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% unless @posts.blank? %>
<div class='row'>
<%= render :partial => "post", :collection => @posts %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<input id="post_url" class="input-xlarge uneditable-input" type="text"
value="<%= post_url(@post) %>"></input>

<br/>
<% @post.tag_counts_on(:tags).map(&:name).each do |tag| %>
<%= link_to tag, {:action => 'search_by_tag', :tag_name => tag},
:class => "btn btn-mini" %>
<% end %>

<br/><br/>
<%= render 'like_dislike' %>
<%= render 'comments/comment' %>
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Application < Rails::Application
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)

# Only load the plugins named here, in the order given (default is alphabetical).
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

# note that the helper methods are still called with 'posts' instead of 'p'
# for legibility purposes
get "posts/tags" => "posts#tags", :as => :tags

resources :posts, :path => :p do
resources :comments
resources :linecomments
Expand All @@ -12,8 +14,10 @@
get :dislike
get :markdown
get :parentlist
end
get :search_by_tag
end
end

resources :posts, :as => :p

get '/help' => 'posts#help', :as => :help
Expand Down
Loading