rostra 0.0.8 → 0.0.9
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.
- data/README.rdoc +10 -0
- data/app/assets/stylesheets/rostra/application.css +1 -1
- data/app/assets/stylesheets/rostra/forms.css +10 -0
- data/app/mailers/rostra/application_mailer.rb +15 -0
- data/app/models/comment.rb +5 -0
- data/app/models/rostra/answer.rb +13 -0
- data/app/models/rostra/question.rb +11 -1
- data/app/models/rostra/question_following.rb +6 -0
- data/app/views/rostra/answers/_form.html.erb +1 -0
- data/app/views/rostra/application_mailer/notification.html.erb +5 -0
- data/app/views/rostra/application_mailer/notification.text.erb +5 -0
- data/app/views/rostra/questions/_form.html.erb +1 -0
- data/db/migrate/20111019162723_create_rostra_question_followings.rb +10 -0
- data/lib/generators/rostra/templates/config/initializers/rostra.rb +3 -0
- data/lib/rostra/config.rb +4 -0
- data/lib/rostra/email_notifier.rb +21 -0
- data/lib/rostra/engine.rb +1 -0
- data/lib/rostra/version.rb +1 -1
- data/lib/rostra.rb +5 -2
- metadata +19 -2
data/README.rdoc
CHANGED
@@ -28,7 +28,17 @@ Call <tt>rostra</tt> in your user model:
|
|
28
28
|
rostra
|
29
29
|
end
|
30
30
|
|
31
|
+
== Basic configuration
|
32
|
+
There's some stuff you'll almost definitely want to do in order to get Rostra working correctly for your app. First, set the <tt>default_url_options</tt> for your app. In each of your <tt>config/environment</tt> files you should have something like:
|
31
33
|
|
34
|
+
config.action_mailer.default_url_options = { :host => 'test.com' } # test.rb
|
35
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' } # development.rb
|
36
|
+
config.action_mailer.default_url_options = { :host => 'your_domain.com' } # production.rb
|
37
|
+
|
38
|
+
Also, be sure to read through <tt>config/initializers/rostra.rb</tt> and override configuration options to suit your app. At the very least, you'll want to change:
|
39
|
+
|
40
|
+
config.deliver_emails_from = 'change_me@example.com'
|
41
|
+
`
|
32
42
|
== Customizing the question and answer models
|
33
43
|
Rostra provides a DSL for adding application specific logic to <tt>Rostra::Question</tt> and <tt>Rostra:Answer</tt>:
|
34
44
|
|
@@ -33,6 +33,16 @@ span.error {
|
|
33
33
|
top: 5px;
|
34
34
|
right: -5px;
|
35
35
|
}
|
36
|
+
|
37
|
+
.boolean label {
|
38
|
+
display: inline;
|
39
|
+
margin-left: 5px;
|
40
|
+
}
|
41
|
+
.boolean input[type="checkbox"] {
|
42
|
+
display: inline;
|
43
|
+
width: auto;
|
44
|
+
}
|
45
|
+
|
36
46
|
.field_with_errors input,
|
37
47
|
.field_with_errors textarea {
|
38
48
|
background: #fde6e4;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rostra
|
2
|
+
class ApplicationMailer < ActionMailer::Base
|
3
|
+
|
4
|
+
def notification(user, question)
|
5
|
+
@user = user
|
6
|
+
@question = question
|
7
|
+
mail(
|
8
|
+
:to => user.rostra_user_email,
|
9
|
+
:subject => "There's been activity on: #{question.title}",
|
10
|
+
:from => Rostra::Config.deliver_emails_from
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/app/models/comment.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Comment < ActiveRecord::Base
|
2
2
|
|
3
3
|
include ActsAsCommentable::Comment
|
4
|
+
include Rostra::EmailNotifier
|
4
5
|
|
5
6
|
belongs_to :commentable, :polymorphic => true
|
6
7
|
belongs_to :user
|
@@ -10,4 +11,8 @@ class Comment < ActiveRecord::Base
|
|
10
11
|
|
11
12
|
default_scope :order => 'created_at ASC'
|
12
13
|
|
14
|
+
def question
|
15
|
+
commentable.question if commentable.is_a?(Rostra::Answer)
|
16
|
+
end
|
17
|
+
|
13
18
|
end
|
data/app/models/rostra/answer.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Rostra
|
2
2
|
class Answer < ActiveRecord::Base
|
3
|
+
include Rostra::EmailNotifier
|
4
|
+
|
3
5
|
belongs_to :question
|
4
6
|
belongs_to :user
|
5
7
|
|
@@ -7,5 +9,16 @@ module Rostra
|
|
7
9
|
acts_as_commentable
|
8
10
|
|
9
11
|
validates :text, :presence => true
|
12
|
+
|
13
|
+
before_save :create_question_following
|
14
|
+
|
15
|
+
attr_accessor :follow_by_email
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def create_question_following
|
20
|
+
question.followers << user unless follow_by_email.to_i.zero?
|
21
|
+
end
|
22
|
+
|
10
23
|
end
|
11
24
|
end
|
@@ -3,6 +3,8 @@ module Rostra
|
|
3
3
|
|
4
4
|
belongs_to :user
|
5
5
|
has_many :answers
|
6
|
+
has_many :question_followings
|
7
|
+
has_many :followers, through: :question_followings, source: :user
|
6
8
|
|
7
9
|
acts_as_taggable
|
8
10
|
acts_as_voteable
|
@@ -12,13 +14,15 @@ module Rostra
|
|
12
14
|
validates :user, :presence => true
|
13
15
|
validates :tag_list, :presence => true
|
14
16
|
|
17
|
+
before_save :create_question_following
|
18
|
+
attr_accessor :follow_by_email
|
19
|
+
|
15
20
|
# Finds questions asked within the last 15 days ordered by non-unique page views.
|
16
21
|
#
|
17
22
|
def self.trending(limit = 5)
|
18
23
|
Question.where(created_at: (15.days.ago)..(Time.now)).limit(limit)
|
19
24
|
|
20
25
|
# This code doesn't work in postgres.
|
21
|
-
#
|
22
26
|
# Question
|
23
27
|
# .where(created_at: (15.days.ago)..(Time.now))
|
24
28
|
# .limit(limit)
|
@@ -35,5 +39,11 @@ module Rostra
|
|
35
39
|
impressionist_count(filter: :ip_address)
|
36
40
|
end
|
37
41
|
|
42
|
+
private
|
43
|
+
|
44
|
+
def create_question_following
|
45
|
+
followers << user unless follow_by_email.to_i.zero?
|
46
|
+
end
|
47
|
+
|
38
48
|
end
|
39
49
|
end
|
@@ -4,5 +4,6 @@
|
|
4
4
|
<%= f.hidden_field :user_id, value: rostra_user.id %>
|
5
5
|
<%= f.hidden_field :question_id, value: @question.id %>
|
6
6
|
<%= f.input :text, label: 'Answer this question', input_html: { class: 'wysiwyg' } %>
|
7
|
+
<%= f.input :follow_by_email, as: :boolean, input_html: { checked: true }, label: "I want to follow answers and comments on this question" %>
|
7
8
|
<%= f.submit @answer.new_record? ? 'Answer' : 'Update' %>
|
8
9
|
<% end %>
|
@@ -3,5 +3,6 @@
|
|
3
3
|
<%= f.input :title %>
|
4
4
|
<%= f.input :details, input_html: {class: 'wysiwyg'} %>
|
5
5
|
<%= f.input :tag_list, label: 'Tags', hint: 'Separate tags with commas' %>
|
6
|
+
<%= f.input :follow_by_email, as: :boolean, input_html: { checked: true }, label: "I want to follow answers and comments on this question" %>
|
6
7
|
<%= f.submit "Post your question" %>
|
7
8
|
<% end %>
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# Use this setup block to configure all options available in Rostra.
|
2
2
|
Rostra::Config.setup do |config|
|
3
|
+
# Helper method used to access current user in the view
|
4
|
+
# config.deliver_emails_from = 'change_me@example.com'
|
5
|
+
|
3
6
|
# Helper method used to access current user in the view
|
4
7
|
# config.rostra_user = :current_user
|
5
8
|
|
data/lib/rostra/config.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Rostra
|
2
2
|
module Config
|
3
|
+
# Helper method used to access current user in the view
|
4
|
+
mattr_accessor :deliver_emails_from
|
5
|
+
@@deliver_emails_from = 'change_me@example.com'
|
6
|
+
|
3
7
|
# Helper method used to access current user in the view
|
4
8
|
mattr_accessor :rostra_user
|
5
9
|
@@rostra_user = :current_user
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rostra
|
2
|
+
module EmailNotifier
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.after_create :notify_followers
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
# Send email notification to everyone who is following the question. Of course,
|
11
|
+
# don't send notification to the person that created the answer/comment.
|
12
|
+
#
|
13
|
+
def notify_followers
|
14
|
+
question.followers.each do |user|
|
15
|
+
next if self.user == user
|
16
|
+
ApplicationMailer.notification(user, question).deliver
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/rostra/engine.rb
CHANGED
data/lib/rostra/version.rb
CHANGED
data/lib/rostra.rb
CHANGED
@@ -18,9 +18,12 @@ module Rostra
|
|
18
18
|
# end
|
19
19
|
#
|
20
20
|
def rostra(&block)
|
21
|
-
has_many :questions
|
22
|
-
has_many :answers
|
21
|
+
has_many :questions, class_name: 'Rostra::Question'
|
22
|
+
has_many :answers, class_name: 'Rostra::Answer'
|
23
23
|
has_many :comments
|
24
|
+
has_many :question_followings, class_name: 'Rostra::QuestionFollowing'
|
25
|
+
has_many :followed_questions, through: :question_followings, class_name: 'Rostra::Question', source: :question
|
26
|
+
|
24
27
|
acts_as_voter
|
25
28
|
|
26
29
|
include InstanceMethods
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rostra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Cory Schires
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-10-
|
13
|
+
date: 2011-10-19 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -200,6 +200,17 @@ dependencies:
|
|
200
200
|
version: "0"
|
201
201
|
type: :development
|
202
202
|
version_requirements: *id017
|
203
|
+
- !ruby/object:Gem::Dependency
|
204
|
+
name: email_spec
|
205
|
+
prerelease: false
|
206
|
+
requirement: &id018 !ruby/object:Gem::Requirement
|
207
|
+
none: false
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: "0"
|
212
|
+
type: :development
|
213
|
+
version_requirements: *id018
|
203
214
|
description: Don't use. Not production ready
|
204
215
|
email:
|
205
216
|
- coryschires@gmail.com
|
@@ -479,16 +490,20 @@ files:
|
|
479
490
|
- app/controllers/rostra/comments_controller.rb
|
480
491
|
- app/controllers/rostra/questions_controller.rb
|
481
492
|
- app/helpers/rostra/application_helper.rb
|
493
|
+
- app/mailers/rostra/application_mailer.rb
|
482
494
|
- app/models/comment.rb
|
483
495
|
- app/models/rostra/ability.rb
|
484
496
|
- app/models/rostra/answer.rb
|
485
497
|
- app/models/rostra/question.rb
|
498
|
+
- app/models/rostra/question_following.rb
|
486
499
|
- app/models/rostra/vote.rb
|
487
500
|
- app/models/vote.rb
|
488
501
|
- app/views/layouts/rostra/application.html.erb
|
489
502
|
- app/views/rostra/answers/_form.html.erb
|
490
503
|
- app/views/rostra/answers/edit.html.erb
|
491
504
|
- app/views/rostra/answers/vote.js.erb
|
505
|
+
- app/views/rostra/application_mailer/notification.html.erb
|
506
|
+
- app/views/rostra/application_mailer/notification.text.erb
|
492
507
|
- app/views/rostra/questions/_form.html.erb
|
493
508
|
- app/views/rostra/questions/edit.html.erb
|
494
509
|
- app/views/rostra/questions/index.html.erb
|
@@ -509,9 +524,11 @@ files:
|
|
509
524
|
- db/migrate/20111008224511_thumbs_up_migration.rb
|
510
525
|
- db/migrate/20111012020025_create_comments.rb
|
511
526
|
- db/migrate/20111016021105_create_impressions_table.rb
|
527
|
+
- db/migrate/20111019162723_create_rostra_question_followings.rb
|
512
528
|
- lib/generators/rostra/install_generator.rb
|
513
529
|
- lib/generators/rostra/templates/config/initializers/rostra.rb
|
514
530
|
- lib/rostra/config.rb
|
531
|
+
- lib/rostra/email_notifier.rb
|
515
532
|
- lib/rostra/engine.rb
|
516
533
|
- lib/rostra/version.rb
|
517
534
|
- lib/rostra.rb
|