kublog 0.0.1.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/.gitignore +4 -5
  2. data/.rspec +2 -0
  3. data/Gemfile +3 -1
  4. data/Gemfile.lock +89 -77
  5. data/README.rdoc +102 -61
  6. data/Rakefile +5 -10
  7. data/app/assets/javascripts/kublog/email.js.coffee +24 -9
  8. data/app/assets/javascripts/kublog/posts.js.coffee +46 -19
  9. data/app/assets/javascripts/kublog/shared.js.coffee.erb +1 -1
  10. data/app/assets/javascripts/kublog/wysiwyg.controls.js.coffee +0 -1
  11. data/app/assets/plugins/kublog/ajaxyupload/javascripts/jquery.ajaxyupload.js +1 -1
  12. data/app/assets/stylesheets/kublog/posts.css +2 -2
  13. data/app/controllers/kublog/application_controller.rb +18 -2
  14. data/app/controllers/kublog/categories_controller.rb +2 -2
  15. data/app/controllers/kublog/notifications_controller.rb +13 -0
  16. data/app/controllers/kublog/posts_controller.rb +7 -18
  17. data/app/helpers/kublog/application_helper.rb +15 -0
  18. data/app/helpers/kublog/notifications_helper.rb +4 -0
  19. data/app/helpers/kublog/posts_helper.rb +4 -0
  20. data/app/jobs/kublog/deliver_comment.rb +14 -0
  21. data/app/mailers/kublog/comment_mailer.rb +11 -0
  22. data/app/mailers/kublog/post_mailer.rb +4 -5
  23. data/app/models/kublog/category.rb +13 -5
  24. data/app/models/kublog/comment.rb +17 -6
  25. data/app/models/kublog/notification.rb +27 -0
  26. data/app/models/kublog/post.rb +11 -6
  27. data/app/presenters/kublog/post_form_presenter.rb +19 -0
  28. data/app/presenters/kublog/posts_presenter.rb +7 -1
  29. data/app/uploaders/kublog/file_uploader.rb +0 -3
  30. data/app/views/kublog/comment_mailer/new_comment.html.erb +11 -0
  31. data/app/views/kublog/post_mailer/new_post.html.erb +1 -1
  32. data/app/views/kublog/post_mailer/new_post.liquid.html.erb +9 -1
  33. data/app/views/kublog/posts/_email_form.html.erb +27 -9
  34. data/app/views/kublog/posts/_facebook_form.html.erb +10 -0
  35. data/app/views/kublog/posts/_form.html.erb +7 -45
  36. data/app/views/kublog/posts/_twitter_form.html.erb +11 -0
  37. data/app/views/kublog/posts/edit.html.erb +1 -1
  38. data/app/views/kublog/posts/index.atom.builder +1 -2
  39. data/app/views/kublog/posts/index.rss.builder +20 -0
  40. data/app/views/kublog/posts/new.html.erb +1 -1
  41. data/config/locales/kublog/en.yml +9 -0
  42. data/config/routes.rb +8 -0
  43. data/db/migrate/20110816211552_create_kublog_posts.rb +1 -9
  44. data/db/migrate/20110901205127_create_kublog_notifications.rb +18 -0
  45. data/index.html +10 -0
  46. data/kublog.gemspec +10 -10
  47. data/lib/generators/kublog/install/USAGE +8 -0
  48. data/lib/generators/kublog/install/install_generator.rb +78 -0
  49. data/lib/generators/kublog/install/templates/configuration.rb.tt +45 -0
  50. data/lib/kublog.rb +43 -13
  51. data/lib/kublog/author.rb +2 -3
  52. data/lib/kublog/engine.rb +1 -0
  53. data/lib/kublog/network/email.rb +113 -0
  54. data/lib/kublog/network/facebook.rb +54 -0
  55. data/lib/kublog/network/twitter.rb +55 -0
  56. data/lib/kublog/notifiable.rb +2 -5
  57. data/lib/kublog/processor.rb +27 -0
  58. data/lib/kublog/version.rb +2 -2
  59. data/script/rails +1 -1
  60. data/{test → spec}/dummy/Rakefile +0 -0
  61. data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -0
  62. data/{test → spec}/dummy/app/assets/javascripts/sessions.js +0 -0
  63. data/{test → spec}/dummy/app/assets/javascripts/users.js +0 -0
  64. data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
  65. data/{test → spec}/dummy/app/assets/stylesheets/sessions.css +0 -0
  66. data/{test → spec}/dummy/app/assets/stylesheets/users.css +0 -0
  67. data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
  68. data/{test → spec}/dummy/app/controllers/sessions_controller.rb +0 -0
  69. data/{test → spec}/dummy/app/controllers/users_controller.rb +0 -0
  70. data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
  71. data/{test → spec}/dummy/app/helpers/error_messages_helper.rb +0 -0
  72. data/{test → spec}/dummy/app/helpers/layout_helper.rb +0 -0
  73. data/{test → spec}/dummy/app/helpers/sessions_helper.rb +0 -0
  74. data/{test → spec}/dummy/app/helpers/users_helper.rb +0 -0
  75. data/{test → spec}/dummy/app/mailers/.gitkeep +0 -0
  76. data/{test → spec}/dummy/app/models/.gitkeep +0 -0
  77. data/{test → spec}/dummy/app/models/ability.rb +0 -0
  78. data/{test → spec}/dummy/app/models/user.rb +1 -5
  79. data/{test → spec}/dummy/app/views/layouts/_account.html.erb +0 -0
  80. data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
  81. data/{test → spec}/dummy/app/views/layouts/kublog/application.html.erb +0 -0
  82. data/{test → spec}/dummy/app/views/sessions/new.html.erb +0 -0
  83. data/{test → spec}/dummy/app/views/users/new.html.erb +0 -0
  84. data/{test → spec}/dummy/config.ru +0 -0
  85. data/{test → spec}/dummy/config/application.rb +0 -0
  86. data/{test → spec}/dummy/config/boot.rb +0 -0
  87. data/{test → spec}/dummy/config/database.yml +0 -0
  88. data/{test → spec}/dummy/config/environment.rb +0 -0
  89. data/{test → spec}/dummy/config/environments/development.rb +0 -0
  90. data/{test → spec}/dummy/config/environments/production.rb +0 -0
  91. data/{test → spec}/dummy/config/environments/test.rb +0 -0
  92. data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  93. data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  94. data/spec/dummy/config/initializers/kublog.rb +34 -0
  95. data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
  96. data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
  97. data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
  98. data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
  99. data/{test → spec}/dummy/config/locales/en.yml +9 -0
  100. data/{test → spec}/dummy/config/routes.rb +0 -0
  101. data/{test → spec}/dummy/db/migrate/20110816225222_create_users.rb +1 -0
  102. data/{test → spec}/dummy/db/migrate/20110819135547_create_delayed_jobs.rb +0 -0
  103. data/{test → spec}/dummy/db/schema.rb +16 -10
  104. data/{test → spec}/dummy/lib/assets/.gitkeep +0 -0
  105. data/{test → spec}/dummy/log/.gitkeep +0 -0
  106. data/{test → spec}/dummy/public/404.html +0 -0
  107. data/{test → spec}/dummy/public/422.html +0 -0
  108. data/{test → spec}/dummy/public/500.html +0 -0
  109. data/{test → spec}/dummy/public/favicon.ico +0 -0
  110. data/{test → spec}/dummy/script/delayed_job +0 -0
  111. data/{test → spec}/dummy/script/rails +0 -0
  112. data/spec/factories.rb +54 -0
  113. data/spec/fixtures/Adrian.png +0 -0
  114. data/spec/fixtures/rendered_email.html +15 -0
  115. data/spec/lib/author_spec.rb +25 -0
  116. data/spec/lib/network/email_spec.rb +113 -0
  117. data/spec/lib/network/facebook_spec.rb +68 -0
  118. data/spec/lib/network/twitter_spec.rb +68 -0
  119. data/spec/lib/notifiable_spec.rb +23 -0
  120. data/spec/lib/processor_spec.rb +25 -0
  121. data/spec/models/kublog/category_spec.rb +43 -0
  122. data/spec/models/kublog/comment_spec.rb +56 -0
  123. data/spec/models/kublog/image_spec.rb +37 -0
  124. data/spec/models/kublog/notification_spec.rb +53 -0
  125. data/spec/models/kublog/post_spec.rb +63 -0
  126. data/spec/spec_helper.rb +43 -0
  127. metadata +198 -208
  128. data/app/assets/stylesheets/kublog/categories.css +0 -4
  129. data/app/assets/stylesheets/kublog/comments.css +0 -4
  130. data/lib/kublog/notification/email.rb +0 -86
  131. data/lib/kublog/notification/email_job.rb +0 -14
  132. data/lib/kublog/notification/fb_post.rb +0 -43
  133. data/lib/kublog/notification/fb_post_job.rb +0 -16
  134. data/lib/kublog/notification/tweet.rb +0 -68
  135. data/lib/kublog/notification/tweet_job.rb +0 -16
  136. data/test/dummy/test/fixtures/users.yml +0 -9
  137. data/test/dummy/test/functional/sessions_controller_test.rb +0 -7
  138. data/test/dummy/test/functional/users_controller_test.rb +0 -7
  139. data/test/dummy/test/unit/helpers/sessions_helper_test.rb +0 -4
  140. data/test/dummy/test/unit/helpers/users_helper_test.rb +0 -4
  141. data/test/dummy/test/unit/user_test.rb +0 -7
  142. data/test/factories.rb +0 -9
  143. data/test/fixtures/kublog/categories.yml +0 -7
  144. data/test/fixtures/kublog/comments.yml +0 -7
  145. data/test/fixtures/kublog/images.yml +0 -9
  146. data/test/fixtures/kublog/posts.yml +0 -9
  147. data/test/functional/kublog/categories_controller_test.rb +0 -9
  148. data/test/functional/kublog/comments_controller_test.rb +0 -9
  149. data/test/functional/kublog/images_controller_test.rb +0 -9
  150. data/test/functional/kublog/post_mailer_test.rb +0 -9
  151. data/test/functional/kublog/posts_controller_test.rb +0 -9
  152. data/test/integration/navigation_test.rb +0 -10
  153. data/test/kublog_test.rb +0 -7
  154. data/test/test_helper.rb +0 -12
  155. data/test/unit/helpers/kublog/categories_helper_test.rb +0 -6
  156. data/test/unit/helpers/kublog/comments_helper_test.rb +0 -6
  157. data/test/unit/helpers/kublog/images_helper_test.rb +0 -6
  158. data/test/unit/helpers/kublog/posts_helper_test.rb +0 -6
  159. data/test/unit/kublog/category_test.rb +0 -9
  160. data/test/unit/kublog/comment_test.rb +0 -9
  161. data/test/unit/kublog/image_test.rb +0 -9
  162. data/test/unit/kublog/post_test.rb +0 -19
