i18n_emails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +48 -0
- data/LICENSE +20 -0
- data/README.rdoc +46 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/i18n_emails.rb +62 -0
- data/lib/i18n_emails/i18n_extension.rb +10 -0
- data/spec/fixtures/dont_load.me +1 -0
- data/spec/fixtures/en.yml +2 -0
- data/spec/fixtures/forgotten_password.email +11 -0
- data/spec/fixtures/nested/a_nested.email +11 -0
- data/spec/fixtures/nested/second_nest/second_nest.email +11 -0
- data/spec/fixtures/with_shorter_split.email +11 -0
- data/spec/i18n_emails_spec.rb +69 -0
- data/spec/spec_helper.rb +12 -0
- metadata +103 -0
data/.document
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
GEM
|
2
|
+
specs:
|
3
|
+
abstract (1.0.0)
|
4
|
+
actionpack (3.0.0)
|
5
|
+
activemodel (= 3.0.0)
|
6
|
+
activesupport (= 3.0.0)
|
7
|
+
builder (~> 2.1.2)
|
8
|
+
erubis (~> 2.6.6)
|
9
|
+
i18n (~> 0.4.1)
|
10
|
+
rack (~> 1.2.1)
|
11
|
+
rack-mount (~> 0.6.12)
|
12
|
+
rack-test (~> 0.5.4)
|
13
|
+
tzinfo (~> 0.3.23)
|
14
|
+
activemodel (3.0.0)
|
15
|
+
activesupport (= 3.0.0)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
i18n (~> 0.4.1)
|
18
|
+
activesupport (3.0.0)
|
19
|
+
builder (2.1.2)
|
20
|
+
diff-lcs (1.1.2)
|
21
|
+
erubis (2.6.6)
|
22
|
+
abstract (>= 1.0.0)
|
23
|
+
i18n (0.4.2)
|
24
|
+
rack (1.2.1)
|
25
|
+
rack-mount (0.6.13)
|
26
|
+
rack (>= 1.0.0)
|
27
|
+
rack-test (0.5.6)
|
28
|
+
rack (>= 1.0)
|
29
|
+
rspec (2.0.0)
|
30
|
+
rspec-core (= 2.0.0)
|
31
|
+
rspec-expectations (= 2.0.0)
|
32
|
+
rspec-mocks (= 2.0.0)
|
33
|
+
rspec-core (2.0.0)
|
34
|
+
rspec-expectations (2.0.0)
|
35
|
+
diff-lcs (>= 1.1.2)
|
36
|
+
rspec-mocks (2.0.0)
|
37
|
+
rspec-core (= 2.0.0)
|
38
|
+
rspec-expectations (= 2.0.0)
|
39
|
+
tzinfo (0.3.23)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
actionpack
|
46
|
+
activesupport
|
47
|
+
i18n
|
48
|
+
rspec (= 2.0.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Matt Vague, VersaPay Corporation
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= easy_i18n_emails
|
2
|
+
|
3
|
+
I18nEmails makes it easy to create and maintain I18n emails in Rails apps.
|
4
|
+
|
5
|
+
Using I18n in large Rails apps often results in large and incomprehensible translation files. The idea of splitting up concerns should also apply to translations files and emails in particular and that is why this gem was created.
|
6
|
+
|
7
|
+
I18nEmails allows you to create separate translation files for each email (.email) and store them in a nested folder structure mirroring a translation file, for example: config/locales/en/notifier/forgotten_password.email.
|
8
|
+
|
9
|
+
The email body content in a .email file is also more readable for both developer and non-technical people then a YAML file.
|
10
|
+
|
11
|
+
== Example email:
|
12
|
+
|
13
|
+
subject: Forgotten password
|
14
|
+
|
15
|
+
heading: It's ok, we all forget our passwords sometimes
|
16
|
+
# Available interpolation args: username, link
|
17
|
+
|
18
|
+
--------------------------------------------
|
19
|
+
|
20
|
+
Hi %{username},
|
21
|
+
|
22
|
+
Click here to reset your password %{link}.
|
23
|
+
|
24
|
+
Have a great day!
|
25
|
+
|
26
|
+
== Notes
|
27
|
+
|
28
|
+
Anything above the <code>----</code> is still parsed as YAML, but anything below it becomes the body of the email (newlines are converted to <p></p> tags using simple_format)
|
29
|
+
|
30
|
+
== Note on Patches/Pull Requests
|
31
|
+
|
32
|
+
* Fork the project.
|
33
|
+
* Make your feature addition or bug fix.
|
34
|
+
* Add tests for it. This is important so I don't break it in a
|
35
|
+
future version unintentionally.
|
36
|
+
* Commit, do not mess with rakefile, version, or history.
|
37
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
38
|
+
* Send me a pull request. Bonus points for topic branches.
|
39
|
+
|
40
|
+
== Contributors
|
41
|
+
|
42
|
+
* Greg Bell http://github.com/gregbell
|
43
|
+
|
44
|
+
== Copyright
|
45
|
+
|
46
|
+
Copyright (c) 2010 Matt Vague, VersaPay Corporation. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "i18n_emails"
|
8
|
+
gem.summary = %Q{The nicer way to create and maintain emails in Rails apps using I18n}
|
9
|
+
gem.description = %Q{I18nEmails makes it easy to create and maintain I18n emails in Rails apps.
|
10
|
+
|
11
|
+
Using I18n in large Rails apps often results in large and incomprehensible translation files. The idea of splitting up concerns should also apply to translations files and emails in particular and that is why this gem was created.
|
12
|
+
|
13
|
+
I18nEmails allows you to create separate translation files for each email (.email) and store them in a nested folder structure mirroring a translation file, for example: config/locales/en/notifier/forgotten_password.email.
|
14
|
+
|
15
|
+
The email body content in a .email file is also more readable for both developer and non-technical people then a YAML file. }
|
16
|
+
gem.email = "mattvague@gmail.com"
|
17
|
+
gem.homepage = "http://github.com/mattvague/i18n_emails"
|
18
|
+
gem.authors = ["Matt Vague", "Greg Bell", "VersaPay"]
|
19
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
20
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'spec/rake/spectask'
|
28
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
34
|
+
spec.libs << 'lib' << 'spec'
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :spec => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "i18n_emails #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/i18n_emails.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext/module/aliasing'
|
4
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
5
|
+
require 'action_view'
|
6
|
+
require "yaml"
|
7
|
+
require "i18n_emails/i18n_extension"
|
8
|
+
|
9
|
+
module I18nEmails
|
10
|
+
|
11
|
+
mattr_accessor :load_path
|
12
|
+
self.load_path = "config/locales/en"
|
13
|
+
|
14
|
+
class Email
|
15
|
+
|
16
|
+
include ActionView::Helpers::TagHelper
|
17
|
+
include ActionView::Helpers::TextHelper # to use simple_format
|
18
|
+
|
19
|
+
BODY_SPLIT = /^-{3,}\n/
|
20
|
+
|
21
|
+
class << self
|
22
|
+
# Returns a hash of the content of all .email files contained the
|
23
|
+
# the specified directory (searches recursivly)
|
24
|
+
def load_all(dir = I18nEmails.load_path)
|
25
|
+
hash = {}
|
26
|
+
|
27
|
+
Dir[File.join(dir, "*")].each do |file_or_folder|
|
28
|
+
if File.directory?(file_or_folder)
|
29
|
+
hash[File.basename(file_or_folder)] = Email.load_all(file_or_folder)
|
30
|
+
else
|
31
|
+
if email_file?(file_or_folder)
|
32
|
+
email = Email.new(file_or_folder)
|
33
|
+
hash[email.key] = email.to_hash
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def email_file?(filename)
|
44
|
+
filename =~ /.email$/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize(path)
|
49
|
+
@path = path
|
50
|
+
@file_contents = File.read(path)
|
51
|
+
end
|
52
|
+
|
53
|
+
def key
|
54
|
+
File.basename(@path).gsub(".email", '')
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_hash
|
58
|
+
header, body = @file_contents.split(BODY_SPLIT)
|
59
|
+
YAML::load(header).merge({'body' => simple_format(body)})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
subject: NOOOOO!
|
@@ -0,0 +1,11 @@
|
|
1
|
+
subject: Forgotten password
|
2
|
+
|
3
|
+
heading: It's ok, we all forget our passwords sometimes
|
4
|
+
# Available interpolation args: username, link
|
5
|
+
|
6
|
+
--------------------------------------------
|
7
|
+
Hi %{username},
|
8
|
+
|
9
|
+
Click here to reset your password %{link}.
|
10
|
+
|
11
|
+
Have a great day!
|
@@ -0,0 +1,11 @@
|
|
1
|
+
subject: Forgotten password
|
2
|
+
|
3
|
+
heading: It's ok, we all forget our passwords sometimes
|
4
|
+
# Available interpolation args: username, link
|
5
|
+
|
6
|
+
-------------------------------
|
7
|
+
Hi %{username},
|
8
|
+
|
9
|
+
Click here to reset your password %{link}.
|
10
|
+
|
11
|
+
Have a great day!
|
@@ -0,0 +1,11 @@
|
|
1
|
+
subject: Forgotten password
|
2
|
+
|
3
|
+
heading: It's ok, we all forget our passwords sometimes
|
4
|
+
# Available interpolation args: username, link
|
5
|
+
|
6
|
+
-------------------------------
|
7
|
+
Hi %{username},
|
8
|
+
|
9
|
+
Click here to reset your password %{link}.
|
10
|
+
|
11
|
+
Have a great day!
|
@@ -0,0 +1,11 @@
|
|
1
|
+
subject: Forgotten password
|
2
|
+
|
3
|
+
heading: It's ok, we all forget our passwords sometimes
|
4
|
+
# Available interpolation args: username, link
|
5
|
+
|
6
|
+
-------------------------------
|
7
|
+
Hi %{username},
|
8
|
+
|
9
|
+
Click here to reset your password %{link}.
|
10
|
+
|
11
|
+
Have a great day!
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "I18nEmails" do
|
4
|
+
describe "loading a file" do
|
5
|
+
|
6
|
+
let(:email_file) {File.expand_path("../fixtures/forgotten_password.email", __FILE__)}
|
7
|
+
let(:email) { I18nEmails::Email.new(email_file) }
|
8
|
+
|
9
|
+
it "should load the email header keys" do
|
10
|
+
email.to_hash["subject"].should == "Forgotten password"
|
11
|
+
email.to_hash["heading"].should == "It's ok, we all forget our passwords sometimes"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should load the email body with newlines converted to paragraph tags" do
|
15
|
+
email.to_hash["body"].should == "<p>Hi %{username},</p>\n\n<p>Click here to reset your password %{link}.</p>\n\n<p>Have a great day!</p>"
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with a different split" do
|
19
|
+
let(:email_file) {File.expand_path("../fixtures/with_shorter_split.email", __FILE__)}
|
20
|
+
|
21
|
+
it "should load the email header keys" do
|
22
|
+
email.to_hash["subject"].should == "Forgotten password"
|
23
|
+
email.to_hash["heading"].should == "It's ok, we all forget our passwords sometimes"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should load the email body" do
|
27
|
+
email.to_hash["body"].should == "<p>Hi %{username},</p>\n\n<p>Click here to reset your password %{link}.</p>\n\n<p>Have a great day!</p>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise an exception if no file" do
|
32
|
+
lambda {
|
33
|
+
I18nEmails::Email.new("/my/non/existent/file")
|
34
|
+
}.should raise_exception(Errno::ENOENT)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "loading files" do
|
39
|
+
|
40
|
+
let(:email_dir) {File.expand_path("../fixtures/", __FILE__)}
|
41
|
+
|
42
|
+
it "should load all files in a directory" do
|
43
|
+
I18nEmails::Email.load_all(email_dir).keys.should include("with_shorter_split", "forgotten_password", "nested")
|
44
|
+
end
|
45
|
+
|
46
|
+
context "from a subdirectory" do
|
47
|
+
it "should load files in a nested hash" do
|
48
|
+
I18nEmails::Email.load_all(email_dir)["nested"].keys.should include("a_nested")
|
49
|
+
end
|
50
|
+
it "should load files nested twice" do
|
51
|
+
I18nEmails::Email.load_all(email_dir)["nested"]["second_nest"].keys.should == ["second_nest"]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should should only load .email files" do
|
56
|
+
I18nEmails::Email.load_all(email_dir).keys.should_not include("dont_load.me")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "loading translations into I18n" do
|
61
|
+
it "should load into a backend" do
|
62
|
+
I18n.load_path = [File.expand_path("../fixtures/en.yml", __FILE__)]
|
63
|
+
I18nEmails.load_path = File.expand_path("../fixtures", __FILE__)
|
64
|
+
I18n.reload!
|
65
|
+
I18n.t("hello").should == "World"
|
66
|
+
I18n.t("forgotten_password.subject").should == "Forgotten password"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'i18n_emails'
|
4
|
+
|
5
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require "bundler"
|
9
|
+
Bundler.setup
|
10
|
+
|
11
|
+
require 'rspec'
|
12
|
+
require 'rspec/autorun'
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_emails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matt Vague
|
14
|
+
- Greg Bell
|
15
|
+
- VersaPay
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-11-16 00:00:00 -08:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: rspec
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 13
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 2
|
35
|
+
- 9
|
36
|
+
version: 1.2.9
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id001
|
39
|
+
description: "I18nEmails makes it easy to create and maintain I18n emails in Rails apps.\n\n Using I18n in large Rails apps often results in large and incomprehensible translation files. The idea of splitting up concerns should also apply to translations files and emails in particular and that is why this gem was created.\n\n I18nEmails allows you to create separate translation files for each email (.email) and store them in a nested folder structure mirroring a translation file, for example: config/locales/en/notifier/forgotten_password.email.\n\n The email body content in a .email file is also more readable for both developer and non-technical people then a YAML file. "
|
40
|
+
email: mattvague@gmail.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files:
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
files:
|
49
|
+
- .document
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE
|
54
|
+
- README.rdoc
|
55
|
+
- Rakefile
|
56
|
+
- VERSION
|
57
|
+
- lib/i18n_emails.rb
|
58
|
+
- lib/i18n_emails/i18n_extension.rb
|
59
|
+
- spec/fixtures/dont_load.me
|
60
|
+
- spec/fixtures/en.yml
|
61
|
+
- spec/fixtures/forgotten_password.email
|
62
|
+
- spec/fixtures/nested/a_nested.email
|
63
|
+
- spec/fixtures/nested/second_nest/second_nest.email
|
64
|
+
- spec/fixtures/with_shorter_split.email
|
65
|
+
- spec/i18n_emails_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/mattvague/i18n_emails
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: The nicer way to create and maintain emails in Rails apps using I18n
|
101
|
+
test_files:
|
102
|
+
- spec/i18n_emails_spec.rb
|
103
|
+
- spec/spec_helper.rb
|