jaimito 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b02881110ef2ea65e308e8866c372a567400e4f8
4
+ data.tar.gz: 49745cd8b92a287e8d3c93d9a2d80d6af57f5bfb
5
+ SHA512:
6
+ metadata.gz: 2b39224ab46f3ee17fc8522326c9f953947711371c66fc13215d93d1d7bc1087a5d1cd1cb74e49beb54e7d18b53f9b50a74d5bde3b411dcf252f60986c5f71c3
7
+ data.tar.gz: c6ba810965aabde872e2b1475ccfe7804a936b89e23d1219e6a8239ca2490f7bea3c70aedf3f2982279a50bbbdfe3bd15245f7597cef1329bdcc74aaec64c2df
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ **.gem
2
+ .rvmrc
3
+ /.bundle/
4
+ /vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,156 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jaimito (0.1.0)
5
+ rails (~> 4.2.0)
6
+ sanitize (> 3.0.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (4.2.5.1)
12
+ actionpack (= 4.2.5.1)
13
+ actionview (= 4.2.5.1)
14
+ activejob (= 4.2.5.1)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.5.1)
18
+ actionview (= 4.2.5.1)
19
+ activesupport (= 4.2.5.1)
20
+ rack (~> 1.6)
21
+ rack-test (~> 0.6.2)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ actionview (4.2.5.1)
25
+ activesupport (= 4.2.5.1)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
+ activejob (4.2.5.1)
31
+ activesupport (= 4.2.5.1)
32
+ globalid (>= 0.3.0)
33
+ activemodel (4.2.5.1)
34
+ activesupport (= 4.2.5.1)
35
+ builder (~> 3.1)
36
+ activerecord (4.2.5.1)
37
+ activemodel (= 4.2.5.1)
38
+ activesupport (= 4.2.5.1)
39
+ arel (~> 6.0)
40
+ activesupport (4.2.5.1)
41
+ i18n (~> 0.7)
42
+ json (~> 1.7, >= 1.7.7)
43
+ minitest (~> 5.1)
44
+ thread_safe (~> 0.3, >= 0.3.4)
45
+ tzinfo (~> 1.1)
46
+ arel (6.0.3)
47
+ builder (3.2.2)
48
+ byebug (3.5.1)
49
+ columnize (~> 0.8)
50
+ debugger-linecache (~> 1.2)
51
+ slop (~> 3.6)
52
+ coderay (1.1.0)
53
+ columnize (0.9.0)
54
+ concurrent-ruby (1.0.0)
55
+ crass (1.0.2)
56
+ debugger-linecache (1.2.0)
57
+ diff-lcs (1.2.5)
58
+ erubis (2.7.0)
59
+ globalid (0.3.6)
60
+ activesupport (>= 4.1.0)
61
+ i18n (0.7.0)
62
+ json (1.8.3)
63
+ loofah (2.0.3)
64
+ nokogiri (>= 1.5.9)
65
+ mail (2.6.3)
66
+ mime-types (>= 1.16, < 3)
67
+ method_source (0.8.2)
68
+ mime-types (2.99.1)
69
+ mini_portile2 (2.0.0)
70
+ minitest (5.8.4)
71
+ nokogiri (1.6.7.2)
72
+ mini_portile2 (~> 2.0.0.rc2)
73
+ nokogumbo (1.4.7)
74
+ nokogiri
75
+ pry (0.10.1)
76
+ coderay (~> 1.1.0)
77
+ method_source (~> 0.8.1)
78
+ slop (~> 3.4)
79
+ pry-byebug (3.0.1)
80
+ byebug (~> 3.4)
81
+ pry (~> 0.10)
82
+ rack (1.6.4)
83
+ rack-test (0.6.3)
84
+ rack (>= 1.0)
85
+ rails (4.2.5.1)
86
+ actionmailer (= 4.2.5.1)
87
+ actionpack (= 4.2.5.1)
88
+ actionview (= 4.2.5.1)
89
+ activejob (= 4.2.5.1)
90
+ activemodel (= 4.2.5.1)
91
+ activerecord (= 4.2.5.1)
92
+ activesupport (= 4.2.5.1)
93
+ bundler (>= 1.3.0, < 2.0)
94
+ railties (= 4.2.5.1)
95
+ sprockets-rails
96
+ rails-deprecated_sanitizer (1.0.3)
97
+ activesupport (>= 4.2.0.alpha)
98
+ rails-dom-testing (1.0.7)
99
+ activesupport (>= 4.2.0.beta, < 5.0)
100
+ nokogiri (~> 1.6.0)
101
+ rails-deprecated_sanitizer (>= 1.0.1)
102
+ rails-html-sanitizer (1.0.3)
103
+ loofah (~> 2.0)
104
+ railties (4.2.5.1)
105
+ actionpack (= 4.2.5.1)
106
+ activesupport (= 4.2.5.1)
107
+ rake (>= 0.8.7)
108
+ thor (>= 0.18.1, < 2.0)
109
+ rake (10.5.0)
110
+ rspec-core (3.4.3)
111
+ rspec-support (~> 3.4.0)
112
+ rspec-expectations (3.4.0)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.4.0)
115
+ rspec-mocks (3.4.1)
116
+ diff-lcs (>= 1.2.0, < 2.0)
117
+ rspec-support (~> 3.4.0)
118
+ rspec-rails (3.4.2)
119
+ actionpack (>= 3.0, < 4.3)
120
+ activesupport (>= 3.0, < 4.3)
121
+ railties (>= 3.0, < 4.3)
122
+ rspec-core (~> 3.4.0)
123
+ rspec-expectations (~> 3.4.0)
124
+ rspec-mocks (~> 3.4.0)
125
+ rspec-support (~> 3.4.0)
126
+ rspec-support (3.4.1)
127
+ sanitize (4.0.1)
128
+ crass (~> 1.0.2)
129
+ nokogiri (>= 1.4.4)
130
+ nokogumbo (~> 1.4.1)
131
+ slop (3.6.0)
132
+ sprockets (3.5.2)
133
+ concurrent-ruby (~> 1.0)
134
+ rack (> 1, < 3)
135
+ sprockets-rails (3.0.2)
136
+ actionpack (>= 4.0)
137
+ activesupport (>= 4.0)
138
+ sprockets (>= 3.0.0)
139
+ sqlite3 (1.3.11)
140
+ thor (0.19.1)
141
+ thread_safe (0.3.5)
142
+ tzinfo (1.2.2)
143
+ thread_safe (~> 0.1)
144
+
145
+ PLATFORMS
146
+ ruby
147
+
148
+ DEPENDENCIES
149
+ jaimito!
150
+ pry
151
+ pry-byebug
152
+ rspec-rails (~> 3.4.2)
153
+ sqlite3
154
+
155
+ BUNDLED WITH
156
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ThiagoNP
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ rescue LoadError
8
+ # no rspec available
9
+ end
data/jaimito.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'jaimito/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'jaimito'
7
+ s.version = Jaimito::VERSION
8
+ s.description = ''
9
+ s.summary = ''
10
+ s.authors = ['Thiago Porto', 'Hideki Matsumoto']
11
+ s.email = 'contato@vizir.com.br'
12
+ s.version = '0.1.0'
13
+ s.homepage = 'https://github.com/Vizir/jaimito'
14
+ s.files = `git ls-files`.split("\n")
15
+ s.licenses = ['MIT license (MIT)']
16
+
17
+ s.add_dependency 'sanitize', '~> 3.0', '> 3.0.0'
18
+ s.add_dependency 'rails', '~> 4.2', '>= 4.2.0'
19
+
20
+ s.add_development_dependency 'rspec-rails', '~> 3.4', '>= 3.4.2'
21
+ s.add_development_dependency 'pry', '~>3.0.1', '>=3.0.1'
22
+ s.add_development_dependency 'pry-byebug', '~>0.10', '>= 0.10'
23
+ s.add_development_dependency 'sqlite3', '~>1.3.11', '>=1.3.11'
24
+ end
@@ -0,0 +1,23 @@
1
+ module Jaimito
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def install
9
+ template "initializer.rb", "config/initializers/jaimito_initializer.rb"
10
+ template "model.rb", "app/models/mail_template.rb"
11
+ template "mailer.rb", "app/mailers/sample_mailer.rb"
12
+ template "mailer_seed.rb", "db/mailers_seed.rb"
13
+ template "jaimito.yml", "config/locales/jaimito.yml"
14
+ migration_template "migration_create_mail_templates.rb", "db/migrate/create_mail_templates.rb"
15
+ end
16
+
17
+ def self.next_migration_number(dirname)
18
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ Jaimito.configure do |config|
2
+ config.model_name = 'mail_template'
3
+ config.template_subject_attribute = 'subject'
4
+ config.template_body_attribute = 'body'
5
+ config.mailer_name_attribute = 'mailer_name'
6
+ config.method_name_attribute = 'method_name'
7
+ config.locale_attribute = 'locale'
8
+ config.available_locales = [ 'en', 'pt-br' ]
9
+ end
@@ -0,0 +1,15 @@
1
+ en:
2
+ jaimito:
3
+ translated_classes_names:
4
+ user: User
5
+ translated_attributes_names:
6
+ user:
7
+ name: Name
8
+
9
+ pt-br:
10
+ jaimito:
11
+ translated_classes_names:
12
+ user: Usuário
13
+ translated_attributes_names:
14
+ user:
15
+ name: Nome
@@ -0,0 +1,5 @@
1
+ class SampleMailer < ActionMailer::Base
2
+ include Jaimito::Mailer
3
+ default from: "jaimito@example.com"
4
+ get_receiver_email_from user: :email
5
+ end
@@ -0,0 +1,25 @@
1
+ ActiveRecord::Base.transaction do
2
+ MailTemplate.create!(
3
+ subject: 'Welcome [[User - Name]]!',
4
+ body: %Q(
5
+ <b>Welcome [[User - Name]]</b> to our platform!
6
+ <br>
7
+ <a href='example'>Click here</a> if you don't wish to receive emails.
8
+ ),
9
+ mailer_name: 'sample_mailer',
10
+ method_name: 'welcome_mail',
11
+ locale: :en
12
+ )
13
+
14
+ MailTemplate.create!(
15
+ subject: 'Bem vindo [[Usuário - Nome]]!',
16
+ body: %Q(
17
+ <b>Bem vindo [[Usuário - Nome]]</b>!
18
+ <br>
19
+ <a href='example'>Clique aqui</a> para cancelar o recebimento de emails.
20
+ ),
21
+ mailer_name: 'sample_mailer',
22
+ method_name: 'welcome_mail',
23
+ locale: :'pt-br'
24
+ )
25
+ end
@@ -0,0 +1,9 @@
1
+ class CreateMailTemplates < ActiveRecord::Migration
2
+ create_table :mail_templates do | t |
3
+ t.string :subject
4
+ t.text :body
5
+ t.string :mailer_name
6
+ t.string :method_name
7
+ t.string :locale
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ class MailTemplate < ActiveRecord::Base
2
+ validates :subject, presence: true
3
+ validates :body, presence: true
4
+ validates :mailer_name, presence: true
5
+ validates :method_name, presence: true,
6
+ uniqueness: { scope: [:locale, :mailer_name]}
7
+ validates :locale, presence: true,
8
+ inclusion: { in: Jaimito::Config.available_locales }
9
+
10
+ validate :mailer_class_should_exist
11
+
12
+ private
13
+
14
+ def mailer_class_should_exist
15
+ mailer_name.classify.constantize
16
+ rescue
17
+ errors.add(:mailer_name, :invalid)
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Jaimito
2
+
3
+ class Config
4
+ class << self
5
+ attr_accessor :model_name, :mailer_name_attribute, :method_name_attribute,
6
+ :template_subject_attribute, :template_body_attribute,
7
+ :available_locales, :locale_attribute
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,5 @@
1
+ module Jaimito
2
+ module Errors
3
+ class InexistentMailerTemplate < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,73 @@
1
+ module Jaimito
2
+ class MailTemplate
3
+
4
+ def self.exists?(mailer_class, method)
5
+ model_to_fetch_template.find_by(
6
+ config.mailer_name_attribute => mailer_class.name.underscore,
7
+ config.method_name_attribute => method.to_s)
8
+ .present?
9
+ end
10
+
11
+ def self.subject(mailer_class, method, *args)
12
+ template_string = template(mailer_class, method).send(config.template_subject_attribute)
13
+ parse_template_string(template_string, *args)
14
+ end
15
+
16
+ def self.body(mailer_class, method, *args)
17
+ template_string = template(mailer_class, method).send(config.template_body_attribute)
18
+ parse_template_string(template_string, *args)
19
+ end
20
+
21
+ def self.parse_template_string(template_string, *args)
22
+ args.each do |arg|
23
+ class_name = arg.class.name.underscore
24
+ translated_class_name = I18n.t("jaimito.translated_classes_names.#{class_name}")
25
+ attributes_hash = hash_of_attributes_and_translations(arg.class, class_name)
26
+ attributes_hash.each do |key, value|
27
+ template_string.gsub!(/\[\[\s?#{translated_class_name}\s?-\s?#{value}\s?\]\]/i,
28
+ arg.send(key))
29
+ end
30
+ end
31
+ Sanitize.fragment(template_string, Sanitize::Config::RELAXED).html_safe
32
+ end
33
+
34
+ def self.hash_of_attributes_and_translations(klass, class_name)
35
+ attributes_hash = {}
36
+ klass.attribute_names.each do |attr|
37
+ attributes_hash[attr.to_sym] = attr if I18n.exists?( "jaimito.translated_attributes_names.#{class_name}.#{attr}")
38
+ end
39
+ attributes_hash
40
+ end
41
+
42
+ def self.template(mailer_class, method)
43
+ model_to_fetch_template.find_by!(
44
+ config.mailer_name_attribute => mailer_class.name.underscore,
45
+ config.method_name_attribute => method.to_s,
46
+ config.locale_attribute => current_locale
47
+ )
48
+ rescue => e
49
+ raise Jaimito::Errors::InexistentMailerTemplate, %Q(
50
+ The #{config.model_name} #{method} template does not exist!
51
+ )
52
+ end
53
+
54
+ def self.model_to_fetch_template
55
+ config.model_name.classify.constantize
56
+ end
57
+
58
+ def self.config
59
+ Jaimito::Config
60
+ end
61
+
62
+ def self.current_locale
63
+ I18n.locale.to_s
64
+ end
65
+
66
+ private_class_method :parse_template_string
67
+ private_class_method :template
68
+ private_class_method :model_to_fetch_template
69
+ private_class_method :hash_of_attributes_and_translations
70
+ private_class_method :config
71
+ private_class_method :current_locale
72
+ end
73
+ end
@@ -0,0 +1,57 @@
1
+ module Jaimito
2
+ module Mailer
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ @jaimito_mailer_config = {}
7
+
8
+ def self.get_receiver_email_from(model_with_attribute)
9
+ @jaimito_mailer_config[:model_to_get_receiver_email] =
10
+ model_with_attribute.keys.first.to_s.downcase
11
+ @jaimito_mailer_config[:attribute_to_get_receiver_email] =
12
+ model_with_attribute.values.first.to_s
13
+ end
14
+
15
+ def self.model_to_get_receiver_email
16
+ @jaimito_mailer_config[:model_to_get_receiver_email]
17
+ end
18
+
19
+ def self.attribute_to_get_receiver_email
20
+ @jaimito_mailer_config[:attribute_to_get_receiver_email]
21
+ end
22
+
23
+ def self.method_missing(method, *args, &block)
24
+ if Jaimito::MailTemplate.exists?(self, method)
25
+ define_mailer_method(method)
26
+ return self.send(method, *args)
27
+ end
28
+ super
29
+ end
30
+
31
+ private
32
+
33
+ def self.define_mailer_method(method)
34
+ define_method method do | *args |
35
+ mail(
36
+ to: self.class.get_receiver_email(*args),
37
+ subject: Jaimito::MailTemplate.subject(self.class, method, *args),
38
+ ) do |format|
39
+ format.html{ render html: Jaimito::MailTemplate.body(self.class, method, *args), layout: _layout }
40
+ end
41
+ end
42
+
43
+ define_singleton_method method do | *args |
44
+ self.send(:new).send(method, *args)
45
+ end
46
+ end
47
+
48
+ def self.get_receiver_email(*args)
49
+ args.each do | arg |
50
+ if arg.class.name.downcase == self.model_to_get_receiver_email
51
+ return arg.send(self.attribute_to_get_receiver_email)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Jaimito
2
+ VERSION = '0.1.0'
3
+ end
data/lib/jaimito.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'action_mailer'
4
+ require 'sanitize'
5
+ require 'active_record'
6
+ require 'jaimito/version'
7
+ require 'jaimito/errors'
8
+ require 'jaimito/config'
9
+ require 'jaimito/mail_template'
10
+ require 'jaimito/mailer'
11
+
12
+ module Jaimito
13
+ def self.configure
14
+ yield Config
15
+ end
16
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jaimito::Mailer do
4
+ before(:all) do
5
+ class TestMailer < ActionMailer::Base
6
+ include Jaimito::Mailer
7
+ default from: "a@a.com"
8
+ get_receiver_email_from user: :email
9
+ end
10
+ end
11
+ before(:each) { ActionMailer::Base.deliveries.clear }
12
+
13
+ it 'sends a email' do
14
+ Jaimito.configure do |config|
15
+ config.model_name = 'mail_template_test'
16
+ config.locale_attribute = 'locale'
17
+ config.template_subject_attribute = 'subject'
18
+ config.template_body_attribute = 'body'
19
+ config.mailer_name_attribute = 'mailer_name'
20
+ config.method_name_attribute = 'method_name'
21
+ config.available_locales = [ 'en', 'pt-br' ]
22
+ end
23
+ user = User.create(email: 'user@user.com', name: 'jaimito')
24
+
25
+ MailTemplateTest.create!(
26
+ subject: 'Welcome [[User - Name]]!',
27
+ body: %Q(<b>Welcome [[User - Name]]</b> to our platform!),
28
+ mailer_name: 'test_mailer',
29
+ method_name: 'sample_mail',
30
+ locale: :en
31
+ )
32
+
33
+ TestMailer.sample_mail(user).deliver
34
+ expect(ActionMailer::Base.deliveries.count).to eq(1)
35
+ end
36
+
37
+ it 'changes const name' do
38
+ TranslationsCreater.create_classes_name("user", "user")
39
+ TranslationsCreater.create_attributes_name("user", "name", "name")
40
+
41
+ Jaimito.configure do |config|
42
+ config.model_name = 'mail_template_test'
43
+ config.locale_attribute = 'locale'
44
+ config.template_subject_attribute = 'subject'
45
+ config.template_body_attribute = 'body'
46
+ config.mailer_name_attribute = 'mailer_name'
47
+ config.method_name_attribute = 'method_name'
48
+ config.available_locales = [ 'en', 'pt-br' ]
49
+ end
50
+ user = User.create(email: 'user@user.com', name: 'jaimito')
51
+
52
+ MailTemplateTest.create!(
53
+ subject: 'Welcome [[User - Name]]!',
54
+ body: %Q(<b>Welcome [[User - Name]]</b> to our platform!),
55
+ mailer_name: 'test_mailer',
56
+ method_name: 'sample_mail',
57
+ locale: :en
58
+ )
59
+
60
+ mailer = TestMailer.sample_mail(user)
61
+ expect(mailer.subject.include?(user.name)).to be true
62
+ end
63
+
64
+ it 'changes const name from both classes' do
65
+ TranslationsCreater.create_classes_name("user", "user")
66
+ TranslationsCreater.create_classes_name("admin", "admin")
67
+ TranslationsCreater.create_attributes_name("user", "name", "name")
68
+ TranslationsCreater.create_attributes_name("admin", "name", "name")
69
+
70
+ Jaimito.configure do |config|
71
+ config.model_name = 'mail_template_test'
72
+ config.locale_attribute = 'locale'
73
+ config.template_subject_attribute = 'subject'
74
+ config.template_body_attribute = 'body'
75
+ config.mailer_name_attribute = 'mailer_name'
76
+ config.method_name_attribute = 'method_name'
77
+ config.available_locales = [ 'en', 'pt-br' ]
78
+ end
79
+ user = User.create(email: 'user@user.com', name: 'jaimito')
80
+ admin = Admin.create(email: 'admin@admin.com', name: 'admin')
81
+
82
+ MailTemplateTest.create!(
83
+ subject: '[[User - Name]] want to subscribe!',
84
+ body: %Q(<b>[[Admin - Name]]</b> [[User - Name]] want to subscribe!),
85
+ mailer_name: 'test_mailer',
86
+ method_name: 'admin_mail',
87
+ locale: :en
88
+ )
89
+
90
+ mailer = TestMailer.admin_mail(user, admin)
91
+ expect(mailer.subject.include?(user.name)).to be true
92
+ expect(mailer.body.raw_source.include?(admin.name)).to be true
93
+ end
94
+ end
@@ -0,0 +1,49 @@
1
+ require 'pry'
2
+ require 'pry-byebug'
3
+ require 'jaimito'
4
+ require 'action_controller'
5
+
6
+ Dir[File.expand_path('spec/support/**/*.rb'), __FILE__].each { |f| require f }
7
+
8
+ RSpec.configure do |config|
9
+ config.expect_with :rspec do |expectations|
10
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
11
+ end
12
+ config.mock_with :rspec do |mocks|
13
+ mocks.verify_partial_doubles = true
14
+ end
15
+
16
+ config.before(:suite) do
17
+ class MailTemplateTest < ActiveRecord::Base; end
18
+ class User < ActiveRecord::Base; end
19
+ class Admin < ActiveRecord::Base; end
20
+
21
+ ActiveRecord::Base.establish_connection(
22
+ adapter: 'sqlite3',
23
+ database: ':memory:'
24
+ )
25
+
26
+ silence_stream(STDOUT) do
27
+ ActiveRecord::Migration.class_eval do
28
+ create_table :users do |t|
29
+ t.string :email
30
+ t.text :name
31
+ end
32
+
33
+ create_table :admins do |t|
34
+ t.string :email
35
+ t.text :name
36
+ end
37
+
38
+ create_table :mail_template_tests do |t|
39
+ t.string :subject
40
+ t.text :body
41
+ t.string :mailer_name
42
+ t.string :method_name
43
+ t.string :locale
44
+ end
45
+ end
46
+ end
47
+ ActionMailer::Base.delivery_method = :test
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ class TranslationsCreater
2
+ def self.create_classes_name(key, value)
3
+ I18n.backend.store_translations(:en, {
4
+ jaimito: {translated_classes_names: {key => value}}
5
+ })
6
+
7
+ I18n.backend.store_translations(:pt, {
8
+ jaimito: {translated_classes_names: {key => value}}
9
+ })
10
+ end
11
+
12
+ def self.create_attributes_name(class_name, key, value)
13
+ I18n.backend.store_translations(:en, {jaimito: {translated_attributes_names: { class_name => {key => value}}
14
+ }})
15
+
16
+ I18n.backend.store_translations(:pt, {
17
+ jaimito: {translated_attributes_names: { class_name => {key => value}}
18
+ }})
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jaimito
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thiago Porto
8
+ - Hideki Matsumoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-04-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sanitize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '3.0'
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ - !ruby/object:Gem::Dependency
35
+ name: rails
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 4.2.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '4.2'
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 4.2.0
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec-rails
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.4'
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.4.2
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.4'
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 3.4.2
74
+ - !ruby/object:Gem::Dependency
75
+ name: pry
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 3.0.1
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 3.0.1
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 3.0.1
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 3.0.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry-byebug
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '0.10'
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0.10'
114
+ - !ruby/object:Gem::Dependency
115
+ name: sqlite3
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: 1.3.11
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 1.3.11
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 1.3.11
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.11
134
+ description: ''
135
+ email: contato@vizir.com.br
136
+ executables: []
137
+ extensions: []
138
+ extra_rdoc_files: []
139
+ files:
140
+ - ".gitignore"
141
+ - ".rspec"
142
+ - Gemfile
143
+ - Gemfile.lock
144
+ - LICENSE
145
+ - README.md
146
+ - Rakefile
147
+ - jaimito.gemspec
148
+ - lib/generators/jaimito/install_generator.rb
149
+ - lib/generators/jaimito/templates/initializer.rb
150
+ - lib/generators/jaimito/templates/jaimito.yml
151
+ - lib/generators/jaimito/templates/mailer.rb
152
+ - lib/generators/jaimito/templates/mailer_seed.rb
153
+ - lib/generators/jaimito/templates/migration_create_mail_templates.rb
154
+ - lib/generators/jaimito/templates/model.rb
155
+ - lib/jaimito.rb
156
+ - lib/jaimito/config.rb
157
+ - lib/jaimito/errors.rb
158
+ - lib/jaimito/mail_template.rb
159
+ - lib/jaimito/mailer.rb
160
+ - lib/jaimito/version.rb
161
+ - spec/app/jaimito_mailer_spec.rb
162
+ - spec/spec_helper.rb
163
+ - spec/support/translations_creater.rb
164
+ homepage: https://github.com/Vizir/jaimito
165
+ licenses:
166
+ - MIT license (MIT)
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.2.2
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: ''
188
+ test_files: []