@@ -1,4 +0,0 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
@@ -1,4 +0,0 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
@@ -1,86 +0,0 @@
1
- # This class includes the interface to all the different
2
- # Delivery methods and requires the one that the user chose
3
- # in the configuration File
4
-
5
- module Kublog
6
- module Notification
7
- module Email
8
-
9
- # Sets callbacks for E-mail delivery
10
- # Includes necessary methods for e-mail notification callback
11
- # and requires appropriate method of notification (Immediate, Delayed Job..)
12
- def self.included(base)
13
-
14
- base.send :after_create, :notify_email
15
- base.send :before_validation, :build_email_body, :on => :create
16
-
17
- base.send :include, case Kublog.notification_processing.try(:to_sym)
18
- when :delayed_job then DelayedJob
19
- else Immediate
20
- end
21
-
22
- base.send :include, InstanceMethods
23
-
24
- # Defines a for_x type of method for each user kind
25
- # Designed to interface with the user to selectively deliver E-mails
26
- Kublog.user_kinds.each do |user_kind|
27
- define_method "for_#{user_kind}?" do
28
- self.intended_for.include?(user_kind)
29
- end
30
- end
31
- end
32
-
33
- module InstanceMethods
34
-
35
- # Called to notify users after the creation of a post
36
- # probably should happen after publication
37
- def notify_email
38
- klass = user.class
39
- if klass.try(:kublog_notifiable) && self.email_notify
40
- notifications_sent = 0
41
- klass.find_each do |user|
42
- if user.notify_post?(self)
43
- post_deliver(self, user)
44
- notifications_sent += 1
45
- end
46
- end
47
- self.update_attribute :users_notified, notifications_sent
48
- end
49
- end
50
-
51
- protected
52
-
53
- # Opens the ERB and Liquid Template set in the mailer view folders
54
- # sets the context variables and processes them before to remove erb section
55
- def build_email_body
56
- if self.email_body.blank? && !Sanitize.clean(self.body).blank?
57
- template_path = "app/views/kublog/post_mailer/new_post.liquid.html.erb"
58
- template = File.open(File.join(Rails.root, template_path))
59
- read_erb_template(template)
60
- end
61
- end
62
-
63
- def read_erb_template(template)
64
- post = self
65
- self.email_body = ERB.new(template.read).result(binding)
66
- end
67
-
68
- end
69
-
70
- # Queues Process on DJ
71
- module DelayedJob
72
- def post_deliver(post, user)
73
- Delayed::Job.enqueue(EmailJob.new(post, user))
74
- end
75
- end
76
-
77
- # Delivers Immediately
78
- module Immediate
79
- def post_deliver(post,user)
80
- PostMailer.new_post(post,user).deliver
81
- end
82
- end
83
-
84
- end
85
- end
86
- end
@@ -1,14 +0,0 @@
1
- # Class configured to Notify via DelayedJob
2
- module Kublog
3
- module Notification
4
- class EmailJob
5
- def initialize(post, user)
6
- @post, @user = post, user
7
- end
8
-
9
- def perform
10
- PostMailer.new_post(@post, @user).deliver
11
- end
12
- end
13
- end
14
- end
@@ -1,43 +0,0 @@
1
- module Kublog
2
- module Notification
3
- module FbPost
4
-
5
- def self.included(base)
6
- base.send :include, InstanceMethods
7
-
8
- base.send :include, case Kublog.notification_processing.try(:to_sym)
9
- when :delayed_job then DelayedJob
10
- else Immediate
11
- end
12
-
13
- base.send :after_create, :notify_facebook
14
- base.send :validates_presence_of, :facebook_text, :if => :facebook_notify
15
- end
16
-
17
- module InstanceMethods
18
-
19
- protected
20
-
21
- def notify_facebook
22
- if self.facebook_notify
23
- wall_post_deliver(:link => self.url, :message => self.facebook_text)
24
- end
25
- end
26
-
27
- end
28
-
29
- module DelayedJob
30
- def wall_post_deliver(elements={})
31
- Delayed::Job.enqueue(FbPostJob.new(elements))
32
- end
33
- end
34
-
35
- module Immediate
36
- def wall_post_deliver(elements={})
37
- Kublog.facebook_client.link!(elements)
38
- end
39
- end
40
-
41
- end
42
- end
43
- end
@@ -1,16 +0,0 @@
1
- # Class configured to Notify via DelayedJob
2
- module Kublog
3
- module Notification
4
- class FbPostJob
5
-
6
- def initialize(elements={})
7
- @elements = elements
8
- end
9
-
10
- def perform
11
- Kublog.facebook_client.link!(@elements)
12
- end
13
-
14
- end
15
- end
16
- end
@@ -1,68 +0,0 @@
1
- # Includes functionality to send to twitter on after_create callback
2
-
3
- module Kublog
4
- module Notification
5
- module Tweet
6
-
7
- def self.included(base)
8
- base.send :include, InstanceMethods
9
- base.send :extend, ClassMethods
10
-
11
- base.send :include, case Kublog.notification_processing.try(:to_sym)
12
- when :delayed_job then DelayedJob
13
- else Immediate
14
- end
15
-
16
- base.send :after_create, :notify_tweet
17
- base.send :validates_presence_of, :tweet_text, :if => :twitter_notify
18
- end
19
-
20
- module InstanceMethods
21
-
22
- protected
23
-
24
- def notify_tweet
25
- if self.twitter_notify
26
- tweet_deliver([self.tweet_text, self.url].join(' '))
27
- end
28
- end
29
-
30
- end
31
- end
32
-
33
- module ClassMethods
34
-
35
- # TODO Find out more about Twitter::NotFound()
36
- # Configure whether or not to send errors
37
- def safe_twitter_update(update, post)
38
- begin
39
- return Kublog.twitter_client.update(update)
40
- rescue Twitter::NotFound
41
- latest_tweet = Kublog.twitter_client.user_timeline.first
42
- if latest_tweet.text.gsub(/ http:\/\/[^ ]\Z/, '') == post.tweet_text
43
- return latest_tweet
44
- else
45
- return {:id => nil, :text => post.tweet_text}
46
- end
47
- end
48
- end
49
-
50
- end
51
-
52
- # Queues Process on DJ
53
- module DelayedJob
54
- def tweet_deliver(tweet)
55
- Delayed::Job.enqueue(TweetJob.new(tweet, self))
56
- end
57
- end
58
-
59
- # Delivers Immediately
60
- module Immediate
61
- def tweet_deliver(tweet)
62
- response = safe_twitter_update(tweet, self)
63
- self.update_attributes :tweet_id => response.id, :tweet_text => response.text
64
- end
65
- end
66
-
67
- end
68
- end
@@ -1,16 +0,0 @@
1
- # Class configured to Notify via DelayedJob
2
- module Kublog
3
- module Notification
4
- class TweetJob
5
-
6
- def initialize(tweet, post)
7
- @tweet, @post = tweet, post
8
- end
9
-
10
- def perform
11
- Post.safe_twitter_update(@tweet, @post)
12
- end
13
-
14
- end
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- email: MyString
5
- password_digest: MyString
6
-
7
- two:
8
- email: MyString
9
- password_digest: MyString
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SessionsControllerTest < ActionController::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UsersControllerTest < ActionController::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SessionsHelperTest < ActionView::TestCase
4
- end
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UsersHelperTest < ActionView::TestCase
4
- end
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UserTest < ActiveSupport::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,9 +0,0 @@
1
- Factory.define :post, :class => Kublog::Post do |f|
2
- f.title 'Nuevos features'
3
- f.body 'Este mes estuvimos trabajando en nuevos features...'
4
- f.user_id 1
5
- end
6
-
7
- Factory.define :category :class=> Kublo::Category do |f|
8
- f.name 'Nuevos Features'
9
- end
@@ -1,7 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- name: MyString
5
-
6
- two:
7
- name: MyString
@@ -1,7 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- body: MyText
5
-
6
- two:
7
- body: MyText
@@ -1,9 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- name: MyString
5
- file: MyString
6
-
7
- two:
8
- name: MyString
9
- file: MyString
@@ -1,9 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- title: MyString
5
- body: MyText
6
-
7
- two:
8
- title: MyString
9
- body: MyText
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Kublog
4
- class CategoriesControllerTest < ActionController::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Kublog
4
- class CommentsControllerTest < ActionController::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Kublog
4
- class ImagesControllerTest < ActionController::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Kublog
4
- class PostMailerTest < ActionMailer::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Kublog
4
- class PostsControllerTest < ActionController::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NavigationTest < ActionDispatch::IntegrationTest
4
- fixtures :all
5
-
6
- # test "the truth" do
7
- # assert true
8
- # end
9
- end
10
-
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class KublogTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Kublog
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
3
-
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
6
- require 'factory_girl'
7
- require 'factories'
8
-
9
- Rails.backtrace_cleaner.remove_silencers!
10
-
11
- # Load support files
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }