Skip to content

Commit e68a7af

Browse files
Merge pull request #589 from Fodoj/rails4
2 parents d96d63e + dc8f343 commit e68a7af

File tree

85 files changed

+276
-2003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+276
-2003
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ env:
66
- DB=mysql
77
- DB=sqlite
88
rvm:
9+
- 2.1.0
910
- 2.0.0
1011
- 1.9.3
1112
- jruby-19mode
13+
14+
matrix:
15+
allowed_failures:
16+
- rvm: jruby-19mode

CONTRIBUTING.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Here's a quick guide:
2626
2. Run the tests. We only take pull requests with passing tests, and it's great
2727
to know that you have a clean slate:
2828

29-
```shell
30-
bundle exec rake forem:dummy_app
31-
bundle exec rspec spec
32-
```
29+
```shell
30+
bundle exec rake forem:dummy_app
31+
bundle exec rspec spec
32+
```
3333

3434
3. Add a test for your change. Only refactoring and documentation changes
3535
require no new tests. If you are adding functionality or fixing a bug, we need

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ gemspec
66

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

1111
platforms :jruby do
1212
gem "activerecord-jdbc-adapter", :require => false

README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Forem - using Bootstrap](https://github.com/radar/forem/raw/master/doc/theme.png)
1+
![Forem - using Bootstrap](https://raw.githubusercontent.com/radar/forem/rails4/doc/theme.png)
22

33
*Forem, using the forem-bootstrap theme*
44

@@ -52,21 +52,21 @@ rails g forem:install
5252

5353
## Set up helper methods in your user model
5454

55-
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:
55+
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:
5656

5757
```ruby
58-
def to_s
58+
def forem_name
5959
name
6060
end
6161
```
6262

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

66-
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:
66+
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:
6767

6868
```ruby
69-
def email
69+
def forem_email
7070
email_address
7171
end
7272
```
@@ -227,15 +227,13 @@ If all the tests are passing (they usually are), then you're good to go! Develop
227227

228228
## Places using Forem
229229

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

241239
If you want yours added here, just ask!

Rakefile

-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ begin
33
require 'bundler/setup'
44
end
55

6-
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
7-
8-
if File.exists?(APP_RAKEFILE)
9-
load 'rails/tasks/engine.rake'
10-
end
11-
126
load 'lib/tasks/forem_tasks.rake'
137

148
$:.unshift File.join(File.dirname(__FILE__), 'spec','support')

app/assets/javascripts/forem.js.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//= require select2/select2
1+
//= require select2
22
//= require jquery
33

44
var Forem = {};
@@ -37,4 +37,4 @@ function update_preview(data)
3737
{
3838
selector = $(textareaSelector).data("previewElementSelector");
3939
$(selector).html(data.html);
40-
}
40+
}

app/assets/stylesheets/forem/base.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/*
22
*= require select2
3-
*/
3+
*/
4+

app/controllers/forem/admin/categories_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def destroy
3535
private
3636

3737
def category_params
38-
params.require(:category).permit(:name)
38+
params.require(:category).permit(:name, :position)
3939
end
4040

4141
def find_category

app/controllers/forem/forums_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ForumsController < Forem::ApplicationController
44
helper 'forem/topics'
55

66
def index
7-
@categories = Forem::Category.all
7+
@categories = Forem::Category.order('position DESC')
88
end
99

1010
def show

app/controllers/forem/moderation_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ModerationController < Forem::ApplicationController
55
helper 'forem/posts'
66

77
def index
8-
@posts = forum.posts.pending_review.topic_not_pending_review
8+
@posts = forum.posts.pending_review
99
@topics = forum.topics.pending_review
1010
end
1111

app/controllers/forem/posts_controller.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
module Forem
22
class PostsController < Forem::ApplicationController
3-
before_filter :authenticate_forem_user
3+
before_filter :authenticate_forem_user, except: :show
44
before_filter :find_topic, except: [:preview]
55
before_filter :reject_locked_topic!, :only => [:create]
66
before_filter :block_spammers, :only => [:new, :create]
77
before_filter :authorize_reply_for_topic!, :only => [:new, :create]
88
before_filter :authorize_edit_post_for_forum!, :only => [:edit, :update]
9-
before_filter :find_post_for_topic, :only => [:edit, :update, :destroy]
9+
before_filter :find_post_for_topic, :only => [:show, :edit, :update, :destroy]
1010
before_filter :ensure_post_ownership!, :only => [:destroy]
1111
before_filter :authorize_destroy_post_for_forum!, :only => [:destroy]
1212

13+
def show
14+
page = (@topic.posts.count.to_f / Forem.per_page.to_f).ceil
15+
16+
redirect_to forum_topic_url(@topic.forum, @topic, pagination_param => page, anchor: "post-#{@post.id}")
17+
end
18+
1319
def new
1420
@post = @topic.posts.build
1521
find_reply_to_post

app/helpers/forem/application_helper.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ def forem_paginate(collection, options={})
3434
end
3535
end
3636

37-
def forem_atom_auto_discovery_link_tag
37+
def forem_atom_auto_discovery_link_tag
3838
if controller_name == "topics" && action_name == "show"
3939
auto_discovery_link_tag(:atom)
4040
end
4141
end
4242

4343
def forem_emojify(content)
44-
h(content).to_str.gsub(/:([a-z0-9\+\-_]+):/) do |match|
45-
if Emoji.names.include?($1)
46-
'<img alt="' + $1 + '" height="20" src="' + asset_path("emoji/#{$1}.png") + '" style="vertical-align:middle" width="20" />'
44+
h(content).to_str.gsub(/:([\w+-]+):/) do |match|
45+
if emoji = Emoji.find_by_alias($1)
46+
%(<img alt="#$1" src="#{asset_path("emoji/#{emoji.image_filename}", type: :image)}" style="vertical-align:middle" width="20" height="20" />)
4747
else
4848
match
4949
end

app/helpers/forem/posts_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def forem_avatar(user, options = {})
55
# Try to use the user's custom avatar method
66
user.try Forem.avatar_user_method.to_sym
77
else
8-
avatar_url user.try(:email), options
8+
avatar_url user.forem_email, options
99
end
1010

1111
image_tag image, :alt => "Avatar" if image.present?

app/helpers/forem/topics_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Forem
22
module TopicsHelper
33
def link_to_latest_post(topic)
44
post = relevant_posts(topic).last
5-
text = "#{time_ago_in_words(post.created_at)} #{t("ago_by")} #{post.user}"
5+
text = "#{time_ago_in_words(post.created_at)} #{t("ago_by")} #{post.user.forem_name}"
66
link_to text, forem.forum_topic_path(post.topic.forum, post.topic, :anchor => "post-#{post.id}", pagination_param => topic.last_page)
77
end
88

app/models/forem/category.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Category < ActiveRecord::Base
77

88
has_many :forums
99
validates :name, :presence => true
10+
validates :position, numericality: { only_integer: true }
1011

1112
def to_s
1213
name

app/models/forem/concerns/.keep

Whitespace-only changes.

app/models/forem/forum.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class Forum < ActiveRecord::Base
1515
has_many :moderator_groups
1616

1717
validates :category, :name, :description, :presence => true
18+
validates :position, numericality: { only_integer: true }
1819

1920
alias_attribute :title, :name
2021

21-
# Fix for #339
22-
default_scope { order(:name) }
22+
default_scope { order(:position) }
2323

2424
def last_post_for(forem_user)
2525
if forem_user && (forem_user.forem_admin? || moderator?(forem_user))

app/models/forem/nil_user.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module Forem
22
class NilUser
3-
def email
3+
def forem_email
44
55
end
66

7-
def to_s
7+
def forem_name
88
"[deleted]"
99
end
1010
end
11-
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<%= simple_form_for [forem, :admin, @category] do |f| %>
22
<%= f.input :name %>
3+
<%= f.input :position %>
34
<%= f.submit :class => "btn btn-primary" %>
45
<% end %>

app/views/forem/admin/forums/_form.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<%= simple_form_for [forem, :admin, @forum] do |f| %>
22
<%= f.association :category, :include_blank => false %>
33
<%= f.input :title %>
4+
<%= f.input :position %>
45
<%= f.input :description, :as => :text %>
56

67
<h3><%= t('forem.admin.forum.moderator_groups') %></h3>

app/views/forem/admin/forums/index.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<div class='description'><%= forem_format(forum.description) %></div>
2727
<%= t('.last_post') %>
2828
<% if last_post = forum.posts.last %>
29-
<%= link_to(forem_emojify(last_post.topic.subject), forem.forum_topic_path(forum, last_post.topic)) -%> <%= t('by') %> <%= last_post.user %> <%= time_ago_in_words(last_post.created_at) -%>
29+
<%= link_to(forem_emojify(last_post.topic.subject), forem.forum_topic_path(forum, last_post.topic)) -%> <%= t('by') %> <%= link_to_if Forem.user_profile_links, last_post.user.forem_name, [main_app, last_post.user] %> <%= time_ago_in_words(last_post.created_at) -%>
3030
<% else %>
3131
<%= t('.none') %>
3232
<% end %>
@@ -49,4 +49,4 @@
4949
</tbody>
5050
</table>
5151
<% end %>
52-
</div>
52+
</div>

app/views/forem/admin/groups/show.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="row">
1818
<ul id='members'>
1919
<% @group.members.each do |member| %>
20-
<li><%= member.to_s %> |
20+
<li><%= member.forem_name %> |
2121
<%= link_to t('forem.admin.groups.show.remove_member'), admin_group_member_url(@group, member),
2222
method: :delete, data: { confirm: t('are_you_sure') } %></li>
2323
<% end %>
@@ -45,4 +45,4 @@
4545
return result.identifier;
4646
}
4747
});
48-
</script>
48+
</script>

