effective_email_templates 0.5.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +22 -36
- data/app/controllers/admin/email_templates_controller.rb +25 -16
- data/app/datatables/effective_email_templates_datatable.rb +18 -16
- data/app/mailers/effective/email_templates_mailer.rb +22 -0
- data/app/models/effective/email_template.rb +66 -34
- data/app/views/admin/email_templates/_actions.html.haml +5 -2
- data/app/views/admin/email_templates/_form.html.haml +16 -9
- data/app/views/admin/email_templates/index.html.haml +1 -1
- data/app/views/layouts/effective_email_templates_mailer_layout.html.haml +7 -0
- data/config/effective_email_templates.rb +16 -25
- data/config/routes.rb +6 -8
- data/db/migrate/01_create_effective_email_templates.rb.erb +14 -8
- data/lib/effective_email_templates.rb +18 -14
- data/lib/effective_email_templates/engine.rb +1 -1
- data/lib/effective_email_templates/importer.rb +55 -0
- data/lib/effective_email_templates/version.rb +1 -1
- data/lib/generators/effective_email_templates/install_generator.rb +1 -1
- data/lib/tasks/effective_email_templates_tasks.rake +19 -0
- metadata +30 -142
- data/Rakefile +0 -23
- data/app/assets/javascripts/effective_email_templates.js +0 -1
- data/app/assets/stylesheets/effective_email_templates.css.scss +0 -1
- data/app/helpers/effective_email_templates_helper.rb +0 -19
- data/app/mailers/effective/email_template_mailer.rb +0 -14
- data/app/models/effective/datatables/email_templates.rb +0 -24
- data/app/views/effective/email_template_mailer/templated_email.html.haml +0 -1
- data/lib/effective/liquid_mailer.rb +0 -15
- data/lib/effective_email_templates/email_view_template.rb +0 -39
- data/lib/effective_email_templates/liquid_resolver.rb +0 -46
- data/lib/effective_email_templates/template_importer.rb +0 -51
- data/lib/tasks/effective_email_templates/import_default_views.rake +0 -19
- data/spec/controllers/admin/email_templates_controller_spec.rb +0 -60
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/welcome_controller.rb +0 -4
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/liquid_resolved_mailer.rb +0 -9
- data/spec/dummy/app/mailers/user_liquid_mailer.rb +0 -10
- data/spec/dummy/app/models/user.rb +0 -15
- data/spec/dummy/app/views/layouts/application.html.erb +0 -17
- data/spec/dummy/app/views/user_liquid/after_create_user.liquid +0 -7
- data/spec/dummy/app/views/welcome/index.html.haml +0 -1
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -78
- data/spec/dummy/config/environments/test.rb +0 -40
- data/spec/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/devise.rb +0 -259
- data/spec/dummy/config/initializers/effective_email_templates.rb +0 -51
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/devise.en.yml +0 -60
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -57
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/migrate/20141126222940_devise_create_users.rb +0 -42
- data/spec/dummy/db/migrate/20141126222941_create_effective_email_templates.rb +0 -20
- data/spec/dummy/db/schema.rb +0 -46
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/effective_email_templates_spec.rb +0 -35
- data/spec/factories/email_template.rb +0 -12
- data/spec/factories/user.rb +0 -16
- data/spec/factory_spec.rb +0 -10
- data/spec/lib/effective_email_templates/template_importer_spec.rb +0 -73
- data/spec/mailers/liquid_resolved_mailer_spec.rb +0 -38
- data/spec/models/email_template_spec.rb +0 -61
- data/spec/models/user_spec.rb +0 -10
- data/spec/sanity_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -26
@@ -1 +0,0 @@
|
|
1
|
-
//= require_tree ./effective_email_templates
|
@@ -1 +0,0 @@
|
|
1
|
-
//
|
@@ -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,24 +0,0 @@
|
|
1
|
-
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
2
|
-
module Effective
|
3
|
-
module Datatables
|
4
|
-
class EmailTemplates < Effective::Datatable
|
5
|
-
datatable do
|
6
|
-
default_order :subject, :asc
|
7
|
-
|
8
|
-
table_column :id, visible: false
|
9
|
-
table_column :slug
|
10
|
-
table_column :subject
|
11
|
-
table_column :from
|
12
|
-
table_column :cc, sortable: false, visible: false, label: 'CC'
|
13
|
-
table_column :bcc, sortable: false, visible: false, label: 'BCC'
|
14
|
-
table_column :body, sortable: false, visible: false
|
15
|
-
table_column :actions, sortable: false, partial: '/admin/email_templates/actions'
|
16
|
-
end
|
17
|
-
|
18
|
-
def collection
|
19
|
-
Effective::EmailTemplate.all
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
= @body
|
@@ -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,39 +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 formats
|
27
|
-
[:html]
|
28
|
-
end
|
29
|
-
|
30
|
-
def identifier
|
31
|
-
effective_email_template.slug
|
32
|
-
end
|
33
|
-
|
34
|
-
def type
|
35
|
-
formats.first
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
@@ -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
|
-
|
data/spec/dummy/README.rdoc
DELETED
@@ -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,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,15 +0,0 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
# Include default devise modules. Others available are:
|
3
|
-
# :confirmable, :lockable, :timeoutable and :omniauthable
|
4
|
-
devise :database_authenticatable, :registerable,
|
5
|
-
:recoverable, :rememberable, :trackable, :validatable
|
6
|
-
|
7
|
-
after_create :after_create
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def after_create
|
12
|
-
mail = UserLiquidMailer.after_create_user
|
13
|
-
mail.deliver
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Dummy</title>
|
5
|
-
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
-
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<p class="notice"><%= notice %></p>
|
12
|
-
<p class="alert"><%= alert %></p>
|
13
|
-
|
14
|
-
<%= yield %>
|
15
|
-
|
16
|
-
</body>
|
17
|
-
</html>
|