Commit 296a549df0c02837907f36de114fac4ee6da320d
Committed by
Joenio Costa
1 parent
ee4ad041
Exists in
master
and in
21 other branches
improvements in core required for the newsletter plugin
* models should use acts_as_having_image transparently * force margin zero in HTML mailing * using require_dependency instead of require to avoid error: "superclass mismatch for class MailingJob" * now plugins can schedule jobs via whenever rubygem * improve 'sample-data' scripts to create some blog posts signed-off-by: Joenio Costa <joenio@colivre.coop.br>
Showing
6 changed files
with
38 additions
and
8 deletions
Show diff stats
app/mailers/mailing.rb
1 | -require 'mailing_job' | 1 | +require_dependency 'mailing_job' |
2 | 2 | ||
3 | class Mailing < ActiveRecord::Base | 3 | class Mailing < ActiveRecord::Base |
4 | 4 | ||
@@ -40,10 +40,8 @@ class Mailing < ActiveRecord::Base | @@ -40,10 +40,8 @@ class Mailing < ActiveRecord::Base | ||
40 | begin | 40 | begin |
41 | Mailing::Sender.notification(self, recipient.email).deliver | 41 | Mailing::Sender.notification(self, recipient.email).deliver |
42 | self.mailing_sents.create(:person => recipient) | 42 | self.mailing_sents.create(:person => recipient) |
43 | - rescue Exception | ||
44 | - # FIXME should not discard errors silently. An idea is to collect all | ||
45 | - # errors and generate a task (notification) for the +source+ | ||
46 | - # (environment/organization) listing these errors. | 43 | + rescue Exception => ex |
44 | + Rails.logger.error("#{ex.class.to_s} - #{ex.to_s} at #{__FILE__}:#{__LINE__}") | ||
47 | end | 45 | end |
48 | end | 46 | end |
49 | end | 47 | end |
app/models/textile_article.rb
@@ -12,7 +12,7 @@ class TextileArticle < TextArticle | @@ -12,7 +12,7 @@ class TextileArticle < TextArticle | ||
12 | convert_to_html(body) | 12 | convert_to_html(body) |
13 | end | 13 | end |
14 | 14 | ||
15 | - def lead | 15 | + def lead(length = nil) |
16 | if abstract.blank? | 16 | if abstract.blank? |
17 | super | 17 | super |
18 | else | 18 | else |
app/views/mailing/sender/notification.html.erb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | <head> | 3 | <head> |
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
5 | </head> | 5 | </head> |
6 | - <body> | 6 | + <body style="margin: 0"> |
7 | <%= word_wrap(@message) %> | 7 | <%= word_wrap(@message) %> |
8 | <p> | 8 | <p> |
9 | --<br/> | 9 | --<br/> |
config/schedule.rb
@@ -28,3 +28,15 @@ end | @@ -28,3 +28,15 @@ end | ||
28 | every 30.days do | 28 | every 30.days do |
29 | runner "ProfileSuggestion.generate_all_profile_suggestions" | 29 | runner "ProfileSuggestion.generate_all_profile_suggestions" |
30 | end | 30 | end |
31 | + | ||
32 | +# Loads "schedule.rb" files from plugins | ||
33 | +# | ||
34 | +# Allows Noosfero's plugins schedule jobs using `whenever` Ruby gem the same | ||
35 | +# way we do here, just create the file "config/schedule.rb" into the plugin | ||
36 | +# root directory and write jobs using the same syntax used here (see example in | ||
37 | +# the `newsletter` plugin) | ||
38 | + | ||
39 | +Dir.glob("config/plugins/*/config/schedule.rb").each do |filename| | ||
40 | + filecontent = IO.read(filename) | ||
41 | + instance_eval(Whenever::NumericSeconds.process_string(filecontent), filename) | ||
42 | +end |
lib/acts_as_having_image.rb
@@ -5,6 +5,7 @@ module ActsAsHavingImage | @@ -5,6 +5,7 @@ module ActsAsHavingImage | ||
5 | belongs_to :image, dependent: :destroy | 5 | belongs_to :image, dependent: :destroy |
6 | scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ] | 6 | scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ] |
7 | scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ] | 7 | scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ] |
8 | + attr_accessible :image_builder | ||
8 | self.send(:include, ActsAsHavingImage) | 9 | self.send(:include, ActsAsHavingImage) |
9 | end | 10 | end |
10 | end | 11 | end |
@@ -19,4 +20,4 @@ module ActsAsHavingImage | @@ -19,4 +20,4 @@ module ActsAsHavingImage | ||
19 | 20 | ||
20 | end | 21 | end |
21 | 22 | ||
22 | -ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods) | ||
23 | \ No newline at end of file | 23 | \ No newline at end of file |
24 | +ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods) |
script/sample-articles
@@ -65,3 +65,22 @@ for subject in EVENT_SUBJECTS | @@ -65,3 +65,22 @@ for subject in EVENT_SUBJECTS | ||
65 | end | 65 | end |
66 | end | 66 | end |
67 | done | 67 | done |
68 | + | ||
69 | +print "Creating some posts: " | ||
70 | +for subject in SUBJECTS | ||
71 | + rand(20).times do |i| | ||
72 | + profile = profiles.sample | ||
73 | + name = "%s #{subject}" % profile.name | ||
74 | + article = TinyMceArticle.new( | ||
75 | + :name => name, | ||
76 | + :body => name, | ||
77 | + :tag_list => [TAGS.sample, TAGS.sample], | ||
78 | + :profile => profile, | ||
79 | + :parent_id => profile.blog.id | ||
80 | + ) | ||
81 | + save article do | ||
82 | + article.add_category categories.sample | ||
83 | + end | ||
84 | + end | ||
85 | +end | ||
86 | +done |