mail_engine 0.1.1 → 0.1.2

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/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "http://rubygems.org"
2
+ # gemspec
2
3
 
3
4
  gem "activesupport", '>= 3.0.0'
4
5
  gem "httparty"
@@ -6,7 +7,7 @@ gem "nokogiri"
6
7
  gem "deep_cloneable"
7
8
  gem "sqlite3-ruby", :require => "sqlite3"
8
9
  gem 'rack', :git => 'git://github.com/rack/rack.git'
9
- gem "liquid", :git => "git://github.com/hlxwell/liquid.git"
10
+ gem "liquid"
10
11
  gem 'kaminari', :git => 'https://github.com/amatsuda/kaminari.git'
11
12
  gem "carrierwave", :git => "git://github.com/jnicklas/carrierwave.git"
12
13
 
data/README.mkd CHANGED
@@ -42,9 +42,21 @@ Add management page needed javascript lib and css files, migration files and mai
42
42
  Run migration.
43
43
 
44
44
  rake db:migrate
45
-
45
+
46
46
  ** Step 4: **
47
47
 
48
+ Add acts_as_mail_receiver definition to "Your User" model.
49
+
50
+ class User < AR
51
+ acts_as_mail_receiver :payload_columns => %w{firstname lastname},
52
+ :groups => %w{all english_users chinese_users}
53
+ end
54
+
55
+ 1. User model must have 'email' and payload specified columns, or else you can delegate to other model.
56
+ 2. "acts_as_mail_receiver" statement has to place below the scope statements.
57
+
58
+ ** Step 5: **
59
+
48
60
  Add below line to the crontab list of your sever:
49
61
 
50
62
  ### check mail schedule for every 15 minutes ###
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,10 +1,15 @@
1
- class MailEngine::ApplicationController < ActionController::Base
1
+ class MailEngine::ApplicationController < ApplicationController
2
2
  prepend_view_path MailEngine::MailTemplate::Resolver.instance
3
-
4
3
  layout 'mail_engine/mail_engine'
4
+
5
+ # set the access check method.
6
+ if MailEngine::Base.current_config["access_check_method"].present?
7
+ before_filter MailEngine::Base.current_config["access_check_method"]
8
+ end
9
+
5
10
  include MailEngine
6
11
  helper MailEngine::MailEngineHelper
7
-
12
+
8
13
  def close_modal_and_refresh
9
14
  render :text => "<script>parent.$.fancybox.close();parent.window.location.reload();</script>"
10
15
  end
@@ -7,7 +7,7 @@ class MailEngine::MailSchedule < ActiveRecord::Base
7
7
  def logs(count = 10)
8
8
  MailEngine::MailLog.where(:mail_template_path => self.mail_template.actual_path).order("id desc").limit(count)
9
9
  end
10
-
10
+
11
11
  # load user info into payload hash used at mail template.
12
12
  def load_payload user
13
13
  payload_hash = {}
@@ -62,6 +62,7 @@ class MailEngine::MailSchedule < ActiveRecord::Base
62
62
 
63
63
  MailEngine::USER_MODEL.send(self.user_group.to_sym).each do |user|
64
64
  puts "-> sending mail to #{user.email}"
65
+ ### FIXME user.email, what if user don't have email column.
65
66
  MailEngine::MailDispatcher.send(mail_template.template_name.to_sym, :to => user.email, :values => self.load_payload(user) ).deliver
66
67
  end
67
68
 
@@ -57,8 +57,8 @@ class MailEngine::MailTemplate < ActiveRecord::Base
57
57
  end
58
58
 
59
59
  # list the templates with same path, but different locale and format
60
- def variations
61
- existed_variations = self.class.where(:path => self.path, :partial => false).order("locale, format")
60
+ def variations(for_partial = false)
61
+ existed_variations = self.class.where(:path => self.path, :partial => for_partial).order("locale, format")
62
62
 
63
63
  all_variation_codes = I18n.available_locales.product([:html, :text])
64
64
  existed_variation_codes = existed_variations.map do |template|
@@ -25,7 +25,7 @@
25
25
  <% end %>
