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
@@ -19,18 +19,18 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # Runtime dependencies
22
- s.add_runtime_dependency "rails", '~>3.1.0.rc5'
23
- s.add_runtime_dependency "jquery-rails", '~>1.0.13'
24
- s.add_runtime_dependency 'coffee-script', '~>2.2.0'
25
- s.add_runtime_dependency "friendly_id", "~> 4.0.0.beta8"
26
- s.add_runtime_dependency "sanitize", '~>2.0.3'
22
+ s.add_runtime_dependency "rails", '>=3.1.0'
23
+ s.add_runtime_dependency "jquery-rails", '>=1.0.13'
24
+ s.add_runtime_dependency 'coffee-script', '>=2.2.0'
25
+ s.add_runtime_dependency "friendly_id", ">= 4.0.0.beta14"
26
+ s.add_runtime_dependency "sanitize"
27
27
 
28
28
  # This gems should stop being dependencies but optional with certain features
29
- s.add_runtime_dependency "rmagick", '~>2.13.1'
30
- s.add_runtime_dependency "carrierwave", '~>0.5.7'
31
- s.add_runtime_dependency 'liquid', '~>2.2.2'
32
- s.add_runtime_dependency 'twitter', '~>1.6.2'
33
- s.add_runtime_dependency 'fb_graph', '~>1.9.5'
29
+ s.add_runtime_dependency "rmagick"
30
+ s.add_runtime_dependency "carrierwave"
31
+ s.add_runtime_dependency 'liquid'
32
+ s.add_runtime_dependency 'twitter'
33
+ s.add_runtime_dependency 'fb_graph'
34
34
 
35
35
  # Development dependencies
36
36
  s.add_development_dependency "factory_girl_rails"
@@ -0,0 +1,8 @@
1
+ Description:
2
+ This generator will create all the necessary files to use and customize Kublog.
3
+
4
+ Example:
5
+ rails generate install kublog
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,78 @@
1
+ module Kublog
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+ source_root File.expand_path(Engine.root, __FILE__)
6
+
7
+ class_option :coffee, :type => :boolean, :default => false, :desc => 'Generates Kublogs coffeescripts'
8
+
9
+ ## Generates migrations to make all installation in one step
10
+ def generate_migrations
11
+ Dir[File.join(source_paths, 'db', 'migrate', '*.rb')].each do |file|
12
+ migration_filepath = file.match(/\A.+\/(db\/migrate\/.+)\Z/i)[1]
13
+ raw_migration_filename = file.match(/\d+\_(.+)\Z/i)[1]
14
+ migration_template migration_filepath, "db/migrate/#{raw_migration_filename}"
15
+ end
16
+ end
17
+
18
+ ## Generates the controller needed for user integration
19
+ def generate_kublog_controller
20
+ copy_file "app/controllers/kublog/application_controller.rb"
21
+ end
22
+
23
+ ## Generates all html views to the users app. Does not copy RSS
24
+ def generate_html_views
25
+ selective_copy 'app/views/kublog/posts/*.html.erb'
26
+ end
27
+
28
+ ## Generates all email views to the users app
29
+ def generate_email_views
30
+ directory "app/views/kublog/post_mailer"
31
+ end
32
+
33
+ def generate_layout
34
+ directory 'app/views/layouts/kublog'
35
+ end
36
+
37
+ def generate_css
38
+ directory 'app/assets/stylesheets/kublog'
39
+ end
40
+
41
+ def generate_configuration
42
+ copy_file template_path('configuration.rb.tt'), 'config/initializers/kublog.rb'
43
+ end
44
+
45
+ def generate_localization
46
+ copy_file "config/locales/kublog/en.yml"
47
+ end
48
+
49
+ ## Optionally copies javascript files
50
+ def generate_coffee
51
+ if options.coffee?
52
+ directory "app/assets/javascripts/kublog"
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def self.next_migration_number(path)
59
+ @seconds = @seconds.nil? ? Time.now.sec : (@seconds.to_i + 1)
60
+ @seconds = "0#{@seconds.to_s}" if @seconds < 10
61
+ Time.now.utc.strftime("%Y%m%d%H%M") + @seconds.to_s
62
+ end
63
+
64
+ ## Copies files in a directory filtering them with a given extension
65
+ def selective_copy(directory, &block)
66
+ Dir[File.join(source_paths, directory)].each do |filename|
67
+ file = filename.to_s.gsub("#{Engine.root.to_s}/", '')
68
+ copy_file file
69
+ end
70
+ end
71
+
72
+ def template_path(file)
73
+ File.join(File.expand_path(__FILE__), '..', 'templates', file)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,45 @@
1
+ Kublog.setup do |config|
2
+
3
+ ## General Configuration
4
+ ##
5
+ config.blog_name = 'Your Blog Name Here'
6
+ config.blog_description = 'Description of your blog here'
7
+ config.default_url_options = {:host => 'www.example.com'}
8
+
9
+ ## Segment E-mail notifications
10
+ ##
11
+ ## Uncomment to segment users notified
12
+ ## config.user_kinds = %w(paying_customers free_loaders)
13
+
14
+ config.author_email 'kublog@kublog.com'
15
+
16
+ ## Twitter Sharing Settings
17
+ ##
18
+ ## config.twitter do |twitter|
19
+ ## twitter.consumer_key = 'your-consumer-key'
20
+ ## twitter.consumer_secret = 'your-consumer-secret'
21
+ ## twitter.oauth_token = 'your-oauth-token'
22
+ ## twitter.oauth_token_secret = 'your-consumer-secret'
23
+ ## end
24
+
25
+ ## Facebook Sharing Setting
26
+ ## It's sort of trick to find this, check docs at github.com/innku/kublog
27
+ ##
28
+ ## config.facebook_page_token = 'your-page-token'
29
+
30
+
31
+ ## Notification processing
32
+ ##
33
+ ## config.notification_processing = {:development => :delayed_job,
34
+ ## :test => :immediate,
35
+ ## :staging => :delayed_job,
36
+ ## :production => :delayed_job }[Rails.env.to_sym]
37
+
38
+ ## Image Storage Configuration
39
+ ##
40
+ ## config.image_storage = {:development => :file,
41
+ ## :test => :file,
42
+ ## :staging => :s3,
43
+ ## :production => :s3}[Rails.env.to_sym]\
44
+
45
+ end
@@ -5,9 +5,9 @@ require "twitter"
5
5
  require "fb_graph"
