Skip to content

Commit

Permalink
Merge pull request #589 from Fodoj/rails4
Browse files Browse the repository at this point in the history
  • Loading branch information
louiecaulfield committed Sep 12, 2014
2 parents d96d63e + 03908c4 commit 77c20aa
Show file tree
Hide file tree
Showing 71 changed files with 221 additions and 1,949 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
- DB=mysql
- DB=sqlite
rvm:
- 2.1.0
- 2.0.0
- 1.9.3
- jruby-19mode
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Here's a quick guide:
2. Run the tests. We only take pull requests with passing tests, and it's great
to know that you have a clean slate:

```shell
bundle exec rake forem:dummy_app
bundle exec rspec spec
```
```shell
bundle exec rake forem:dummy_app
bundle exec rspec spec
```

3. Add a test for your change. Only refactoring and documentation changes
require no new tests. If you are adding functionality or fixing a bug, we need
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gemspec

gem 'pry-rails'
gem 'pry-nav'
gem 'cancan', git: "https://github.com/nukturnal/cancan.git"
gem 'select2-rails', '~> 3.5.4'

platforms :jruby do
gem "activerecord-jdbc-adapter", :require => false
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Forem - using Bootstrap](https://github.com/radar/forem/raw/master/doc/theme.png)
![Forem - using Bootstrap](https://raw.githubusercontent.com/radar/forem/rails4/doc/theme.png)

*Forem, using the forem-bootstrap theme*

Expand Down Expand Up @@ -52,21 +52,21 @@ rails g forem:install

## Set up helper methods in your user model

Forem depends on a `to_s` method being available on your `User` model so that it can display the user's name in posts. Define this in your model like this:
Forem uses a `forem_name` (which defaults as `to_s`) method being available on your `User` model so that it can display the user's name in posts. Define it in your model like this:

```ruby
def to_s
def forem_name
name
end
```

Please note that if you are using Devise, User model does not have `name` column by default,
so you either should use custom migration to add it or use another column (`email` for example).

It also depends on an `email` method for displaying avatars using [Gravatar](http://gravatar.com). If you don't have an `email` attribute on the model, define a new method:
It also uses an optional `forem_email` method for displaying avatars using [Gravatar](http://gravatar.com). It defaults to `email`. If you don't have an `email` attribute on the model, define a new method:

```ruby
def email
def forem_email
email_address
end
```
Expand Down Expand Up @@ -227,15 +227,13 @@ If all the tests are passing (they usually are), then you're good to go! Develop

## Places using Forem

* [Bias Project](http://biasproject.org)
* [Alabama Intel](http://alabamaintel.com)
* [PixieEngine](http://pixieengine.com/community)
* [2012 Presidential Election](http://www.2012-presidential-election.info/network/)
* [Huntington's Disease Youth Organization](http://hdyo.org/)
* [Miniand Tech](https://www.miniand.com/forums)
* [Goodsmiths](https://www.goodsmiths.com/hub)
* [Now Novel](http://nownovel.com/bookwriting)
* [OrbsCCG](http://orbsccg.com/forums/)
* [Airesis](http://www.airesis.eu)
* [Lab Nation](https://www.lab-nation.com/forum/)

If you want yours added here, just ask!
4 changes: 2 additions & 2 deletions app/assets/javascripts/forem.js.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//= require select2/select2
//= require select2
//= require jquery

var Forem = {};
Expand Down Expand Up @@ -37,4 +37,4 @@ function update_preview(data)
{
selector = $(textareaSelector).data("previewElementSelector");
$(selector).html(data.html);
}
}
3 changes: 2 additions & 1 deletion app/assets/stylesheets/forem/base.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
*= require select2
*/
*/

2 changes: 1 addition & 1 deletion app/controllers/forem/moderation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ModerationController < Forem::ApplicationController
helper 'forem/posts'

def index
@posts = forum.posts.pending_review.topic_not_pending_review
@posts = forum.posts.pending_review
@topics = forum.topics.pending_review
end

Expand Down
10 changes: 8 additions & 2 deletions app/controllers/forem/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
module Forem
class PostsController < Forem::ApplicationController
before_filter :authenticate_forem_user
before_filter :authenticate_forem_user, except: :show
before_filter :find_topic, except: [:preview]
before_filter :reject_locked_topic!, :only => [:create]
before_filter :block_spammers, :only => [:new, :create]
before_filter :authorize_reply_for_topic!, :only => [:new, :create]
before_filter :authorize_edit_post_for_forum!, :only => [:edit, :update]
before_filter :find_post_for_topic, :only => [:edit, :update, :destroy]
before_filter :find_post_for_topic, :only => [:show, :edit, :update, :destroy]
before_filter :ensure_post_ownership!, :only => [:destroy]
before_filter :authorize_destroy_post_for_forum!, :only => [:destroy]

def show
page = (@topic.posts.count.to_f / Forem.per_page.to_f).ceil

redirect_to forum_topic_url(@topic.forum, @topic, pagination_param => page, anchor: "post-#{@post.id}")
end

def new
@post = @topic.posts.build
find_reply_to_post
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/forem/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ def forem_paginate(collection, options={})
end
end

def forem_atom_auto_discovery_link_tag
def forem_atom_auto_discovery_link_tag
if controller_name == "topics" && action_name == "show"
auto_discovery_link_tag(:atom)
end
end

def forem_emojify(content)
h(content).to_str.gsub(/:([a-z0-9\+\-_]+):/) do |match|
if Emoji.names.include?($1)
'<img alt="' + $1 + '" height="20" src="' + asset_path("emoji/#{$1}.png") + '" style="vertical-align:middle" width="20" />'
h(content).to_str.gsub(/:([\w+-]+):/) do |match|
if emoji = Emoji.find_by_alias($1)
%(<img alt="#$1" src="#{asset_path("emoji/#{emoji.image_filename}", type: :image)}" style="vertical-align:middle" width="20" height="20" />)
else
match
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/forem/posts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def forem_avatar(user, options = {})
# Try to use the user's custom avatar method
user.try Forem.avatar_user_method.to_sym
else
avatar_url user.try(:email), options
avatar_url user.forem_email, options
end

image_tag image, :alt => "Avatar" if image.present?
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/forem/topics_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Forem
module TopicsHelper
def link_to_latest_post(topic)
post = relevant_posts(topic).last
text = "#{time_ago_in_words(post.created_at)} #{t("ago_by")} #{post.user}"
text = "#{time_ago_in_words(post.created_at)} #{t("ago_by")} #{post.user.forem_name}"
link_to text, forem.forum_topic_path(post.topic.forum, post.topic, :anchor => "post-#{post.id}", pagination_param => topic.last_page)
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/forem/nil_user.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Forem
class NilUser
def email
def forem_email
"[email protected]"
end

def to_s
def forem_name
"[deleted]"
end
end
end
end
4 changes: 2 additions & 2 deletions app/views/forem/admin/groups/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="row">
<ul id='members'>
<% @group.members.each do |member| %>
<li><%= member.to_s %> |
<li><%= member.forem_name %> |
<%= link_to t('forem.admin.groups.show.remove_member'), admin_group_member_url(@group, member),
method: :delete, data: { confirm: t('are_you_sure') } %></li>
<% end %>
Expand Down Expand Up @@ -45,4 +45,4 @@
return result.identifier;
}
});
</script>
</script>
2 changes: 1 addition & 1 deletion app/views/forem/forums/_forum.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= t('forem.forums.index.last_post') -%>
<span class='last_post'>
<% if last_post = forum.last_post_for(forem_user) -%>
<%= link_to(forem_emojify(last_post.topic.subject), forem.forum_topic_path(forum, last_post.topic)) -%> <%= t('by') %> <%= last_post.user %>
<%= link_to(forem_emojify(last_post.topic.subject), forem.forum_topic_path(forum, last_post.topic)) -%> <%= t('by') %> <%= last_post.user.forem_name %>
<time datetime="<%= last_post.created_at.to_s(:db) -%>"><%= "#{time_ago_in_words(last_post.created_at)} #{t("ago")}" %></time>
<% else %>
<%= t('forem.forums.index.none') -%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/forem/forums/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div id='forum_topic_links' class='btn-group'>
<% unless @topic.try(:new_record?) %>
<% if can? :create_topic, @forum %>
<%= link_to t('forem.topic.links.new'), forem.new_forum_topic_path(forum), :class => "btn btn-primary" %>
<%= link_to t('forem.topic.links.new'), forem.new_forum_topic_path(forum), :class => "btn btn-primary", :id => "new-topic" %>
<% end %>
<% end %>
<% if @topic %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/forem/forums/show.atom.builder
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ atom_feed :language => 'en-US' do |feed|
entry.url forem.forum_topic_url(@forum, item)
entry.title item.subject
entry.content forem_format(item.posts.first.text), :type => 'html'
entry.updated(item.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"))
entry.updated(item.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"))

entry.author do |author|
author.name item.user.to_s
author.name item.user.forem_name
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/forem/moderation/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
<%= render posts, :mass_moderation => true %>
<% end %>
</div>
<%= submit_tag t('forem.posts.moderation.moderate'), :class => "btn btn-primary" %>
<% end %>

<h3><%= t('topics_count', :count => @topics.count, :scope => 'forem.forum') %></h3>

<div id='topics'>
<% @topics.limit(25).each_with_index do |topic, topic_counter| %>
<div id='topic_<%= topic_counter + 1 %>' class='topic <%= cycle('odd', 'even') -%>'>
<div id='topic_<%= topic_counter + 1 %>' class='topic <%= cycle('odd', 'even', name: 'topics') -%>'>
<div class='moderation alert'>
<%= link_to forem_emojify(topic.subject),
forem.forum_topic_path(forum, topic) %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/forem/posts/_post.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ show_buttons = post.persisted? && local_assigns[:show_buttons].nil? ? true : sho
<% if post_user.is_a?(Forem::NilUser) %>
<%= t(:deleted) %>
<% else %>
<%= link_to_if Forem.user_profile_links, post_user, [main_app, post_user] %>
<%= link_to_if Forem.user_profile_links, post_user.forem_name, [main_app, post_user] %>
<% end %>
</div>
<div class='icon'><%= forem_avatar(post_user, :size => 60) %></div>
Expand All @@ -55,7 +55,7 @@ show_buttons = post.persisted? && local_assigns[:show_buttons].nil? ? true : sho
</a>
<% if post.reply_to %>
<div class='in-reply-to'>
<%= link_to "#{t("forem.post.in_reply_to")} #{post.reply_to.user}", "#post-#{post.reply_to.id}" %>
<%= link_to "#{t("forem.post.in_reply_to")} #{post.reply_to.user.forem_name}", "#post-#{post.reply_to.id}" %>
</div>
<% end %>

Expand All @@ -77,7 +77,7 @@ show_buttons = post.persisted? && local_assigns[:show_buttons].nil? ? true : sho
<% end %>
<% if can?(:destroy_post, post.topic.forum) %>
<%= link_to t('delete', :scope => 'forem.topic'), forem.forum_topic_post_path(post.forum, post.topic, post), :method => :delete, data: { :confirm => t("are_you_sure") }, :class => "btn btn-danger" %>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/forem/topics/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<% end %>

<%= f.submit :class => "btn btn-primary" %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/forem/topics/_topic.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<td class='byline'>
<%= new_since_last_view_text(topic) %>
<div class='subject'><%= link_to forem_emojify(topic.subject), forem.forum_topic_path(@forum, topic) %></div>
<div class='started-by'><%= t "started_by" %><%= relevant_posts(topic).first.user %></div>
<div class='started-by'><%= t "started_by" %><%= relevant_posts(topic).first.user.forem_name %></div>
</td>
<td class='latest-post text-center'>
<%= link_to_latest_post(topic) -%>
Expand Down
16 changes: 0 additions & 16 deletions bin/a2h

This file was deleted.

16 changes: 0 additions & 16 deletions bin/autospec

This file was deleted.

16 changes: 0 additions & 16 deletions bin/bcat

This file was deleted.

16 changes: 0 additions & 16 deletions bin/btee

This file was deleted.

16 changes: 0 additions & 16 deletions bin/cdiff

This file was deleted.

16 changes: 0 additions & 16 deletions bin/cucumber

This file was deleted.

Loading

0 comments on commit 77c20aa

Please sign in to comment.