26
26
  <td style="width: 200px;">
27
27
  <table style="margin-bottom: 0px;">
28
- <% mail_template.variations.group_by(&:locale).each do |locale, templates| %>
28
+ <% mail_template.variations(params[:type] == 'partial').group_by(&:locale).each do |locale, templates| %>
29
29
  <tr>
30
30
  <td colspan="2" style="background-color: grey; font-weight: bold; color: white; padding: 2px 5px"><%= locale.humanize %></td>
31
31
  </tr>
@@ -8,11 +8,13 @@ module MailEngine
8
8
  # === example
9
9
  #
10
10
  # log_mail: true
11
- # sendgrid_user: "xxx@theplant.jp"
12
- # sendgrid_key: "xxx"
13
- # sendgrid_category: "development"
14
11
  # user_class_name: "User"
15
12
  # mount_at: "/admin"
13
+ # access_check_method: "logged_in?"
14
+ # sendgrid:
15
+ # sendgrid_user: "xxx@theplant.jp"
16
+ # sendgrid_key: "xxx"
17
+ # sendgrid_category: "development"
16
18
  #
17
19
  def current_config
18
20
  MailEngine::Base.configurations[Rails.env] || {}
@@ -3,15 +3,16 @@ module MailEngine
3
3
  require 'mail_engine'
4
4
  require 'carrierwave'
5
5
  require 'kaminari'
6
-
6
+ require 'deep_cloneable'
7
+ require 'liquid'
8
+ require 'mail_engine/liquid_view_patch/liquid_view'
9
+
7
10
  initializer "mail_engine" do
8
11
  ActionMailer::Base.send(:include, MailEngine::Sendgrid::Base)
9
12
  require 'mail_engine/action_mailer_patch'
10
13
  end
11
14
 
12
15
  initializer "mail_engine.register_liquid_template" do
13
- require 'liquid'
14
- require 'extras/liquid_view'
15
16
  ActionView::Template.register_template_handler(:liquid, LiquidView)
16
17
  end
17
18
 
@@ -19,7 +20,7 @@ module MailEngine
19
20
  ActionMailer::Base.layout "layouts/mail_engine/mail_template_layouts/none"
20
21
  ActionMailer::Base.send(:prepend_view_path, MailEngine::MailTemplate::Resolver.instance)
21
22
  end
22
-
23
+
23
24
  initializer "mail_engine.add_acts_as_mail_receiver" do
24
25
  ActiveRecord::Base.send(:include, MailEngine::ActsAsMailReceiver)
25
26
  end
@@ -1,23 +1,29 @@
1
1
  development:
2
2
  log_mail: false
3
- sendgrid_user: "you send grid username"
4
- sendgrid_key: "password"
5
- sendgrid_category: "my sendgrid category"
6
3
  user_class_name: "User"
7
- mount_at: "/admin"
4
+ mount_at: "/admin/mail_engine"
5
+ access_check_method: "logged_in?"
6
+ sendgrid:
7
+ sendgrid_user: "you send grid username"
8
+ sendgrid_key: "password"
9
+ sendgrid_category: "my sendgrid category"
8
10
 
9
11
  test:
10
12
  log_mail: false
11
- sendgrid_user: "you send grid username"
12
- sendgrid_key: "password"
13
- sendgrid_category: "my sendgrid category"
14
13
  user_class_name: "User"
15
- mount_at: "/admin"
14
+ mount_at: "/admin/mail_engine"
15
+ access_check_method: "logged_in?"
16
+ sendgrid:
17
+ sendgrid_user: "you send grid username"
18
+ sendgrid_key: "password"
19
+ sendgrid_category: "my sendgrid category"
16
20
 
17
21
  production:
18
22
  log_mail: false
19
- sendgrid_user: "you send grid username"
20
- sendgrid_key: "password"
21
- sendgrid_category: "my sendgrid category"
22
23
  user_class_name: "User"
