effective_email_templates 0.6.1 → 1.0.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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +22 -36
  4. data/app/controllers/admin/email_templates_controller.rb +25 -16
  5. data/app/datatables/effective_email_templates_datatable.rb +10 -5
  6. data/app/mailers/effective/email_templates_mailer.rb +22 -0
  7. data/app/models/effective/email_template.rb +66 -34
  8. data/app/views/admin/email_templates/_actions.html.haml +5 -2
  9. data/app/views/admin/email_templates/_form.html.haml +16 -9
  10. data/app/views/admin/email_templates/index.html.haml +1 -1
  11. data/app/views/layouts/effective_email_templates_mailer_layout.html.haml +7 -0
  12. data/config/effective_email_templates.rb +16 -25
  13. data/config/routes.rb +6 -8
  14. data/db/migrate/01_create_effective_email_templates.rb.erb +14 -8
  15. data/lib/effective_email_templates/engine.rb +1 -1
  16. data/lib/effective_email_templates/importer.rb +55 -0
  17. data/lib/effective_email_templates/version.rb +1 -1
  18. data/lib/effective_email_templates.rb +18 -14
  19. data/lib/generators/effective_email_templates/install_generator.rb +1 -1
  20. data/lib/tasks/effective_email_templates_tasks.rake +19 -0
  21. metadata +35 -146
  22. data/Rakefile +0 -23
  23. data/app/assets/javascripts/effective_email_templates.js +0 -1
  24. data/app/assets/stylesheets/effective_email_templates.css.scss +0 -1
  25. data/app/helpers/effective_email_templates_helper.rb +0 -19
  26. data/app/mailers/effective/email_template_mailer.rb +0 -14
  27. data/app/views/effective/email_template_mailer/templated_email.html.haml +0 -1
  28. data/lib/effective/liquid_mailer.rb +0 -15
  29. data/lib/effective_email_templates/email_view_template.rb +0 -42
  30. data/lib/effective_email_templates/liquid_resolver.rb +0 -46
  31. data/lib/effective_email_templates/template_importer.rb +0 -51
  32. data/lib/tasks/effective_email_templates/import_default_views.rake +0 -19
  33. data/spec/controllers/admin/email_templates_controller_spec.rb +0 -60
  34. data/spec/dummy/README.rdoc +0 -28
  35. data/spec/dummy/Rakefile +0 -6
  36. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  37. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  38. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  39. data/spec/dummy/app/controllers/welcome_controller.rb +0 -4
  40. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  41. data/spec/dummy/app/mailers/liquid_resolved_mailer.rb +0 -9
  42. data/spec/dummy/app/mailers/user_liquid_mailer.rb +0 -10
  43. data/spec/dummy/app/models/user.rb +0 -15
  44. data/spec/dummy/app/views/layouts/application.html.erb +0 -17
  45. data/spec/dummy/app/views/user_liquid/after_create_user.liquid +0 -7
  46. data/spec/dummy/app/views/welcome/index.html.haml +0 -1
  47. data/spec/dummy/bin/bundle +0 -3
  48. data/spec/dummy/bin/rails +0 -4
  49. data/spec/dummy/bin/rake +0 -4
  50. data/spec/dummy/config/application.rb +0 -26
  51. data/spec/dummy/config/boot.rb +0 -5
  52. data/spec/dummy/config/database.yml +0 -25
  53. data/spec/dummy/config/environment.rb +0 -5
  54. data/spec/dummy/config/environments/development.rb +0 -37
  55. data/spec/dummy/config/environments/production.rb +0 -78
  56. data/spec/dummy/config/environments/test.rb +0 -40
  57. data/spec/dummy/config/initializers/assets.rb +0 -8
  58. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  59. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  60. data/spec/dummy/config/initializers/devise.rb +0 -259
  61. data/spec/dummy/config/initializers/effective_email_templates.rb +0 -51
  62. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  63. data/spec/dummy/config/initializers/inflections.rb +0 -16
  64. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  65. data/spec/dummy/config/initializers/session_store.rb +0 -3
  66. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  67. data/spec/dummy/config/locales/devise.en.yml +0 -60
  68. data/spec/dummy/config/locales/en.yml +0 -23
  69. data/spec/dummy/config/routes.rb +0 -57
  70. data/spec/dummy/config/secrets.yml +0 -22
  71. data/spec/dummy/config.ru +0 -4
  72. data/spec/dummy/db/migrate/20141126222940_devise_create_users.rb +0 -42
  73. data/spec/dummy/db/migrate/20141126222941_create_effective_email_templates.rb +0 -20
  74. data/spec/dummy/db/schema.rb +0 -46
  75. data/spec/dummy/public/404.html +0 -67
  76. data/spec/dummy/public/422.html +0 -67
  77. data/spec/dummy/public/500.html +0 -66
  78. data/spec/dummy/public/favicon.ico +0 -0
  79. data/spec/effective_email_templates_spec.rb +0 -35
  80. data/spec/factories/email_template.rb +0 -12
  81. data/spec/factories/user.rb +0 -16
  82. data/spec/factory_spec.rb +0 -10
  83. data/spec/lib/effective_email_templates/template_importer_spec.rb +0 -73
  84. data/spec/mailers/liquid_resolved_mailer_spec.rb +0 -38
  85. data/spec/models/email_template_spec.rb +0 -61
  86. data/spec/models/user_spec.rb +0 -10
  87. data/spec/sanity_spec.rb +0 -7
  88. data/spec/spec_helper.rb +0 -26