6
6
  require "friendly_id"
7
7
  require "carrierwave"
8
- require "rmagick"
9
- require "sanitize"
8
+ require "RMagick"
10
9
  require "liquid"
10
+ require "sanitize"
11
11
 
12
12
  require "kublog/engine"
13
13
  require "kublog/version"
@@ -16,14 +16,12 @@ module Kublog
16
16
 
17
17
  autoload :Notifiable, 'kublog/notifiable'
18
18
  autoload :Author, 'kublog/author'
19
+ autoload :Processor, 'kublog/processor'
19
20
 
20
- module Notification
21
- autoload :Email, 'kublog/notification/email'
22
- autoload :EmailJob, 'kublog/notification/email_job'
23
- autoload :Tweet, 'kublog/notification/tweet'
24
- autoload :TweetJob, 'kublog/notification/tweet_job'
25
- autoload :FbPost, 'kublog/notification/fb_post'
26
- autoload :FbPostJob, 'kublog/notification/fb_post_job'
21
+ module Network
22
+ autoload :Email, 'kublog/network/email'
23
+ autoload :Facebook, 'kublog/network/facebook'
24
+ autoload :Twitter, 'kublog/network/twitter'
27
25
  end
28
26
 
29
27
  module XhrUpload
@@ -42,7 +40,7 @@ module Kublog
42
40
  @@user_kinds = []
43
41
 
44
42
  mattr_reader :notification_processing
45
- @@notification_processing = :immediately
43
+ @@notification_processing = :immediate
46
44
 
47
45
  mattr_accessor :image_storage
48
46
  @@image_storage = :file
@@ -50,6 +48,9 @@ module Kublog
50
48
  mattr_accessor :author_class
51
49
  @@author_class = 'User'
52
50
 
51
+ mattr_accessor :notify_class
52
+ @@notify_class = 'User'
53
+
53
54
  def self.notification_processing=(method='')
54
55
  @@notification_processing = method.to_sym
55
56
  if @@notification_processing == :delayed_job
@@ -59,6 +60,24 @@ module Kublog
59
60
  end
60
61
  end
61
62
 
63
+ def self.email_from(post)
64
+ if defined?(@@from_action)
65
+ @@from_action.yield(post)
66
+ elsif defined?(@@from_string)
67
+ @@from_string
68
+ else
69
+ 'Change Me Now Kublog<test@kublog.com>'
70
+ end
71
+ end
72
+
73
+ def self.author_email(email='', &block)
74
+ if block_given?
75
+ @@from_action = block
76
+ else
77
+ @@from_string = email
78
+ end
79
+ end
80
+
62
81
  KublogTwitter = Twitter.clone
63
82
  mattr_accessor :twitter_client
64
83
  @@twitter_client = KublogTwitter::Client.new
@@ -67,6 +86,9 @@ module Kublog
67
86
 
68
87
  mattr_accessor :blog_name
69
88
  @@blog_name = 'Kublog::Blog'
89
+
90
+ mattr_accessor :blog_description
91
+ @@blog_description = 'Some blog'
70
92
 
71
93
  def self.facebook_page_token=(token)
72
94
  @@facebook_client = FbGraph::User.me(token)
@@ -77,16 +99,24 @@ module Kublog
77
99
  end
78
100
 
79
101
  def self.twitter
102
+ @@twitter_config = true
80
103
  yield @@twitter_client
81
104
  end
82
105
 
83
- def self.asset_path(path)
84
- ["/assets", self.root_path , path].join
106
+ def self.facebook?
107
+ @@facebook_client.present?
108
+ end
109
+
110
+ def self.twitter?
111
+ defined? @@twitter_config
112
+ end
113
+
114
+ def self.email?
115
+ Kublog.notify_class.present?
85
116
  end