app/views/forem/forums/_forum.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<%= t('forem.forums.index.last_post') -%>
77
<span class='last_post'>
88
<% if last_post = forum.last_post_for(forem_user) -%>
9-
<%= link_to(forem_emojify(last_post.topic.subject), forem.forum_topic_path(forum, last_post.topic)) -%> <%= t('by') %> <%= last_post.user %>
9+
<%= link_to(forem_emojify(last_post.topic.subject), forem.forum_topic_path(forum, last_post.topic)) -%> <%= t('by') %> <%= last_post.user.forem_name %>
1010
<time datetime="<%= last_post.created_at.to_s(:db) -%>"><%= "#{time_ago_in_words(last_post.created_at)} #{t("ago")}" %></time>
1111
<% else %>
1212
<%= t('forem.forums.index.none') -%>

app/views/forem/forums/_head.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div id='forum_topic_links' class='btn-group'>
55
<% unless @topic.try(:new_record?) %>
66
<% if can? :create_topic, @forum %>
7-
<%= link_to t('forem.topic.links.new'), forem.new_forum_topic_path(forum), :class => "btn btn-primary" %>
7+
<%= link_to t('forem.topic.links.new'), forem.new_forum_topic_path(forum), :class => "btn btn-primary", :id => "new-topic" %>
88
<% end %>
99
<% end %>
1010
<% if @topic %>

