maily 0.3.2 → 0.3.3
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.md +35 -4
- data/app/controllers/maily/application_controller.rb +0 -1
- data/lib/generators/templates/initializer.rb +5 -5
- data/lib/maily.rb +7 -6
- data/lib/maily/email.rb +0 -1
- data/lib/maily/mailer.rb +0 -1
- data/lib/maily/version.rb +1 -1
- data/maily.gemspec +2 -2
- data/spec/dummy/README.md +7 -1
- metadata +7 -6
data/README.md
CHANGED
@@ -39,14 +39,14 @@ This installator makes some tasks for you:
|
|
39
39
|
* Adds an initializer (into `config/initializers/maily.rb`) to customize some settings
|
40
40
|
* Adds a file (into `lib/maily_hooks.rb`) to define hooks
|
41
41
|
|
42
|
-
##
|
42
|
+
## Initialization and configuration
|
43
43
|
You should configure Maily via this initializer. You can set these options per environment:
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
Maily.enabled = ENV['MAILY_ENABLED']
|
47
47
|
```
|
48
48
|
|
49
|
-
This is a sample of file with the full list of options:
|
49
|
+
This is a sample of the file with the full list of options:
|
50
50
|
|
51
51
|
```ruby
|
52
52
|
# config/initializers/maily.rb
|
@@ -64,10 +64,16 @@ Maily.setup do |config|
|
|
64
64
|
# config.available_locales = [:en, :es, :pt, :fr]
|
65
65
|
|
66
66
|
# Define parent controller. Allow to run engine under a custom controller
|
67
|
-
# config.base_controller = 'AdminController'
|
67
|
+
# config.base_controller = '::AdminController'
|
68
68
|
end
|
69
69
|
```
|
70
70
|
|
71
|
+
### Templates edition (`allow_edition` option)
|
72
|
+
This feature was designed for `development` environment. Since it's just a file edition and running `production` mode, code is not reloaded between requests, Rails doesn't take in account this change (without restarting the server). Also, allow arbitrary ruby code evaluation is potentially dangerous, that's not a good idea for `production`.
|
73
|
+
|
74
|
+
So, templates edition is not allowed running `production` mode.
|
75
|
+
|
76
|
+
|
71
77
|
## Hooks
|
72
78
|
Most of emails need to populate data to consume it and do intersting things. Hooks are used to define this data with a little DSL. Example:
|
73
79
|
|
@@ -95,10 +101,35 @@ Maily.hooks_for('YourMailerClass') do |mailer|
|
|
95
101
|
end
|
96
102
|
```
|
97
103
|
|
104
|
+
## Customize Authorization
|
105
|
+
By default `Maily` runs under `ActionController::Base`, but you are able to customize that parent controller (`Maily.base_controller` option) in order to achieve (using `before_action`) a kind of access control. For example, set a different base controller:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Maily.setup do |config|
|
109
|
+
...
|
110
|
+
config.base_controller = '::AdminController'
|
111
|
+
...
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
And write your own authorization rules in the defined `base_controller`:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class AdminController < ActionController::Base
|
119
|
+
before_action :maily_authorized?
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def maily_authorized?
|
124
|
+
(current_user && current_user.admin?) || raise('You don't have access to this section!')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
98
129
|
## Notes
|
99
130
|
Rails 4.1 introduced a built-in mechanism to preview the application emails. It is in fact a port of [basecamp/mail_view](https://github.com/basecamp/mail_view) gem to the core.
|
100
131
|
|
101
|
-
Alternatively, there are some other plugins to get a similar functionality with different approaches. For example, [ryanb/letter_opener](https://github.com/ryanb/letter_opener)
|
132
|
+
Alternatively, there are some other plugins to get a similar functionality with different approaches and options. For example, [ryanb/letter_opener](https://github.com/ryanb/letter_opener), [MailCatcher](https://github.com/sj26/mailcatcher) or [Rails Email Preview](https://github.com/glebm/rails_email_preview).
|
102
133
|
|
103
134
|
## License
|
104
135
|
Copyright (c) 2013-2014 Marc Anguera. Maily is released under the [MIT](MIT-LICENSE) License.
|
@@ -1,16 +1,16 @@
|
|
1
1
|
Maily.setup do |config|
|
2
|
-
# On/off engine
|
2
|
+
# On/off engine
|
3
3
|
# config.enabled = Rails.env.production? ? false : true
|
4
4
|
|
5
|
-
# Allow
|
5
|
+
# Allow templates edition
|
6
6
|
# config.allow_edition = Rails.env.production? ? false : true
|
7
7
|
|
8
|
-
# Allow deliveries
|
8
|
+
# Allow deliveries
|
9
9
|
# config.allow_delivery = Rails.env.production? ? false : true
|
10
10
|
|
11
11
|
# I18n.available_locales by default
|
12
12
|
# config.available_locales = [:en, :es, :pt, :fr]
|
13
13
|
|
14
|
-
# 'ActionController::Base' by default
|
15
|
-
# config.base_controller = '
|
14
|
+
# Run maily under different controller. 'ActionController::Base' by default
|
15
|
+
# config.base_controller = 'AdminController'
|
16
16
|
end
|
data/lib/maily.rb
CHANGED
@@ -5,19 +5,18 @@ require 'maily/email'
|
|
5
5
|
|
6
6
|
module Maily
|
7
7
|
class << self
|
8
|
-
|
9
8
|
attr_accessor :enabled, :allow_edition, :allow_delivery, :available_locales, :base_controller
|
10
9
|
|
11
10
|
def init!
|
12
|
-
self.enabled = true
|
13
|
-
self.allow_edition = true
|
14
|
-
self.allow_delivery = true
|
11
|
+
self.enabled = Rails.env.production? ? false : true
|
12
|
+
self.allow_edition = Rails.env.production? ? false : true
|
13
|
+
self.allow_delivery = Rails.env.production? ? false : true
|
15
14
|
self.available_locales = I18n.available_locales
|
16
15
|
self.base_controller = 'ActionController::Base'
|
17
16
|
end
|
18
17
|
|
19
18
|
def load_emails_and_hooks
|
20
|
-
# Load emails
|
19
|
+
# Load emails from file system
|
21
20
|
Dir[Rails.root + 'app/mailers/*.rb'].each do |mailer|
|
22
21
|
klass = File.basename(mailer, '.rb')
|
23
22
|
methods = klass.camelize.constantize.send(:instance_methods, false)
|
@@ -41,8 +40,10 @@ module Maily
|
|
41
40
|
|
42
41
|
def allowed_action?(action)
|
43
42
|
case action.to_sym
|
44
|
-
when :edit,
|
43
|
+
when :edit,
|
45
44
|
allow_edition
|
45
|
+
when :update
|
46
|
+
allow_edition && !Rails.env.production?
|
46
47
|
when :deliver
|
47
48
|
allow_delivery
|
48
49
|
end
|
data/lib/maily/email.rb
CHANGED
data/lib/maily/mailer.rb
CHANGED
data/lib/maily/version.rb
CHANGED
data/maily.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.authors = ["markets"]
|
11
11
|
s.email = ["srmarc.ai@gmail.com"]
|
12
12
|
s.homepage = "https://github.com/markets/maily"
|
13
|
-
s.summary = "Rails Engine to preview emails in
|
14
|
-
s.description = "Rails Engine to preview emails in
|
13
|
+
s.summary = "Rails Engine to preview emails in the browser."
|
14
|
+
s.description = "Rails Engine to preview, follow up, test and edit the emails of your applications in the browser"
|
15
15
|
s.license = "MIT"
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split($/)
|
data/spec/dummy/README.md
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maily
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -43,7 +43,8 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description: Rails Engine to preview emails
|
46
|
+
description: Rails Engine to preview, follow up, test and edit the emails of your
|
47
|
+
applications in the browser
|
47
48
|
email:
|
48
49
|
- srmarc.ai@gmail.com
|
49
50
|
executables: []
|
@@ -150,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
151
|
version: '0'
|
151
152
|
segments:
|
152
153
|
- 0
|
153
|
-
hash:
|
154
|
+
hash: 1797094736581911098
|
154
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
156
|
none: false
|
156
157
|
requirements:
|
@@ -159,13 +160,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
160
|
version: '0'
|
160
161
|
segments:
|
161
162
|
- 0
|
162
|
-
hash:
|
163
|
+
hash: 1797094736581911098
|
163
164
|
requirements: []
|
164
165
|
rubyforge_project:
|
165
166
|
rubygems_version: 1.8.23
|
166
167
|
signing_key:
|
167
168
|
specification_version: 3
|
168
|
-
summary: Rails Engine to preview emails in
|
169
|
+
summary: Rails Engine to preview emails in the browser.
|
169
170
|
test_files:
|
170
171
|
- spec/dummy/README.md
|
171
172
|
- spec/dummy/Rakefile
|