@@ -8,7 +8,7 @@ module EffectiveEmailTemplates
8
8
  source_root File.expand_path('../../templates', __FILE__)
9
9
 
10
10
  def self.next_migration_number(dirname)
11
- if not ActiveRecord::Base.timestamped_migrations
11
+ unless ActiveRecord::Base.timestamped_migrations
12
12
  Time.new.utc.strftime("%Y%m%d%H%M%S")
13
13
  else
14
14
  "%.3d" % (current_migration_number(dirname) + 1)
@@ -0,0 +1,19 @@
1
+ # rake effective_email_templates:import
2
+ # rake effective_email_templates:overwrite
3
+
4
+ namespace :effective_email_templates do
5
+ desc 'Import email templates from the filesystem to the database. Skips existing.'
6
+ task import: :environment do
7
+ require 'effective_email_templates/importer'
8
+ EffectiveEmailTemplates::Importer.import()
9
+ end
10
+
11
+ desc 'Overwrite email templates from the filesystem to the database. Overwrites existing.'
12
+ task overwrite: :environment do
13
+ puts 'WARNING: this task will overwrite existing email templates. Proceed? (y/n)'
14
+ (puts 'Aborted'; exit) unless STDIN.gets.chomp.downcase == 'y'
15
+
16
+ require 'effective_email_templates/importer'
17
+ EffectiveEmailTemplates::Importer.overwrite()
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_email_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2020-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: coffee-rails
28
+ name: liquid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,27 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: liquid
42
+ name: coffee-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- - - "<"
45
+ - - ">="
49
46
  - !ruby/object:Gem::Version
50
- version: '4'
47
+ version: '0'
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '3.0'
58
- - - "<"
52
+ - - ">="
59
53
  - !ruby/object:Gem::Version
60
- version: '4'
54
+ version: '0'
61
55
  - !ruby/object:Gem::Dependency
62
- name: simple_form
56
+ name: effective_bootstrap
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - ">="
@@ -78,15 +72,29 @@ dependencies:
78
72
  requirements:
79
73
  - - ">="
80
74
  - !ruby/object:Gem::Version
81
- version: 2.0.0
75
+ version: 4.0.0
82
76
  type: :runtime
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - ">="
87
81
  - !ruby/object:Gem::Version
88
- version: 2.0.0
89
- description: Uses liquid templates
82
+ version: 4.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: effective_resources
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Effective Email Templates provides an admin access to modify email templates
90
98
  email:
91
99
  - info@codeandeffect.com
92
100
  executables: []
@@ -95,93 +103,30 @@ extra_rdoc_files: []
95
103
  files:
96
104
  - MIT-LICENSE
97
105
  - README.md
98
- - Rakefile
99
- - app/assets/javascripts/effective_email_templates.js
100
- - app/assets/stylesheets/effective_email_templates.css.scss
101
106
  - app/controllers/admin/email_templates_controller.rb
102
107
  - app/datatables/effective_email_templates_datatable.rb
103
- - app/helpers/effective_email_templates_helper.rb
104
- - app/mailers/effective/email_template_mailer.rb
108
+ - app/mailers/effective/email_templates_mailer.rb
105
109
  - app/models/effective/access_denied.rb
106
110
  - app/models/effective/email_template.rb