app/views/forem/forums/show.atom.builder

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ atom_feed :language => 'en-US' do |feed|
99
entry.url forem.forum_topic_url(@forum, item)
1010
entry.title item.subject
1111
entry.content forem_format(item.posts.first.text), :type => 'html'
12-
entry.updated(item.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"))
12+
entry.updated(item.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"))
1313

1414
entry.author do |author|
15-
author.name item.user.to_s
15+
author.name item.user.forem_name
1616
end
1717
end
1818
end

app/views/forem/moderation/index.html.erb

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
<%= render posts, :mass_moderation => true %>
1010
<% end %>
1111
</div>
12-
<%= submit_tag t('forem.posts.moderation.moderate'), :class => "btn btn-primary" %>
1312
<% end %>
1413

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

1716
<div id='topics'>
1817
<% @topics.limit(25).each_with_index do |topic, topic_counter| %>
19-
<div id='topic_<%= topic_counter + 1 %>' class='topic <%= cycle('odd', 'even') -%>'>
18+
<div id='topic_<%= topic_counter + 1 %>' class='topic <%= cycle('odd', 'even', name: 'topics') -%>'>
2019
<div class='moderation alert'>
2120
<%= link_to forem_emojify(topic.subject),
2221
forem.forum_topic_path(forum, topic) %>

app/views/forem/posts/_post.html.erb

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ show_buttons = post.persisted? && local_assigns[:show_buttons].nil? ? true : sho
3232
<% if post_user.is_a?(Forem::NilUser) %>
3333
<%= t(:deleted) %>
3434
<% else %>
35+
<<<<<<< HEAD
3536
<%= link_to_if Forem.user_profile_links, post_user, [main_app, post_user] %>
37+
=======
38+
<%= link_to_if Forem.user_profile_links, post.user.forem_name, [main_app, post.user] %>
39+
>>>>>>> dc8f34302e1d1b02f68629b436e0fbfc7754f788
3640
<% end %>
3741
</div>
3842
<div class='icon'><%= forem_avatar(post_user, :size => 60) %></div>
@@ -55,7 +59,7 @@ show_buttons = post.persisted? && local_assigns[:show_buttons].nil? ? true : sho
5559
</a>
5660
<% if post.reply_to %>
5761
<div class='in-reply-to'>
58-
<%= link_to "#{t("forem.post.in_reply_to")} #{post.reply_to.user}", "#post-#{post.reply_to.id}" %>
62+
<%= link_to "#{t("forem.post.in_reply_to")} #{post.reply_to.user.forem_name}", "#post-#{post.reply_to.id}" %>
5963
</div>
6064
<% end %>
6165

@@ -77,7 +81,7 @@ show_buttons = post.persisted? && local_assigns[:show_buttons].nil? ? true : sho
7781
<% end %>
7882
<% if can?(:destroy_post, post.topic.forum) %>
7983
<%= 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" %>
80-
<% end %>
84+
<% end %>
8185
<% end %>
8286
</div>
8387
<% end %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<a name='post-<%= post.id %>'></a>
2+
<div id='post_<%= post.id %>' class='reply_to_post post <%= cycle('odd', 'even') -%> col-md-10'>
3+
<div class='user col-md-2'>
4+
<div class='username'>
5+
<%= link_to_if Forem.user_profile_links, post.user.forem_name, [main_app, post.user] %>
6+
</div>
7+
<div class='icon'><%= forem_avatar(post.user, :size => 60) %></div>
8+
</div>
9+
10+
<div class='contents col-md-7'>
11+
<time datetime="<%= post.created_at.to_s(:db) -%>"><%= "#{time_ago_in_words(post.created_at)} #{t("ago")}" %></time>
12+
<%= forem_format(post.text) %>
13+
14+
<% if post.reply_to %>
15+
<span class='in_reply_to'>
16+
<%= link_to "#{t("forem.post.in_reply_to")} #{post.reply_to.user.forem_name}", "#post-#{post.reply_to.id}" %>
17+
</span>
18+
<% end %>
19+
</div>
20+
</div>

app/views/forem/topics/_topic.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<td class='byline'>
1919
<%= new_since_last_view_text(topic) %>
2020
<div class='subject'><%= link_to forem_emojify(topic.subject), forem.forum_topic_path(@forum, topic) %></div>
21-
<div class='started-by'><%= t "started_by" %><%= relevant_posts(topic).first.user %></div>
21+
<div class='started-by'><%= t "started_by" %><%= relevant_posts(topic).first.user.forem_name %></div>
2222
</td>
2323
<td class='latest-post text-center'>
2424
<%= link_to_latest_post(topic) -%>

0 commit comments

Comments
 (0)