86
117
 
87
118
  def self.root_path
88
119
  Engine.routes.url_helpers.root_path
89
120
  end
90
121
 
91
-
92
122
  end
@@ -1,6 +1,5 @@
1
- # Module to be included in user that enables him to be
2
- # published in Posts
3
-
1
+ # Include module in the model to be referenced as author in the post
2
+ # Gives the author an association to every post he has published
4
3
  module Kublog
5
4
  module Author
6
5
 
@@ -1,3 +1,4 @@
1
+ ## Sets up the engine with an isolated namespace
1
2
  module Kublog
2
3
  class Engine < Rails::Engine
3
4
  isolate_namespace Kublog
@@ -0,0 +1,113 @@
1
+ # Sets up email delivery method for the notification model
2
+ # Includes validations of non blank email content
3
+
4
+ module Kublog
5
+ module Network
6
+ module Email
7
+
8
+ TEMPLATE = "app/views/kublog/post_mailer/new_post.liquid.html.erb"
9
+
10
+ def self.included(base)
11
+ base.send :include, InstanceMethods
12
+ base.send :extend, ClassMethods
13
+ base.send :validate, :valid_email_content, :if => :email?
14
+ end
15
+
16
+ module InstanceMethods
17
+
18
+ # Calls appropriate processor to process e-mail sending to the
19
+ # bulk of users
20
+ def deliver_email
21
+ Processor.work(BulkEmail.new(self))
22
+ end
23
+
24
+ # Never send e-mail notification by default
25
+ def default_email
26
+ false
27
+ end
28
+
29
+ # Returns true if notification acts as e-mail
30
+ def email?
31
+ self.kind == 'email'
32
+ end
33
+
34
+ def delivered
35
+ self.times_delivered ||= 0
36
+ self.update_attribute :times_delivered, (self.times_delivered + 1)
37
+ end
38
+
39
+ private
40
+
41
+ def valid_email_content
42
+ errors.add(:content, :email) if self.content.blank?
43
+ end
44
+
45
+ end
46
+
47
+ module ClassMethods
48
+
49
+ # Renders a preview of the e-mail that will be sent to the user
50
+ # so that the Author can edit the content of the e-mail on a Liquid Template
51
+ def email_template(post)
52
+ ERB.new(email_erb_template.read).result(binding)
53
+ end
54
+
55
+ private
56
+
57
+ def email_erb_template
58
+ if File.exists?(File.join(Rails.root, TEMPLATE))
59
+ File.open(File.join(Rails.root, TEMPLATE))
60
+ else
61
+ File.open(File.join(Engine.root, TEMPLATE))
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ class BulkEmail
68
+
69
+ def initialize(notification)
70
+ @notification = notification
71
+ @post = notification.post
72
+ end
73
+
74
+ # Processes sending email to bunch of users if appropriate
75
+ # calls notify_post? on every user to determine whether or not
76
+ # to send e-mail
77
+ def perform
78
+ klass = eval(Kublog.notify_class)
79
+ klass.all.each do |user|
80
+ if user.notify_post?(@notification.roles)
81
+ Processor.work(SingleEmail.new(@notification, user))
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ class SingleEmail
89
+
90
+ attr_accessor :subject, :body, :post, :url
91
+
92
+ def initialize(notification, user)
93
+ @subject = notification.title
94
+ @notification = notification
95
+ @body = notification.content
96
+ @post = notification.post
97
+ @url = notification.url
98
+ @user = user
99
+ end
100
+
101
+ # Sends a single e-mail to the user
102
+ def perform
103
+ PostMailer.new_post(self, @post, @user).deliver
104
+ @notification.delivered
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
111
+
112
+ end
113
+ end
@@ -0,0 +1,54 @@
1
+ module Kublog
2
+ module Network
3
+ module Facebook
4
+
5
+ def self.included(base)
6
+ base.send :include, InstanceMethods
7
+ base.send :validate, :valid_facebook_content, :if => :facebook?
8
+ end
9
+
10
+ module InstanceMethods
11
+
12
+ # Calls the appropriate processor on create callback
13
+ # Posts on the fan page wall a link to the post
14
+ def deliver_facebook
15
+ Processor.work(WallPost.new(self.url, self.content))
16
+ end
17
+
18
+ # Defaults to create a facebook wall post when creating a post
19
+ # off by default when editing a post
20
+ def default_facebook
21
+ post.new_record?
22
+ end
23
+
24
+ # Returns true when notification acts as facebook notification
25
+ def facebook?
26
+ self.kind == 'facebook'
27
+ end
28
+
29
+ private
30
+
31
+ def valid_facebook_content
32
+ errors.add(:content, :facebook) if self.content.blank?
33
+ end
34
+
35
+ end
36
+
37
+ class WallPost
38
+
39
+ def initialize(url, message)
40
+ @url = url
41
+ @message = message
42
+ end
43
+
44
+ # Posts a link to the post with the title of the content of the notification
45
+ # as a default message
46
+ def perform
47
+ Kublog.facebook_client.link! :link => @url, :message => @message
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
54
+ end