107
111
  - app/views/admin/email_templates/_actions.html.haml
108
112
  - app/views/admin/email_templates/_form.html.haml
109
113
  - app/views/admin/email_templates/edit.html.haml
110
114
  - app/views/admin/email_templates/index.html.haml
111
- - app/views/effective/email_template_mailer/templated_email.html.haml
115
+ - app/views/layouts/effective_email_templates_mailer_layout.html.haml
112
116
  - config/effective_email_templates.rb
113
117
  - config/routes.rb
114
118
  - db/migrate/01_create_effective_email_templates.rb.erb
115
- - lib/effective/liquid_mailer.rb
116
119
  - lib/effective_email_templates.rb
117
- - lib/effective_email_templates/email_view_template.rb
118
120
  - lib/effective_email_templates/engine.rb
119
- - lib/effective_email_templates/liquid_resolver.rb
120
- - lib/effective_email_templates/template_importer.rb
121
+ - lib/effective_email_templates/importer.rb
121
122
  - lib/effective_email_templates/version.rb
122
123
  - lib/generators/effective_email_templates/install_generator.rb
123
- - lib/tasks/effective_email_templates/import_default_views.rake
124
- - spec/controllers/admin/email_templates_controller_spec.rb
125
- - spec/dummy/README.rdoc
126
- - spec/dummy/Rakefile
127
- - spec/dummy/app/assets/javascripts/application.js
128
- - spec/dummy/app/assets/stylesheets/application.css
129
- - spec/dummy/app/controllers/application_controller.rb
130
- - spec/dummy/app/controllers/welcome_controller.rb
131
- - spec/dummy/app/helpers/application_helper.rb
132
- - spec/dummy/app/mailers/liquid_resolved_mailer.rb
133
- - spec/dummy/app/mailers/user_liquid_mailer.rb
134
- - spec/dummy/app/models/user.rb
135
- - spec/dummy/app/views/layouts/application.html.erb
136
- - spec/dummy/app/views/user_liquid/after_create_user.liquid
137
- - spec/dummy/app/views/welcome/index.html.haml
138
- - spec/dummy/bin/bundle
139
- - spec/dummy/bin/rails
140
- - spec/dummy/bin/rake
141
- - spec/dummy/config.ru
142
- - spec/dummy/config/application.rb
143
- - spec/dummy/config/boot.rb
144
- - spec/dummy/config/database.yml
145
- - spec/dummy/config/environment.rb
146
- - spec/dummy/config/environments/development.rb
147
- - spec/dummy/config/environments/production.rb
148
- - spec/dummy/config/environments/test.rb
149
- - spec/dummy/config/initializers/assets.rb
150
- - spec/dummy/config/initializers/backtrace_silencers.rb
151
- - spec/dummy/config/initializers/cookies_serializer.rb
152
- - spec/dummy/config/initializers/devise.rb
153
- - spec/dummy/config/initializers/effective_email_templates.rb
154
- - spec/dummy/config/initializers/filter_parameter_logging.rb
155
- - spec/dummy/config/initializers/inflections.rb
156
- - spec/dummy/config/initializers/mime_types.rb
157
- - spec/dummy/config/initializers/session_store.rb
158
- - spec/dummy/config/initializers/wrap_parameters.rb
159
- - spec/dummy/config/locales/devise.en.yml
160
- - spec/dummy/config/locales/en.yml
161
- - spec/dummy/config/routes.rb
162
- - spec/dummy/config/secrets.yml
163
- - spec/dummy/db/migrate/20141126222940_devise_create_users.rb
164
- - spec/dummy/db/migrate/20141126222941_create_effective_email_templates.rb
165
- - spec/dummy/db/schema.rb
166
- - spec/dummy/public/404.html
167
- - spec/dummy/public/422.html
168
- - spec/dummy/public/500.html
169
- - spec/dummy/public/favicon.ico
170
- - spec/effective_email_templates_spec.rb
171
- - spec/factories/email_template.rb
172
- - spec/factories/user.rb
173
- - spec/factory_spec.rb
174
- - spec/lib/effective_email_templates/template_importer_spec.rb
175
- - spec/mailers/liquid_resolved_mailer_spec.rb
176
- - spec/models/email_template_spec.rb
177
- - spec/models/user_spec.rb
178
- - spec/sanity_spec.rb
179
- - spec/spec_helper.rb
124
+ - lib/tasks/effective_email_templates_tasks.rake
180
125
  homepage: https://github.com/code-and-effect/effective_email_templates
