active_admin_mail 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c190a664c47a7c4795e365642d6a995b8d67ec85
4
+ data.tar.gz: d12ea2c424ce7b7367c9417297ec379996818dee
5
+ SHA512:
6
+ metadata.gz: 6093a2d18316de77a443318257e562df084cdffa5139e4e3f482c10e1885958fd91afcb87373ac5ef630e104b8458fe3d7fd2594c0be5c6524e5577f2982f1ae
7
+ data.tar.gz: 36d3c1b94369b679faef009ea4e5a6c77790ca9a5b183a99b0dc98a83cb9ad6c1eb9f0d0aea07a892710e98273b8ecb432e17dda32f1dd128015e60606b08f95
Binary file
@@ -0,0 +1,51 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.rbc
11
+ capybara-*.html
12
+ .rspec
13
+ /log
14
+ /tmp
15
+ /db/*.sqlite3
16
+ /db/*.sqlite3-journal
17
+ /public/system
18
+ /coverage/
19
+ /spec/tmp
20
+ **.orig
21
+ rerun.txt
22
+ pickle-email-*.html
23
+
24
+ # TODO Comment out these rules if you are OK with secrets being uploaded to the repo
25
+ config/initializers/secret_token.rb
26
+ config/secrets.yml
27
+
28
+ # dotenv
29
+ # TODO Comment out this rule if environment variables can be committed
30
+ .env
31
+
32
+ ## Environment normalization:
33
+ /.bundle
34
+ /vendor/bundle
35
+
36
+ # these should all be checked in to normalize the environment:
37
+ # Gemfile.lock, .ruby-version, .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
41
+
42
+ # if using bower-rails ignore default bower_components path bower.json files
43
+ /vendor/assets/bower_components
44
+ *.bowerrc
45
+ bower.json
46
+
47
+ # Ignore pow environment settings
48
+ .powenv
49
+
50
+ # Ignore Byebug command history file.
51
+ .byebug_history
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'liquid', '~> 3.0.0'
@@ -0,0 +1,36 @@
1
+ # active_admin_mail
2
+ Manage the emails you send and your ActionMailer mailers with ActiveAdmin
3
+
4
+ # Installation
5
+
6
+ # Usage
7
+
8
+ ```
9
+ class UserMailer < ActionMailer::Base
10
+
11
+ def new_partnership(user)
12
+ @user = user
13
+ active_admin_mail(to: @user.email)
14
+ end
15
+
16
+ end
17
+ ```
18
+
19
+ active_admin_mail internally...
20
+
21
+ * Looks up the mail template in the database via `find_by(:klass => 'UserMailer', :action => 'new_partnership')`
22
+ * Parses that mail template into liquid to render
23
+ * Parses the instance variables in the action that don't start with @_ to a mapped liquid hash like `{ 'user' => { 'id' => 1 }`
24
+ * Sends the email using ActionMailer#mail
25
+ * Logs the email
26
+
27
+ # Todo
28
+
29
+ * Mail layouts
30
+ * Filters for active_admin
31
+ * txt and html
32
+ * Wysiwyg?
33
+ * Preview?
34
+ * Fallback?
35
+ * CC, BCC per mailer?
36
+ * callbacks?
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin_mail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_admin_mail"
8
+ spec.version = ActiveAdminMail::VERSION
9
+ spec.authors = ["Josh Brody"]
10
+ spec.email = ["josh@josh.mn"]
11
+
12
+ spec.summary = %q{Manage your ActionMailer mail templates from ActiveAdmin, and log them.}
13
+ spec.description = %q{Manage your ActionMailer mail templates from ActiveAdmin, and log them.}
14
+ spec.homepage = "https://github.com/joshmn/active_admin_mail"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency 'liquid', '~> 3.0.0'
30
+ spec.add_runtime_dependency 'activeadmin', '~> 1.0.0'
31
+ spec.add_development_dependency "bundler", "~> 1.11"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+
34
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_admin_mail"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,52 @@
1
+ require 'active_admin_mail/mail_builder'
2
+ require 'active_admin_mail/mail_template'
3
+ require 'active_admin_mail/mail_log'
4
+
5
+ begin
6
+ require 'rails/engine'
7
+ require 'active_admin_mail/engine'
8
+ rescue LoadError
9
+
10
+ end
11
+
12
+ module ActiveAdminMail
13
+
14
+ class << self
15
+ attr_accessor :configuration
16
+ end
17
+
18
+ def self.configure
19
+ self.configuration ||= Configuration.new
20
+ yield(configuration)
21
+ end
22
+
23
+ class Configuration
24
+ attr_accessor :mail_classes
25
+
26
+ def initialize
27
+ @mail_classes = []
28
+ end
29
+ end
30
+
31
+ protected
32
+ def self.find_user_by(attr = :email, value = nil)
33
+ User.find_by(attr => value)
34
+ end
35
+
36
+ def self.create_mail_log(from, mail_result)
37
+ ActiveAdminMail::MailLog.create(
38
+ :user => from.instance_variable_get(:@user).nil? ? ActiveAdminMail.find_user_by(:email, mail_result.to.first) : from.instance_variable_get(:@user),
39
+ :active_admin_mail_template_id => from.instance_variable_get(:@_mail_template).id,
40
+ :action => from.action_name,
41
+ :klass => from.class.to_s,
42
+ :headers => self.parsed_headers(mail_result).to_json
43
+ )
44
+ end
45
+
46
+ def self.parsed_headers(mail_result)
47
+ headers = {}
48
+ mail_result.header_fields.map { |k| headers[k.name] = k.value }
49
+ headers
50
+ end
51
+
52
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveAdminMail
2
+ class Engine < Rails::Engine
3
+ isolate_namespace ActiveAdminMail
4
+
5
+ initializer :append_migrations do |app|
6
+ unless app.root.to_s.match root.to_s
7
+ config.paths["db/migrate"].expanded.each do |expanded_path|
8
+ app.config.paths["db/migrate"] << expanded_path
9
+ end
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module ActiveAdminMail
2
+ class MailBuilder
3
+
4
+ def initialize(source, template)
5
+ @source = source
6
+ @template = template
7
+ end
8
+
9
+ def render
10
+ @render ||= parsed_mailer.render(liquid_variables_map)
11
+ end
12
+
13
+ protected
14
+
15
+ # creates a hash for liquid templating within your mailer
16
+ # removes the @instance_variable @ to build it into a standard hash for liquid
17
+ # like { 'user' => { 'id' => 1 }
18
+ def liquid_variables_map
19
+ liquid_variables = {}
20
+ permitted_instance_variables.each do |v|
21
+ liquid_variables[v.to_s[1 .. -1]] = @source.instance_variable_get(v)
22
+ end
23
+ liquid_variables.as_json
24
+ end
25
+
26
+ def parsed_mailer
27
+ @parsed_mailer ||= Liquid::Template.parse(@template.content)
28
+ end
29
+
30
+ def permitted_instance_variables
31
+ @source.instance_variables.select { |v| !v.to_s.start_with?("@_") }
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ module ActiveAdminMail
2
+ class MailLog < ActiveRecord::Base
3
+ self.table_name = 'active_admin_mail_logs'
4
+ belongs_to :user
5
+ end
6
+ end
@@ -0,0 +1,41 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: mail_templates
4
+ #
5
+ # id :integer not null, primary key
6
+ # subject :string
7
+ # content :string
8
+ # klass :string
9
+ # action :string
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
12
+ #
13
+
14
+ module ActiveAdminMail
15
+ class MailTemplate < ActiveRecord::Base
16
+
17
+ self.table_name = 'active_admin_mail_templates'
18
+
19
+ validates_presence_of :klass, :in => -> { rails_mailers }
20
+ validates_uniqueness_of :action, :scope => :klass
21
+
22
+ def additional_headers
23
+ headers = {}
24
+ headers[:subject] = self.subject if self.subject.present?
25
+ headers
26
+ end
27
+
28
+ def self.rails_mailers
29
+ ActiveAdminMail.configuration.mail_classes
30
+ end
31
+
32
+ def self.mail_actions
33
+ rails_mailers.collect { |mailer| [mailer, mailer.constantize.public_instance_methods(false)] }
34
+ end
35
+
36
+ Kaminari.configure do |config|
37
+ config.page_method_name = :per_page_kaminari
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAdminMail
2
+ VERSION = '0.1'
3
+ end
Binary file
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Copies default ActiveAdmin pages for MailTemplate and MailLog to app/your_active_admin_namespace/active_admin_mail
3
+
4
+ Example:
5
+ rails generate active_admin_mail:install [admin_path]
6
+
7
+ admin_path defaults to admin
8
+
9
+ This will create:
10
+ app/admin/active_admin_mail/mail_log.rb
11
+ app/admin/active_admin_mail/mail_template.rb
12
+
13
+ and add a migration of:
14
+ 1_active_admin_mail_migration.rb
@@ -0,0 +1,16 @@
1
+ module ActiveAdminMail
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ desc "Copies default ActiveAdmin pages for MailTemplate and MailLog to app/admin/active_admin_mail."
6
+
7
+ argument :admin_namespace, required: false, default: "admin"
8
+
9
+ def copy_initializer_file
10
+ copy_file "mail_log.rb", "app/#{admin_namespace}/active_admin_mail/mail_log.rb"
11
+ copy_file "mail_template.rb", "app/#{admin_namespace}/active_admin_mail/mail_template.rb"
12
+ copy_file "db/migrate/1_active_admin_mail_migration.rb", "db/migrate/1_active_admin_mail_migration.rb"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ class ActiveAdminMailMigration < ActiveRecord::Migration
2
+ def change
3
+ create_table :active_admin_mail_templates do |t|
4
+ t.string :klass
5
+ t.string :action
6
+ t.text :content
7
+ t.text :subject
8
+
9
+ t.timestamps null: false
10
+ end
11
+ add_index :active_admin_mail_templates, :klass
12
+ add_index :active_admin_mail_templates, :action
13
+
14
+ create_table :active_admin_mail_logs do |t|
15
+ t.integer :active_admin_mail_template_id
16
+ t.string :template
17
+ t.string :action
18
+ t.string :klass
19
+ t.integer :user_id
20
+ t.json :headers
21
+
22
+ t.timestamps null: false
23
+ end
24
+ add_index :active_admin_mail_logs, :active_admin_mail_template_id
25
+ add_index :active_admin_mail_logs, :template
26
+ add_index :active_admin_mail_logs, :action
27
+ add_index :active_admin_mail_logs, :klass
28
+ add_index :active_admin_mail_logs, :user_id
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register ActiveAdminMail::MailLog do
2
+ menu :label => "Log", :parent => "Mail"
3
+ end
@@ -0,0 +1,15 @@
1
+ ActiveAdmin.register ActiveAdminMail::MailTemplate do
2
+ menu :label => "Templates", :parent => "Mail"
3
+
4
+ permit_params :klass, :action, :subject, :content
5
+
6
+ form do |f|
7
+ f.inputs do
8
+ f.input :klass
9
+ f.input :action, :collection => ActiveAdminMail::MailTemplate.mail_actions, :input_html => { :onchange => '$("#active_admin_mail_mail_template_klass").val($("#active_admin_mail_mail_template_action option:selected").closest("optgroup").attr("label"));' }
10
+ f.input :subject
11
+ f.input :content, :as => :text
12
+ end
13
+ actions
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_mail
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Josh Brody
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activeadmin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Manage your ActionMailer mail templates from ActiveAdmin, and log them.
70
+ email:
71
+ - josh@josh.mn
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".DS_Store"
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - active_admin_mail.gemspec
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/.DS_Store
85
+ - lib/active_admin_mail.rb
86
+ - lib/active_admin_mail/engine.rb
87
+ - lib/active_admin_mail/mail_builder.rb
88
+ - lib/active_admin_mail/mail_log.rb
89
+ - lib/active_admin_mail/mail_template.rb
90
+ - lib/active_admin_mail/version.rb
91
+ - lib/generators/.DS_Store
92
+ - lib/generators/active_admin_mail/.DS_Store
93
+ - lib/generators/active_admin_mail/USAGE
94
+ - lib/generators/active_admin_mail/install_generator.rb
95
+ - lib/generators/active_admin_mail/templates/.DS_Store
96
+ - lib/generators/active_admin_mail/templates/db/.DS_Store
97
+ - lib/generators/active_admin_mail/templates/db/migrate/1_active_admin_mail_migration.rb
98
+ - lib/generators/active_admin_mail/templates/mail_log.rb
99
+ - lib/generators/active_admin_mail/templates/mail_template.rb
100
+ homepage: https://github.com/joshmn/active_admin_mail
101
+ licenses: []
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.3
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Manage your ActionMailer mail templates from ActiveAdmin, and log them.
124
+ test_files: []