forem 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +13 -0
  3. data/Gemfile.lock +166 -0
  4. data/MIT-LICENSE +20 -0
  5. data/Rakefile +33 -0
  6. data/app/controllers/forem/application_controller.rb +13 -0
  7. data/app/controllers/forem/forums_controler.rb +11 -0
  8. data/app/controllers/forem/posts_controller.rb +26 -0
  9. data/app/controllers/forem/topics_controller.rb +35 -0
  10. data/app/helpers/forem/application_helper.rb +4 -0
  11. data/app/models/forem/forum.rb +4 -0
  12. data/app/models/forem/post.rb +11 -0
  13. data/app/models/forem/topic.rb +17 -0
  14. data/app/views/forem/forums/index.html.erb +13 -0
  15. data/app/views/forem/forums/show.html.erb +3 -0
  16. data/app/views/forem/posts/_form.html.erb +4 -0
  17. data/app/views/forem/posts/_post.html.erb +20 -0
  18. data/app/views/forem/posts/new.html.erb +6 -0
  19. data/app/views/forem/topics/_form.html.erb +9 -0
  20. data/app/views/forem/topics/new.html.erb +3 -0
  21. data/app/views/forem/topics/show.html.erb +6 -0
  22. data/config/locales/en.yml +23 -0
  23. data/config/routes.rb +9 -0
  24. data/db/migrate/20110214221555_create_forums.rb +13 -0
  25. data/db/migrate/20110221092741_create_topics.rb +11 -0
  26. data/db/migrate/20110221094502_create_posts.rb +11 -0
  27. data/db/migrate/20110228084940_add_reply_to_to_posts.rb +5 -0
  28. data/forem.gemspec +16 -0
  29. data/lib/forem.rb +4 -0
  30. data/lib/forem/engine.rb +13 -0
  31. data/lib/rack/utils_monkey_patch.rb +9 -0
  32. data/lib/tasks/forem_tasks.rake +4 -0
  33. data/public/javascripts/application.js +2 -0
  34. data/public/javascripts/controls.js +965 -0
  35. data/public/javascripts/dragdrop.js +974 -0
  36. data/public/javascripts/effects.js +1123 -0
  37. data/public/javascripts/prototype.js +6082 -0
  38. data/public/javascripts/rails.js +192 -0
  39. data/public/stylesheets/.gitkeep +0 -0
  40. data/script/rails +6 -0
  41. data/spec/dummy/Rakefile +7 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/controllers/fake_controller.rb +5 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/models/user.rb +6 -0
  46. data/spec/dummy/app/views/fake/sign_in.html.erb +7 -0
  47. data/spec/dummy/app/views/layouts/application.html.erb +17 -0
  48. data/spec/dummy/config.ru +4 -0
  49. data/spec/dummy/config/application.rb +43 -0
  50. data/spec/dummy/config/boot.rb +10 -0
  51. data/spec/dummy/config/database.yml +16 -0
  52. data/spec/dummy/config/environment.rb +5 -0
  53. data/spec/dummy/config/environments/development.rb +26 -0
  54. data/spec/dummy/config/environments/production.rb +49 -0
  55. data/spec/dummy/config/environments/test.rb +35 -0
  56. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/spec/dummy/config/initializers/inflections.rb +10 -0
  58. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  59. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  60. data/spec/dummy/config/initializers/session_store.rb +8 -0
  61. data/spec/dummy/config/locales/en.yml +5 -0
  62. data/spec/dummy/config/routes.rb +4 -0
  63. data/spec/dummy/db/migrate/001_create_users.rb +8 -0
  64. data/spec/dummy/db/schema.rb +43 -0
  65. data/spec/dummy/public/404.html +26 -0
  66. data/spec/dummy/public/422.html +26 -0
  67. data/spec/dummy/public/500.html +26 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/public/javascripts/application.js +2 -0
  70. data/spec/dummy/public/javascripts/controls.js +965 -0
  71. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  72. data/spec/dummy/public/javascripts/effects.js +1123 -0
  73. data/spec/dummy/public/javascripts/prototype.js +6082 -0
  74. data/spec/dummy/public/javascripts/rails.js +192 -0
  75. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  76. data/spec/dummy/script/rails +6 -0
  77. data/spec/integration/forums_spec.rb +22 -0
  78. data/spec/integration/posts_spec.rb +36 -0
  79. data/spec/integration/topics_spec.rb +71 -0
  80. data/spec/models/post_spec.rb +16 -0
  81. data/spec/spec_helper.rb +15 -0
  82. data/spec/support/capybara.rb +6 -0
  83. data/spec/support/capybara_ext.rb +47 -0
  84. data/spec/support/dummy_login.rb +33 -0
  85. data/spec/support/factories.rb +45 -0
  86. data/spec/support/factories/forums.rb +4 -0
  87. data/spec/support/factories/topics.rb +4 -0
  88. data/spec/support/routes.rb +5 -0
  89. metadata +221 -0
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ pkg/
3
+ *.sqlite3
4
+ *.log
5
+ .rvmrc
6
+ *.gem
7
+ *.gems
8
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', :git => "git://github.com/rails/rails"
4
+ gem 'rack', :git => "git://github.com/rack/rack.git"
5
+ gem 'arel', :git => "git://github.com/rails/arel.git"
6
+
7
+ if RUBY_VERSION < '1.9'
8
+ gem "ruby-debug", ">= 0.10.3"
9
+ else
10
+ gem "ruby-debug19"
11
+ end
12
+
13
+ gemspec
@@ -0,0 +1,166 @@
1
+ GIT
2
+ remote: git://github.com/rack/rack.git
3
+ revision: e3ffeac0dc04bb8d5994b7923bf12e55d549a279
4
+ specs:
5
+ rack (1.2.1)
6
+
7
+ GIT
8
+ remote: git://github.com/rails/arel.git
9
+ revision: dbc86c0f2c2fc3c8bacf35c67fb8e0967b0a8980
10
+ specs:
11
+ arel (2.0.7.beta.20110121165657)
12
+
13
+ GIT
14
+ remote: git://github.com/rails/rails
15
+ revision: 5f1fc0c8ac6e71bfb4d66da2005b1b0694e18446
16
+ specs:
17
+ actionmailer (3.1.0.beta)
18
+ actionpack (= 3.1.0.beta)
19
+ mail (~> 2.2.15)
20
+ actionpack (3.1.0.beta)
21
+ activemodel (= 3.1.0.beta)
22
+ activesupport (= 3.1.0.beta)
23
+ builder (~> 3.0.0)
24
+ erubis (~> 2.6.6)
25
+ i18n (~> 0.5.0)
26
+ rack (~> 1.2.1)
27
+ rack-cache (~> 1.0.0)
28
+ rack-mount (~> 0.6.13)
29
+ rack-test (~> 0.5.7)
30
+ tzinfo (~> 0.3.23)
31
+ activemodel (3.1.0.beta)
32
+ activesupport (= 3.1.0.beta)
33
+ bcrypt-ruby (~> 2.1.4)
34
+ builder (~> 3.0.0)
35
+ i18n (~> 0.5.0)
36
+ activerecord (3.1.0.beta)
37
+ activemodel (= 3.1.0.beta)
38
+ activesupport (= 3.1.0.beta)
39
+ arel (~> 2.0.2)
40
+ tzinfo (~> 0.3.23)
41
+ activeresource (3.1.0.beta)
42
+ activemodel (= 3.1.0.beta)
43
+ activesupport (= 3.1.0.beta)
44
+ activesupport (3.1.0.beta)
45
+ rails (3.1.0.beta)
46
+ actionmailer (= 3.1.0.beta)
47
+ actionpack (= 3.1.0.beta)
48
+ activerecord (= 3.1.0.beta)
49
+ activeresource (= 3.1.0.beta)
50
+ activesupport (= 3.1.0.beta)
51
+ bundler (~> 1.0)
52
+ railties (= 3.1.0.beta)
53
+ railties (3.1.0.beta)
54
+ actionpack (= 3.1.0.beta)
55
+ activesupport (= 3.1.0.beta)
56
+ rake (>= 0.8.7)
57
+ thor (~> 0.14.4)
58
+
59
+ PATH
60
+ remote: .
61
+ specs:
62
+ forem (0.0.1)
63
+ simple_form
64
+
65
+ GEM
66
+ remote: http://rubygems.org/
67
+ specs:
68
+ abstract (1.0.0)
69
+ archive-tar-minitar (0.5.2)
70
+ bcrypt-ruby (2.1.4)
71
+ builder (3.0.0)
72
+ capybara (0.4.1.2)
73
+ celerity (>= 0.7.9)
74
+ culerity (>= 0.2.4)
75
+ mime-types (>= 1.16)
76
+ nokogiri (>= 1.3.3)
77
+ rack (>= 1.0.0)
78
+ rack-test (>= 0.5.4)
79
+ selenium-webdriver (>= 0.0.27)
80
+ xpath (~> 0.1.3)
81
+ celerity (0.8.8)
82
+ childprocess (0.1.7)
83
+ ffi (~> 0.6.3)
84
+ columnize (0.3.2)
85
+ configuration (1.2.0)
86
+ culerity (0.2.15)
87
+ diff-lcs (1.1.2)
88
+ erubis (2.6.6)
89
+ abstract (>= 1.0.0)
90
+ ffi (0.6.3)
91
+ rake (>= 0.8.7)
92
+ i18n (0.5.0)
93
+ json_pure (1.5.1)
94
+ launchy (0.3.7)
95
+ configuration (>= 0.0.5)
96
+ rake (>= 0.8.1)
97
+ linecache19 (0.5.11)
98
+ ruby_core_source (>= 0.1.4)
99
+ mail (2.2.15)
100
+ activesupport (>= 2.3.6)
101
+ i18n (>= 0.4.0)
102
+ mime-types (~> 1.16)
103
+ treetop (~> 1.4.8)
104
+ mime-types (1.16)
105
+ nokogiri (1.4.4)
106
+ polyglot (0.3.1)
107
+ rack-cache (1.0)
108
+ rack (>= 0.4)
109
+ rack-mount (0.6.13)
110
+ rack (>= 1.0.0)
111
+ rack-test (0.5.7)
112
+ rack (>= 1.0)
113
+ rake (0.8.7)
114
+ rspec (2.5.0)
115
+ rspec-core (~> 2.5.0)
116
+ rspec-expectations (~> 2.5.0)
117
+ rspec-mocks (~> 2.5.0)
118
+ rspec-core (2.5.1)
119
+ rspec-expectations (2.5.0)
120
+ diff-lcs (~> 1.1.2)
121
+ rspec-mocks (2.5.0)
122
+ rspec-rails (2.5.0)
123
+ actionpack (~> 3.0)
124
+ activesupport (~> 3.0)
125
+ railties (~> 3.0)
126
+ rspec (~> 2.5.0)
127
+ ruby-debug-base19 (0.11.24)
128
+ columnize (>= 0.3.1)
129
+ linecache19 (>= 0.5.11)
130
+ ruby_core_source (>= 0.1.4)
131
+ ruby-debug19 (0.11.6)
132
+ columnize (>= 0.3.1)
133
+ linecache19 (>= 0.5.11)
134
+ ruby-debug-base19 (>= 0.11.19)
135
+ ruby_core_source (0.1.4)
136
+ archive-tar-minitar (>= 0.5.2)
137
+ rubyzip (0.9.4)
138
+ selenium-webdriver (0.1.3)
139
+ childprocess (~> 0.1.5)
140
+ ffi (~> 0.6.3)
141
+ json_pure
142
+ rubyzip
143
+ simple_form (1.3.1)
144
+ sqlite3 (1.3.3)
145
+ sqlite3-ruby (1.3.3)
146
+ sqlite3 (>= 1.3.3)
147
+ thor (0.14.6)
148
+ treetop (1.4.9)
149
+ polyglot (>= 0.3.1)
150
+ tzinfo (0.3.24)
151
+ xpath (0.1.3)
152
+ nokogiri (~> 1.3)
153
+
154
+ PLATFORMS
155
+ ruby
156
+
157
+ DEPENDENCIES
158
+ arel!
159
+ capybara
160
+ forem!
161
+ launchy
162
+ rack!
163
+ rails!
164
+ rspec-rails (~> 2.5)
165
+ ruby-debug19
166
+ sqlite3-ruby
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rake/rdoctask'
9
+
10
+ Rake::RDocTask.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'Forem'
13
+ rdoc.options << '--line-numbers' << '--inline-source'
14
+ rdoc.rdoc_files.include('README.rdoc')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
19
+ load 'rails/tasks/engine.rake'
20
+
21
+ require 'rake/testtask'
22
+
23
+ Rake::TestTask.new(:test) do |t|
24
+ t.libs << 'lib'
25
+ t.libs << 'test'
26
+ t.pattern = 'test/**/*_test.rb'
27
+ t.verbose = false
28
+ end
29
+
30
+
31
+ task :default => :test
32
+
33
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,13 @@
1
+ class Forem::ApplicationController < ApplicationController
2
+ def authenticate_forem_user
3
+ if !current_user
4
+ session[:return_to] = request.fullpath
5
+ flash[:error] = t("forem.errors.not_signed_in")
6
+ redirect_to "/sign_in" #TODO: Change to routing helper for flexibility
7
+ end
8
+ end
9
+
10
+ # dummy method
11
+ def current_user
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Forem
2
+ class ForumsController < Forem::ApplicationController
3
+ def index
4
+ @forums = Forem::Forum.all
5
+ end
6
+
7
+ def show
8
+ @forum = Forem::Forum.find(params[:id])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ class Forem::PostsController < Forem::ApplicationController
2
+ before_filter :authenticate_forem_user
3
+ before_filter :find_topic
4
+
5
+ def new
6
+ @post = @topic.posts.build
7
+ end
8
+
9
+ def create
10
+ @post = @topic.posts.build(params[:post])
11
+ if @post.save
12
+ flash[:notice] = t("forem.post.created")
13
+ redirect_to [@topic.forum, @topic]
14
+ else
15
+ params[:reply_to_id] = params[:post][:reply_to_id]
16
+ flash[:error] = t("forem.post.not_created")
17
+ render :action => "new"
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def find_topic
24
+ @topic = Forem::Topic.find(params[:topic_id])
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ class Forem::TopicsController < Forem::ApplicationController
2
+ before_filter :authenticate_forem_user, :except => [:show]
3
+ before_filter :find_forum
4
+
5
+ def show
6
+ @topic = @forum.topics.find(params[:id])
7
+ end
8
+
9
+ def new
10
+ @topic = @forum.topics.build
11
+ @topic.posts.build
12
+ end
13
+
14
+ def create
15
+ # Association builders are broken in edge Rails atm
16
+ # Hack our way around it
17
+ # TODO: Fix the hack
18
+ @topic = Forem::Topic.new(params[:topic])
19
+ @topic.user = current_user
20
+ @topic.forum_id = params[:forum_id]
21
+ if @topic.save
22
+ flash[:notice] = t("forem.topic.created")
23
+ redirect_to [@forum, @topic]
24
+ else
25
+ flash[:error] = t("forem.topic.not_created")
26
+ render :action => "new"
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def find_forum
33
+ @forum = Forem::Forum.find(params[:forum_id])
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module Forem
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ class Forem::Forum < ActiveRecord::Base
2
+ has_many :topics
3
+ has_many :posts, :through => :topics
4
+ end
@@ -0,0 +1,11 @@
1
+ class Forem::Post < ActiveRecord::Base
2
+ belongs_to :topic
3
+ belongs_to :user
4
+ belongs_to :reply_to, :class_name => "Post"
5
+
6
+ has_many :replies, :class_name => "Post",
7
+ :foreign_key => "reply_to_id",
8
+ :dependent => :nullify
9
+
10
+ validates :text, :presence => true
11
+ end
@@ -0,0 +1,17 @@
1
+ class Forem::Topic < ActiveRecord::Base
2
+ belongs_to :forum
3
+ belongs_to :user
4
+ has_many :posts
5
+ accepts_nested_attributes_for :posts
6
+
7
+ validates :subject, :presence => true
8
+
9
+ before_save :set_first_post_user
10
+
11
+ private
12
+
13
+ def set_first_post_user
14
+ post = self.posts.first
15
+ post.user = self.user
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ <ul class="forums listing">
2
+ <% @forums.each do |forum| %>
3
+ <li class="<%= cycle("odd", "even") %>">
4
+ <h2><%= link_to forum.title, forum_path(forum) %></h2>
5
+ <%= forum.description %>
6
+ <br>
7
+ <%= t("forem.forum.topics_count", :count => forum.topics.count) %> topics,
8
+ <%= t("forem.forum.posts_count", :count => forum.posts.count) %> posts
9
+ <br>
10
+ Last post was TIME AGO by NAME in TOPIC
11
+ </li>
12
+ <% end %>
13
+ </ul>
@@ -0,0 +1,3 @@
1
+ <div id='forum'>
2
+ <h2><%= @forum.title %></h2>
3
+ </div>
@@ -0,0 +1,4 @@
1
+ <%= f.input :text %>
2
+ <% if params[:reply_to_id] %>
3
+ <%= f.hidden_field :reply_to_id, :value => params[:reply_to_id] %>
4
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <a name='post-#{post.id}'></a>
2
+ <div id='post_<%= post.id %>' class='post'>
3
+ <div class='user'>
4
+ User: <%= post.user %>
5
+ </div>
6
+
7
+ <div class='actions'>
8
+ <% if current_user %>
9
+ <%= link_to "Reply", new_topic_post_path(@topic, :reply_to_id => post.id) %>
10
+ <% end %>
11
+ <% if post.reply_to %>
12
+ <%= link_to "In reply to #{post.reply_to.user}", "#post-#{post.reply_to.id}" %>
13
+ <% end %>
14
+ </div>
15
+
16
+ <div class='text'>
17
+ <%= post.text %>
18
+ </div>
19
+
20
+ </div>
@@ -0,0 +1,6 @@
1
+ <h2><%= t("forem.post.new") %></h2>
2
+
3
+ <%= simple_form_for [@topic, @post] do |f| %>
4
+ <%= render :partial => "form", :locals => { :f => f } %>
5
+ <%= f.submit t("forem.post.buttons.reply") %>
6
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <%= simple_form_for [@forum, @topic] do |f| %>
2
+ <%= f.input :subject %>
3
+
4
+ <%= f.simple_fields_for :posts do |post| %>
5
+ <%= render :partial => "forem/posts/form", :locals => { :f => post }%>
6
+ <% end %>
7
+
8
+ <%= f.submit %>
9
+ <% end %>