181
126
  licenses:
182
127
  - MIT
183
128
  metadata: {}
184
- post_install_message:
129
+ post_install_message:
185
130
  rdoc_options: []
186
131
  require_paths:
187
132
  - lib
@@ -196,64 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
141
  - !ruby/object:Gem::Version
197
142
  version: '0'
198
143
  requirements: []
199
- rubygems_version: 3.1.2
200
- signing_key:
144
+ rubygems_version: 3.0.3
145
+ signing_key:
201
146
  specification_version: 4
202
147
  summary: Effective Email Templates provides an admin access to modify email templates
203
- test_files:
204
- - spec/spec_helper.rb
205
- - spec/sanity_spec.rb
206
- - spec/dummy/app/mailers/user_liquid_mailer.rb
207
- - spec/dummy/app/mailers/liquid_resolved_mailer.rb
208
- - spec/dummy/app/models/user.rb
209
- - spec/dummy/app/controllers/application_controller.rb
210
- - spec/dummy/app/controllers/welcome_controller.rb
211
- - spec/dummy/app/views/welcome/index.html.haml
212
- - spec/dummy/app/views/layouts/application.html.erb
213
- - spec/dummy/app/views/user_liquid/after_create_user.liquid
214
- - spec/dummy/app/assets/javascripts/application.js
215
- - spec/dummy/app/assets/stylesheets/application.css
216
- - spec/dummy/app/helpers/application_helper.rb
217
- - spec/dummy/bin/rake
218
- - spec/dummy/bin/bundle
219
- - spec/dummy/bin/rails
220
- - spec/dummy/config/secrets.yml
221
- - spec/dummy/config/routes.rb
222
- - spec/dummy/config/locales/en.yml
223
- - spec/dummy/config/locales/devise.en.yml
224
- - spec/dummy/config/environments/production.rb
225
- - spec/dummy/config/environments/development.rb
226
- - spec/dummy/config/environments/test.rb
227
- - spec/dummy/config/environment.rb
228
- - spec/dummy/config/application.rb
229
- - spec/dummy/config/database.yml
230
- - spec/dummy/config/boot.rb
231
- - spec/dummy/config/initializers/backtrace_silencers.rb
232
- - spec/dummy/config/initializers/mime_types.rb
233
- - spec/dummy/config/initializers/filter_parameter_logging.rb
234
- - spec/dummy/config/initializers/session_store.rb
235
- - spec/dummy/config/initializers/wrap_parameters.rb
236
- - spec/dummy/config/initializers/assets.rb
237
- - spec/dummy/config/initializers/cookies_serializer.rb
238
- - spec/dummy/config/initializers/devise.rb
239
- - spec/dummy/config/initializers/inflections.rb
240
- - spec/dummy/config/initializers/effective_email_templates.rb
241
- - spec/dummy/config.ru
242
- - spec/dummy/Rakefile
243
- - spec/dummy/public/favicon.ico
244
- - spec/dummy/public/422.html
245
- - spec/dummy/public/500.html
246
- - spec/dummy/public/404.html
247
- - spec/dummy/db/schema.rb
248
- - spec/dummy/db/migrate/20141126222940_devise_create_users.rb
249
- - spec/dummy/db/migrate/20141126222941_create_effective_email_templates.rb
250
- - spec/dummy/README.rdoc
251
- - spec/factory_spec.rb
252
- - spec/mailers/liquid_resolved_mailer_spec.rb
253
- - spec/models/email_template_spec.rb
254
- - spec/models/user_spec.rb
255
- - spec/factories/email_template.rb
256
- - spec/factories/user.rb
257
- - spec/lib/effective_email_templates/template_importer_spec.rb
258
- - spec/effective_email_templates_spec.rb
259
- - spec/controllers/admin/email_templates_controller_spec.rb
148
+ test_files: []
data/Rakefile DELETED
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
-
8
- # Our tasks
9
- load 'lib/tasks/effective_email_templates/import_default_views.rake'
10
-
11
- # Testing tasks
12
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
13
- load 'rails/tasks/engine.rake'
14
-
15
- Bundler::GemHelper.install_tasks
16
-
17
- require 'rspec/core'
18
- require 'rspec/core/rake_task'
19
-
20
- desc "Run all specs in spec directory (excluding plugin specs)"
21
- RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
22
-
23
- task :default => :spec
@@ -1 +0,0 @@
1
- //= require_tree ./effective_email_templates
@@ -1,19 +0,0 @@
1
- module EffectiveEmailTemplatesHelper
2
- def datatable_of(description_of_objects, datatable)
3
- if datatable.nil?
4
- content_tag(:p, "Please use Effective Datatables gem")
5
- elsif datatable.collection.length > 0
6
- render_datatable(datatable)
7
- else
8
- content_tag(:p, "There are no email templates")
9
- end
10
- end
11
-
12
- def email_template_form_url( email_template )
13
- if email_template.new_record?
14
- effective_email_templates.admin_email_templates_path
15
- else
16
- effective_email_templates.admin_email_template_path( email_template )
17
- end
18
- end
19
- end
@@ -1,14 +0,0 @@
1
- module Effective
2
- class EmailTemplateMailer < ActionMailer::Base
3
- def templated_email(address, body, email_template, options)
4
- @body = body
5
- mail(
6
- to: address,
7
- from: email_template.from,
8
- subject: email_template.subject,
9
- cc: options.fetch(:cc, false),
10
- bcc: options.fetch(:bcc, false),
11
- )
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- module Effective
2
- class LiquidMailer < (defined?(::ApplicationMailer) ? ::ApplicationMailer : ::ActionMailer::Base)
3
- def mail(headers = {}, &block)
4
- # this be dangerous and requires ruby 2.0+
5
- mail_method = caller_locations(1, 1)[0].label
6
- options = EffectiveEmailTemplates.get(mail_method).mail_options
7
-
8
- if options[:subject].present?
9
- options[:subject] = Liquid::Template.parse(options[:subject]).render(@to_liquid) rescue options[:subject]
10
- end
11
-
12
- super(headers.merge(options), &block)
13
- end
14
- end
15
- end
@@ -1,42 +0,0 @@
1
- module EffectiveEmailTemplates
2
- class EmailViewTemplate
3
- def initialize( effective_email_template )
4
- @effective_email_template = effective_email_template
5
- end
6
-
7
- attr_accessor :locals
8
- attr_reader :effective_email_template
9
-
10
- def render(view, locals, buffer=nil, &block)
11
- # The view object here is an anonymous view object (it has a class
12
- # of Class). It has all of the view helper methods inside of it.
13
-
14
- if view.assigns['email_body']
15
- effective_email_template.body = view.assigns['email_body']
16
- effective_email_template.precompile
17
-
18
- if effective_email_template.errors[:template].present?
19
- raise "Email body error: #{effective_email_template.errors[:template].join('')}"
20
- end
21
- end
22
-
23
- effective_email_template.render(view.assigns['to_liquid'])
24
- end
25
-
26
- def format
27
- :html
28
- end
29
-
30
- def formats
31
- [:html]
32
- end
33
-
34
- def identifier
35
- effective_email_template.slug
36
- end
37
-
38
- def type
39
- formats.first
40
- end
41
- end
42
- end
@@ -1,46 +0,0 @@
1
- module EffectiveEmailTemplates
2
- class LiquidResolver < ::ActionView::Resolver
3
-
4
- attr_reader :name, :prefix
5
- alias_method :slug, :name
6
-
7
- def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
8
- # key is used for caching which we won't do since
9
- # these templates can be updated at any time by
10
- # an admin. TODO: expire the resolver's cache when
11
- # a template is updated rather than skip caching
12
- @name = name
13
- @prefix = prefix
14
-
15
- return [] unless liquid_mailer?
16
-
17
- templates = collect_view_templates
18
- decorate(templates, [name, prefix, partial], details, locals)
19
- templates
20
- end
21
-
22
- private
23
-
24
- # Ensures all the resolver information is set in the template.
25
- def decorate(templates, path_info, details, locals)
26
- templates.each do |t|
27
- t.locals = locals
28
- end
29
- end
30
-
31
- def collect_view_templates
32
- effective_email_templates.map do |eet|
33
- EmailViewTemplate.new(eet)
34
- end
35
- end
36
-
37
- def effective_email_templates
38
- Array.wrap(Effective::EmailTemplate.find_by_slug(slug))
39
- end
40
-
41
- def liquid_mailer?
42
- prefix =~ /liquid/
43
- end
44
- end
45
- end
46
-
@@ -1,51 +0,0 @@
1
- module EffectiveEmailTemplates
2
- class TemplateImporter
3
- def self.invoke(importer = new, overwrite: false)
4
- importer.invoke(overwrite)
5
- end
6
-
7
- def invoke(overwrite = false)
8
- Dir[Rails.root.join('app', 'views', '**', '*.liquid')].each do |liquid_template_filepath|
9
- slug = File.basename(liquid_template_filepath, '.liquid')
10
- template = Effective::EmailTemplate.find_or_initialize_by(slug: slug)
11
-
12
- update_template(template, liquid_template_filepath) if (template.persisted? && overwrite) || template.new_record?
13
- end
14
- end
15
-
16
- private
17
-
18
- def add_template_meta(file, template)
19
- template.attributes = File.open(file) do |f|
20
- attr = YAML.load(f)
21
- attr.is_a?(Hash) ? attr : {}
22
- end
23
- template
24
- end
25
-
26
- def extract_template_body(file)
27
- contents = file.read
28
- match = contents.match(/(---+(.|\n)+---+)/)
29
-
30
- contents.gsub(match[1], '').strip if match
31
- end
32
-
33
- def print_errors(template, liquid_template_filepath)
34
- puts 'ERROR -- There was one or more validation errors while uploading:'
35
- puts " Email Template: #{liquid_template_filepath}"
36
- template.errors.each do |attribute, error|
37
- puts " -> #{attribute} #{error}"
38
- end
39
- end
40
-
41
- def update_template(template, liquid_template_filepath)
42
- file = File.new(liquid_template_filepath, 'r')
43
-
44
- template = add_template_meta(file, template)
45
- template.body = extract_template_body(file)
46
- template.save
47
-
48
- print_errors(template, liquid_template_filepath) unless template.valid?
49
- end
50
- end
51
- end
@@ -1,19 +0,0 @@
1
- namespace :effective_email_templates do
2
- desc 'Import email templates from the filesystem to the database. This rake task does not overwrite existing database templates.'
3
- task import_templates: :environment do
4
- EffectiveEmailTemplates::TemplateImporter.invoke
5
- end
6
-
7
- desc 'Overwrite existing default database email templates from the filesystem.'
8
- task overwrite_templates: :environment do
9
- puts 'By running this task, all email templates that exist in the database will be overwritten by the templates in the filesystem. Do you still want to run this task? (Y/n): '
10
- answer = $stdin.gets.chomp
11
-
12
- if answer.downcase == 'y'
13
- EffectiveEmailTemplates::TemplateImporter.invoke(overwrite: true)
14
- puts 'Default email templates have been overwritten successfully!'
15
- else
16
- puts 'Cancelled!'
17
- end
18
- end
19
- end
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Admin::EmailTemplatesController do
4
- context "as an admin" do
5
- before :each do
6
- @admin = create(:admin)
7
- sign_in @admin
8
- end
9
-
10
- describe "#index" do
11
- it 'opens' do
12
- get :index, :use_route => :effective_email_templates
13
- expect(response.status).to eq 200
14
- end
15
- end
16
-
17
- describe "#new" do
18
- it 'opens' do
19
- get :new, :use_route => :effective_email_templates
20
- expect(response.status).to eq 200
21
- end
22
- end
23
-
24
- describe "#create" do
25
- it 'creates an email template' do
26
- expect{
27
- post :create, effective_email_template: attributes_for(:email_template), :use_route => :effective_email_templates
28
- }.to change(Effective::EmailTemplate,:count).by(1)
29
- end
30
- end
31
-
32
- context "member actions" do
33
- before :each do
34
- @email_template = create(:email_template)
35
- end
36
-
37
- describe "#edit" do
38
- it 'opens' do
39
- get :edit, :id => @email_template.id, :use_route => :effective_email_templates
40
- expect(response.status).to eq 200
41
- end
42
- end
43
-
44
- describe "#update" do
45
- it 'updates an email template' do
46
- attributes = @email_template.attributes
47
- old_from = @email_template.from
48
- new_from = "gfssljewr@dsfa.com"
49
- attributes["from"] = new_from
50
- expect{
51
- patch :update, id: @email_template.id, effective_email_template: attributes, :use_route => :effective_email_templates
52
- @email_template.reload
53
- }.to change(@email_template,:from)
54
- end
55
- end
56
- end
57
-
58
- end
59
- end
60
-
@@ -1,28 +0,0 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.
data/spec/dummy/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
-
6
- Rails.application.load_tasks
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,5 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
- end