actionmailer-localized_preview 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +2 -0
- data/actionmailer-localized_preview.gemspec +26 -0
- data/lib/action_mailer/localized_preview.rb +43 -0
- data/lib/action_mailer/localized_preview/version.rb +5 -0
- data/spec/localized_preview_spec.rb +78 -0
- data/spec/spec_helper.rb +2 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d862fc0f1e806a26ad89e18ef376a0fec4500c18
|
4
|
+
data.tar.gz: b999b907118c85e32eacc6214d8e3eb04657dd98
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e634c1b7dd129c9bc1ef02ea87aa89127b5c69cb0e14cd86445f53686daa29fc3e719837c21b0d5168dedba1484a170aa79a28809da10ddca627ce4bf516a4d9
|
7
|
+
data.tar.gz: e380dda48f44858da2674dbb42840662620a5dc6b37a7f4aba4e14363a36fc35db7a76e60fabac42b0d447dfafc97b50dd68ff319f3394e799d814a5da01ea20
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Xavier Defrang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# ActionMailer::LocalizedPreview
|
2
|
+
|
3
|
+
This gem extends [ActionMailer::Preview](http://api.rubyonrails.org/classes/ActionMailer/Preview.html) to allow previews of emails in all available locales.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Simply include `ActionMailer::LocalizedPreview` in your preview class
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'action_mailer/localized_preview'
|
11
|
+
|
12
|
+
class NotifierPreview < ActionMailer::Preview
|
13
|
+
include ActionMailer::LocalizedPreview
|
14
|
+
|
15
|
+
def account_confirmation
|
16
|
+
account = Account.new(name: "Cosmo Kramer")
|
17
|
+
Notifier.account_confirmation(account)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
```
|
23
|
+
|
24
|
+
Assuming that `I18n.available_locales` is set to `[:en, :fr, :nl]`, it will make the following preview methods available:
|
25
|
+
|
26
|
+
* `account_confirmation_en`
|
27
|
+
* `account_confirmation_fr`
|
28
|
+
* `account_confirmation_nl`
|
29
|
+
|
30
|
+
If you want direct access to the current locale in your mailer preview method, you may add a parameter to your method signature and the locale will be passed on:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'action_mailer/localized_preview'
|
34
|
+
|
35
|
+
class NotifierPreview < ActionMailer::Preview
|
36
|
+
include ActionMailer::LocalizedPreview
|
37
|
+
|
38
|
+
def account_confirmation(locale)
|
39
|
+
account = Account.new(name: "Cosmo Kramer", prefered_language: locale)
|
40
|
+
Notifier.account_confirmation(account)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
### Caveats
|
48
|
+
|
49
|
+
* This was built for **Rails 4.1 onwards** and **wont work** with the [mail_view](https://github.com/basecamp/mail_view) gem which is the ancestor of the mailer preview feature but sports a different API
|
50
|
+
* It hasn't been tested with locales containing a regional setting (e.g. `en-US`, `en-GB`, ...) and these are most probably not supported at this point.
|
51
|
+
|
52
|
+
## Installation
|
53
|
+
|
54
|
+
Add this line to your application's Gemfile:
|
55
|
+
|
56
|
+
gem 'actionmailer-localized_preview'
|
57
|
+
|
58
|
+
And then execute:
|
59
|
+
|
60
|
+
$ bundle
|
61
|
+
|
62
|
+
Or install it yourself as:
|
63
|
+
|
64
|
+
$ gem install actionmailer-localized_preview
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it ( https://github.com/[my-github-username]/actionmailer-localized_preview/fork )
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'action_mailer/localized_preview/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "actionmailer-localized_preview"
|
8
|
+
spec.version = ActionMailer::LocalizedPreview::VERSION
|
9
|
+
spec.authors = ["Xavier Defrang"]
|
10
|
+
spec.email = ["xavier.defrang@gmail.com"]
|
11
|
+
spec.summary = %q{Extends ActionMailer::Preview to allow email previews in all available locales}
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "actionmailer", "~> 4.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "action_mailer/localized_preview/version"
|
2
|
+
|
3
|
+
module ActionMailer
|
4
|
+
module LocalizedPreview
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def locales
|
10
|
+
I18n.available_locales
|
11
|
+
end
|
12
|
+
|
13
|
+
def emails
|
14
|
+
public_instance_methods(false).each_with_object([]) do |method, list|
|
15
|
+
locales.each do |locale|
|
16
|
+
list << "#{method}_#{locale}"
|
17
|
+
end
|
18
|
+
end.sort
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(localized_method_name, *args)
|
24
|
+
localized_method_name.to_s =~ /(.*)_([^_]+)$/
|
25
|
+
method_name, locale = $1, $2.to_sym
|
26
|
+
current_locale = I18n.locale
|
27
|
+
begin
|
28
|
+
I18n.locale = $2
|
29
|
+
case self.method(method_name).arity
|
30
|
+
when 0
|
31
|
+
public_send(method_name)
|
32
|
+
when 1
|
33
|
+
public_send(method_name, locale)
|
34
|
+
else
|
35
|
+
raise ArgumentError, "wrong number of arguments (expected 0 or 1)"
|
36
|
+
end
|
37
|
+
ensure
|
38
|
+
I18n.locale = current_locale
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestPreview < ActionMailer::Preview
|
4
|
+
|
5
|
+
include ActionMailer::LocalizedPreview
|
6
|
+
|
7
|
+
def mailer1
|
8
|
+
"mailer1_message_with_locale_#{I18n.locale}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def mailer2(locale)
|
12
|
+
"mailer2_message_with_locale_#{locale}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def mailer3(foo, bar)
|
16
|
+
"will raise an error"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ActionMailer::LocalizedPreview do
|
22
|
+
|
23
|
+
before do
|
24
|
+
I18n.available_locales = [:en, :fr, :nl]
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".emails" do
|
28
|
+
|
29
|
+
it "returns localized method names" do
|
30
|
+
expected = %w{mailer1_en mailer1_fr mailer1_nl mailer2_en mailer2_fr mailer2_nl mailer3_en mailer3_fr mailer3_nl}
|
31
|
+
expect(TestPreview.emails).to eq(expected)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".call" do
|
37
|
+
|
38
|
+
context "when calling a mailer with no arguments" do
|
39
|
+
|
40
|
+
it "calls the method with the correct locale set" do
|
41
|
+
expect(TestPreview.call("mailer1_en")).to eq("mailer1_message_with_locale_en")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "does not affect the current locale" do
|
45
|
+
expect { TestPreview.call("mailer1_en") }.not_to change(I18n, :locale)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when calling a mailer which accepts one argument" do
|
51
|
+
|
52
|
+
it "passes the locale as argument to the method" do
|
53
|
+
expect(TestPreview.call("mailer2_fr")).to eq("mailer2_message_with_locale_fr")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "does not affect the current locale" do
|
57
|
+
expect { TestPreview.call("mailer2_fr") }.not_to change(I18n, :locale)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when calling a mailer which accepts more than one argument" do
|
63
|
+
|
64
|
+
it "raises an error" do
|
65
|
+
expect { TestPreview.call("mailer3_fr") }.to raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "does not affect the current locale" do
|
69
|
+
expect do
|
70
|
+
TestPreview.call("mailer3_fr") rescue ArgumentError
|
71
|
+
end.not_to change(I18n, :locale)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionmailer-localized_preview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xavier Defrang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionmailer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- xavier.defrang@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- actionmailer-localized_preview.gemspec
|
83
|
+
- lib/action_mailer/localized_preview.rb
|
84
|
+
- lib/action_mailer/localized_preview/version.rb
|
85
|
+
- spec/localized_preview_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Extends ActionMailer::Preview to allow email previews in all available locales
|
111
|
+
test_files:
|
112
|
+
- spec/localized_preview_spec.rb
|
113
|
+
- spec/spec_helper.rb
|