23
- mount_at: "/admin"
24
+ mount_at: "/admin/mail_engine"
25
+ access_check_method: "logged_in?"
26
+ sendgrid:
27
+ sendgrid_user: "you send grid username"
28
+ sendgrid_key: "password"
29
+ sendgrid_category: "my sendgrid category"
@@ -0,0 +1,52 @@
1
+ # LiquidView is a action view extension class. You can register it with rails
2
+ # and use liquid as an template system for .liquid files
3
+ #
4
+ # Example
5
+ #
6
+ # ActionView::Base::register_template_handler :liquid, LiquidView
7
+ class LiquidView
8
+ PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
9
+ _response url _request _cookies variables_added _flash params _headers request cookies
10
+ ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
11
+ PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
12
+ @helpers @assigns_added @template @_render_stack @template_format @assigns )
13
+
14
+ def self.call(template)
15
+ "LiquidView.new(self).render('#{template.source.gsub(/\'/, '"')}', local_assigns)"
16
+ end
17
+
18
+ def initialize(view)
19
+ @view = view
20
+ end
21
+
22
+ def render(template, local_assigns = nil)
23
+ ### when I render text layout, it still set me html content type. so remove it.
24
+ # @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
25
+
26
+ # Rails 2.2 Template has source, but not locals
27
+ if template.respond_to?(:source) && !template.respond_to?(:locals)
28
+ assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
29
+ hash[ivar[1..-1]] = @view.instance_variable_get(ivar)
30
+ hash
31
+ end
32
+ else
33
+ assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
34
+ end
35
+
36
+ source = template.respond_to?(:source) ? template.source : template
37
+ local_assigns = (template.respond_to?(:locals) ? template.locals : local_assigns) || {}
38
+
39
+ if content_for_layout = @view.instance_variable_get("@content_for_layout")
40
+ assigns['content_for_layout'] = content_for_layout
41
+ end
42
+ assigns.merge!(local_assigns.stringify_keys)
43
+
44
+ liquid = Liquid::Template.parse(source)
45
+ liquid.render(assigns, :filters => [@view.helpers], :registers => {:action_view => @view, :controller => @view.controller})
46
+ end
47
+
48
+ def compilable?
49
+ false
50
+ end
51
+
52
+ end
@@ -9,7 +9,7 @@ module MailEngine
9
9
  class RestApi
10
10
  include HTTParty
11
11
  base_uri "https://sendgrid.com/api"
12
- default_params :api_key => MailEngine::Base.current_config["sendgrid_key"], :api_user => MailEngine::Base.current_config["sendgrid_user"]
12
+ default_params :api_key => MailEngine::Base.current_config["sendgrid"]["sendgrid_key"], :api_user => MailEngine::Base.current_config["sendgrid"]["sendgrid_user"]
13
13
 
14
14
  class << self
15
15
  # <stats>
data/lib/mail_engine.rb CHANGED
@@ -20,4 +20,5 @@ module MailEngine
20
20
  autoload :Mailer
21
21
  autoload :ActsAsMailReceiver
22
22
  autoload :Configuration
23
- end
23
+ end
24
+
data/mail_engine.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mail_engine}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["michael he"]
12
- s.date = %q{2011-03-04}
12
+ s.date = %q{2011-03-05}
13
13
  s.description = %q{Rails system mail management solution.}
14
14
  s.email = %q{hlxwell@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -88,7 +88,6 @@ Gem::Specification.new do |s|
88
88
  ".yardoc/objects/root.dat",
89
89
  ".yardoc/proxy_types",
90
90
  "Gemfile",
91
- "Gemfile.lock",
92
91
  "MIT-LICENSE",
93
92
  "README.mkd",
94
93
  "Rakefile",
@@ -202,6 +201,7 @@ Gem::Specification.new do |s|
202
201
  "lib/mail_engine/generators/install.rb",
203
202
  "lib/mail_engine/generators/templates/mail_engine_config.yml",
204
203
  "lib/mail_engine/html_document_assets_replacer.rb",
204
+ "lib/mail_engine/liquid_view_patch/liquid_view.rb",
205
205
  "lib/mail_engine/mail_log_subscriber.rb",
206
206
  "lib/mail_engine/sendgrid.rb",
207
207
  "lib/mail_engine/sendgrid/base.rb",
@@ -55,7 +55,8 @@ class MailEngine::MailTemplateTest < ActiveSupport::TestCase
55
55
  end
56
56
 
57
57
  should "be able to get missing variations" do
58
- assert_equal 4, @template.variations.count
58
+ assert_equal 4, @template.variations.count # all normal templates
59
+ assert_equal 4, @template.variations(true).count # all partials
59
60
  assert_equal 3, @template.variations.delete_if {|v| v.persisted? }.size
60
61
 
61
62
  variations = @template.variations.map { |v|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - michael he
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-04 00:00:00 +08:00
18
+ date: 2011-03-05 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -311,7 +311,6 @@ files:
311
311
  - .yardoc/objects/root.dat
312
312
  - .yardoc/proxy_types
313
313
  - Gemfile
314
- - Gemfile.lock
315
314
  - MIT-LICENSE
316
315
  - README.mkd
317
316
  - Rakefile
@@ -425,6 +424,7 @@ files:
425
424
  - lib/mail_engine/generators/install.rb
426
425
  - lib/mail_engine/generators/templates/mail_engine_config.yml
427
426
  - lib/mail_engine/html_document_assets_replacer.rb
427
+ - lib/mail_engine/liquid_view_patch/liquid_view.rb
428
428
  - lib/mail_engine/mail_log_subscriber.rb
429
429
  - lib/mail_engine/sendgrid.rb
430
430
  - lib/mail_engine/sendgrid/base.rb
data/Gemfile.lock DELETED
@@ -1,180 +0,0 @@
1
- GIT
2
- remote: git://github.com/hlxwell/liquid.git
3
- revision: d70ed7582215507a579fee8b5e5b3269600f3fb3
4
- specs:
5
- liquid (2.2.2)
6
-
7
- GIT
8
- remote: git://github.com/jnicklas/carrierwave.git
9
- revision: d85841ca51fa2c546bd73d9d7ba871c7c0d9455b
10
- specs:
11
- carrierwave (0.5.2)
12
- activesupport (~> 3.0)
13
-
14
- GIT
15
- remote: git://github.com/rack/rack.git
16
- revision: e3ffeac0dc04bb8d5994b7923bf12e55d549a279
17
- specs:
18
- rack (1.2.1)
19
-
20
- GIT
21
- remote: git://github.com/thoughtbot/factory_girl.git
22
- revision: a7f7e85187e9178f4da2db1b87fa38aec6a96178
23
- specs:
24
- factory_girl (2.0.0.beta1)
25
-
26
- GIT
27
- remote: https://github.com/amatsuda/kaminari.git
28
- revision: 91e9137096e2e5aedfe91f9ebab35b4af8de2408
29
- specs:
30
- kaminari (0.10.4)
31
- rails (>= 3.0.0)
32
-
33
- GEM
34
- remote: http://rubygems.org/
35
- specs:
36
- abstract (1.0.0)
37
- actionmailer (3.0.4)
38
- actionpack (= 3.0.4)
39
- mail (~> 2.2.15)
40
- actionpack (3.0.4)
41
- activemodel (= 3.0.4)
42
- activesupport (= 3.0.4)
43
- builder (~> 2.1.2)
44
- erubis (~> 2.6.6)
45
- i18n (~> 0.4)
46
- rack (~> 1.2.1)
47
- rack-mount (~> 0.6.13)
48
- rack-test (~> 0.5.7)
49
- tzinfo (~> 0.3.23)
50
- activemodel (3.0.4)
51
- activesupport (= 3.0.4)
52
- builder (~> 2.1.2)
53
- i18n (~> 0.4)
54
- activerecord (3.0.4)
55
- activemodel (= 3.0.4)
56
- activesupport (= 3.0.4)
57
- arel (~> 2.0.2)
58
- tzinfo (~> 0.3.23)
59
- activeresource (3.0.4)
60
- activemodel (= 3.0.4)
61
- activesupport (= 3.0.4)
62
- activesupport (3.0.4)
63
- arel (2.0.9)
64
- bluecloth (2.0.11)
65
- builder (2.1.2)
66
- capybara (0.4.1.2)
67
- celerity (>= 0.7.9)
68
- culerity (>= 0.2.4)
69
- mime-types (>= 1.16)
70
- nokogiri (>= 1.3.3)
71
- rack (>= 1.0.0)
72
- rack-test (>= 0.5.4)
73
- selenium-webdriver (>= 0.0.27)
74
- xpath (~> 0.1.3)
75
- celerity (0.8.8)
76
- childprocess (0.1.7)
77
- ffi (~> 0.6.3)
78
- crack (0.1.8)
79
- culerity (0.2.15)
80
- deep_cloneable (1.2.1)
81
- erubis (2.6.6)
82
- abstract (>= 1.0.0)
83
- fakeweb (1.3.0)
84
- ffi (0.6.3)
85
- rake (>= 0.8.7)
86
- git (1.2.5)
87
- httparty (0.6.1)
88
- crack (= 0.1.8)
89
- i18n (0.5.0)
90
- jeweler (1.5.2)
91
- bundler (~> 1.0.0)
92
- git (>= 1.2.5)
93
- rake
94
- json_pure (1.5.1)
95
- mail (2.2.15)
96
- activesupport (>= 2.3.6)
97
- i18n (>= 0.4.0)
98
- mime-types (~> 1.16)
99
- treetop (~> 1.4.8)
100
- mime-types (1.16)
101
- mocha (0.9.10)
102
- rake
103
- nokogiri (1.4.4)
104
- polyglot (0.3.1)
105
- rack-mount (0.6.13)
106
- rack (>= 1.0.0)
107
- rack-test (0.5.7)
108
- rack (>= 1.0)
109
- rails (3.0.4)
110
- actionmailer (= 3.0.4)
111
- actionpack (= 3.0.4)
112
- activerecord (= 3.0.4)
113
- activeresource (= 3.0.4)
114
- activesupport (= 3.0.4)
115
- bundler (~> 1.0)
116
- railties (= 3.0.4)
117
- railties (3.0.4)
118
- actionpack (= 3.0.4)
119
- activesupport (= 3.0.4)
120
- rake (>= 0.8.7)
121
- thor (~> 0.14.4)
122
- rake (0.8.7)
123
- rcov (0.9.9)
124
- reek (1.2.8)
125
- ruby2ruby (~> 1.2)
126
- ruby_parser (~> 2.0)
127
- sexp_processor (~> 3.0)
128
- ruby2ruby (1.2.5)
129
- ruby_parser (~> 2.0)
130
- sexp_processor (~> 3.0)
131
- ruby_parser (2.0.6)
132
- sexp_processor (~> 3.0)
133
- rubyzip (0.9.4)
134
- selenium-webdriver (0.1.3)
135
- childprocess (~> 0.1.5)
136
- ffi (~> 0.6.3)
137
- json_pure
138
- rubyzip
139
- sexp_processor (3.0.5)
140
- shoulda (2.11.3)
141
- sqlite3 (1.3.3)
142
- sqlite3-ruby (1.3.3)
143
- sqlite3 (>= 1.3.3)
144
- test_benchmarker (1.2.1)
145
- thor (0.14.6)
146
- timecop (0.3.5)
147
- treetop (1.4.9)
148
- polyglot (>= 0.3.1)
149
- tzinfo (0.3.24)
150
- xpath (0.1.3)
151
- nokogiri (~> 1.3)
152
- yard (0.6.4)
153
-
154
- PLATFORMS
155
- ruby
156
-
157
- DEPENDENCIES
158
- activesupport (>= 3.0.0)
159
- bluecloth
160
- bundler
161
- capybara (>= 0.4.0)
162
- carrierwave!
163
- deep_cloneable
164
- factory_girl!
165
- fakeweb
166
- httparty
167
- jeweler
168
- kaminari!
169
- liquid!
170
- mocha
171
- nokogiri
172
- rack!
173
- rack-test
174
- rcov
175
- reek
176
- shoulda
177
- sqlite3-ruby
178
- test_benchmarker
179
- timecop
180
- yard