rails_email_preview 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa7d4eb9873fb41236d985af8f4d4944a6aa7056
4
- data.tar.gz: a2b36c22f1f76369e2f400fecda49383fa1f0dfa
3
+ metadata.gz: 52a17e3d36b0d7cf89ee5d5cd203f46c24710a36
4
+ data.tar.gz: 3e80c0aa0452d9048e2325e2fb16fd18aa0ac32a
5
5
  SHA512:
6
- metadata.gz: 67f0eb7c5cb4ad07bd3f991aa0cc8c000a67d56982c140cc46a70a5674e75aa125096d6ac1ee376a8d00d1923bfd20ca0aad4e1724b71a1efff8ccaf8fce2b3f
7
- data.tar.gz: af01ce4227f49d190fb846a1152e5ecf611b69397b0fa1d40eedfb5c7727bbced5d741cec44e951ab872c5ed211a4a198bf9e6a994cfa3f9b4d0d06b49cb4ba7
6
+ metadata.gz: 0f33ae9252698108f4e03fb383239d777e96fad40abbf390f1fdfda54fbed1d54f95c2935c002386444d0d8270655a18326f5ed14b385d2b1a3a6925b579abc4
7
+ data.tar.gz: 59faa202e37281f126da6813783b6297267b4d3b5ae9f09bcaa7ba875f6000a467aa3654b8d632a57fbd093c1d54c75613bc723621e2bc30918bdc953475f8c5
data/README.md CHANGED
@@ -10,21 +10,22 @@ A Rails Engine to preview plain text and html email in your browser. Compatible
10
10
  How to
11
11
  -----
12
12
 
13
- You will need to provide data for preview of each email:
13
+ Add to Gemfile
14
14
 
15
- # Say you have this mailer
16
- class UserMailer < ActionMailer::Base
17
- def invitation(inviter, invitee)
18
- # ...
19
- end
15
+ gem 'rails_email_preview'
20
16
 
21
- def welcome(user)
22
- # ...
23
- end
24
- end
17
+ Run generators
18
+
19
+ # Add initializer and route
20
+ rails g rails_email_preview:install
21
+
22
+ # Generate preview classes and method stubs in app/mailer_previews/
23
+ rails g rails_email_preview:update_previews
24
+
25
+ You will need to provide data for preview of each email:
25
26
 
26
- # Define a Preview class with the same mail action names, but with no arguments
27
- # mkdir -p app/mailer_previews/; touch app/mailer_previews/user_mailer_preview.rb
27
+ # Say there is a UserMailer with 2 actions
28
+ # in app/mailer_previews/user_mailer_preview.rb initialize the emails for preview:
28
29
  class UserMailerPreview
29
30
  # preview methods should return Mail objects, e.g.:
30
31
  def invitation
@@ -36,24 +37,24 @@ You will need to provide data for preview of each email:
36
37
  end
37
38
 
38
39
  private
40
+ # You can put all your mock helpers in a module
41
+ # Or, if you have factories/fabricators for your tests you could use those, but be careful not to create anything!
39
42
  def mock_user(name = 'Bill Gates')
40
- User.new(name: name, email: "user@test.com#{rand 100}").tap { |u| u.define_singleton_method(:id) { 123 + rand(100) } }
43
+ fake_id User.new(name: name, email: "user#{rand 100}@test.com")
44
+ end
45
+
46
+ def fake_id(obj)
47
+ obj.define_singleton_method(:id) { 123 + rand(100) }
48
+ obj
41
49
  end
42
- end
43
-
44
- # Let REP know about UserMailerPreview:
45
- # touch config/initializers/rails_email_preview.rb
46
- RailsEmailPreview.setup do |config|
47
- config.preview_classes = %w( UserMailerPreview )
48
50
  end
49
51
 
50
52
 
51
53
  Routing
52
54
  -------
53
-
54
- mount RailsEmailPreview::Engine, at: 'emails'
55
-
56
- # You can access REP urls like this:
55
+
56
+ You can access REP urls like this:
57
+
57
58
  rails_email_preview.root_url #=> '/emails'
58
59
 
59
60
  Email editing
@@ -12,7 +12,17 @@ class RailsEmailPreview::EmailsController < RailsEmailPreview::ApplicationContro
12
12
  def show
13
13
  I18n.with_locale @email_locale do
14
14
  @part_type = params[:part_type] || 'text/html'
15
- @mail = @preview_class.new.send(params[:mail_action])
15
+ if @preview_class.respond_to?(:new)
16
+ @mail = @preview_class.new.send(params[:mail_action])
17
+ else
18
+ # @preview_class is not a preview class
19
+ arg_info = "#{@preview_class}"
20
+ if @preview_class.is_a?(Module)
21
+ chain = @preview_class.ancestors.map(&:to_s)
22
+ chain = chain[1 .. chain.index { |c| c =~ /^Application[A-Z][A-z]+$/ } || -1]
23
+ end
24
+ raise ArgumentError.new("#{arg_info} is not a preview class #{"(ancestors: #{chain * ' < '})"} ")
25
+ end
16
26
  end
17
27
  render
18
28
  end
@@ -42,7 +52,7 @@ class RailsEmailPreview::EmailsController < RailsEmailPreview::ApplicationContro
42
52
  protected
43
53
 
44
54
  def set_email_preview_locale
45
- @email_locale = (params[:email_locale] || I18n.locale).to_s
55
+ @email_locale = (params[:email_locale] || I18n.default_locale).to_s
46
56
  end
47
57
 
48
58
  private
@@ -7,14 +7,15 @@ javascript:
7
7
  $('.center-column').css('margin', 0);
8
8
 
9
9
  // Snippet form:
10
- var control = function(name) { return $('[name="snippet[' + name + ']"]').closest('.control-group'); };
10
+ var control = function(name) { return $('[name^="snippet[' + name + ']"]').closest('.control-group'); };
11
11
 
12
+ // retext labels
12
13
  control('label').find('.control-label').text("Subject");
13
14
  control('content').find('.control-label').text("Body");
14
15
 
15
- // Hide identifier and categories
16
+ // hide identifier and categories
16
17
  control('identifier').hide();
17
- $('label[for="snippet_"]').closest('.control-group').hide();
18
+ control('category_ids').hide()
18
19
 
19
20
  // Do not mess with identifier
20
21
  $('[data-slug]').removeAttr('data-slug');
@@ -1,14 +1,14 @@
1
1
  ruby:
2
2
  headers = {
3
- 'From' => @mail.from,
4
- 'To' => @mail.to,
5
- 'CC' => @mail.cc,
6
- 'BCC' => @mail.bcc,
7
- 'Subject' => @mail.subject || '(no subject)'
3
+ 'From' => @mail.from,
4
+ 'To' => @mail.to,
5
+ 'Reply to' => @mail.reply_to,
6
+ 'CC' => @mail.cc,
7
+ 'BCC' => @mail.bcc,
8
+ 'Subject' => @mail.subject || '(no subject)'
8
9
  }.delete_if { |k, v| v.blank? }
9
10
 
10
11
 
11
-
12
12
  dl
13
13
  - headers.each do |header, value|
14
14
  dt #{header}
@@ -0,0 +1,29 @@
1
+ require 'rails_email_preview'
2
+
3
+ # Add this to process preview with premailer-rails
4
+ # RailsEmailPreview.before_render { |message| Premailer::Rails::Hook.delivering_email(message) }
5
+
6
+ # with actionmailer-inline-css
7
+ # RailsEmailPreview.before_render { |message| ActionMailer::InlineCssHook.delivering_email(message) }
8
+
9
+ Rails.application.config.to_prepare do
10
+ # Choose where to load preview_classes from:
11
+ RailsEmailPreview.preview_classes = Dir['app/mailer_previews/*_preview.rb'].map { |p|
12
+ File.basename(p, '.rb').camelize
13
+ }
14
+
15
+ # Use a custom layout
16
+ # RailsEmailPreview::ApplicationController.layout 'admin'
17
+
18
+ # Add authorization
19
+ # RailsEmailPreview::ApplicationController.module_eval do
20
+ # before_filter :check_permissions
21
+ # private
22
+ # def check_permissions
23
+ # render status: 403 unless current_user.try(:admin?)
24
+ # end
25
+ # end
26
+ end
27
+
28
+ # Uncomment this to enable comfortable_mexican_sofa integration
29
+ # require 'rails_email_preview/integrations/comfortable_mexica_sofa'
@@ -0,0 +1,18 @@
1
+ module RailsEmailPreview
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "creates an initializer file at config/initializers/rails_email_preview.rb and adds REP route to config/routes.rb"
5
+ source_root File.expand_path('../../../..', __FILE__)
6
+
7
+ def generate_initialization
8
+ copy_file 'config/initializers/rails_email_preview.rb', 'config/initializers/rails_email_preview.rb'
9
+ end
10
+
11
+ def generate_routing
12
+ route "mount RailsEmailPreview::Engine, at: 'emails'"
13
+ log "# You can access REP urls like this:
14
+ rails_email_preview.root_url #=> '/emails'"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ module RailsEmailPreview
2
+ module Generators
3
+ class UpdatePreviewsGenerator < Rails::Generators::Base
4
+ desc "creates app/mailer_previews/NEW_MAILER_preview.rb for each new mailer"
5
+ def generate_mailer_previews
6
+ previews_dir = 'app/mailer_previews/'
7
+ empty_directory previews_dir
8
+ Dir['app/mailers/*.rb'].each do |p|
9
+ basename = File.basename(p, '.rb')
10
+ if basename == 'application_mailer' || File.read(p) !~ /\bdef\s/
11
+ shell.say_status :skip, basename, :blue
12
+ next
13
+ end
14
+ preview_path = File.join(previews_dir, "#{basename}_preview.rb")
15
+ if File.exists?(preview_path)
16
+ shell.say_status :exist, preview_path, :blue
17
+ next
18
+ end
19
+ create_file preview_path, mailer_class_body(basename.camelize)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def mailer_class_body(mailer_class_name)
26
+ <<-RUBY
27
+ class #{mailer_class_name}Preview
28
+ #{mailer_methods(mailer_class_name) * "\n\n"}
29
+ end
30
+ RUBY
31
+ end
32
+
33
+ def mailer_methods(mailer_class_name)
34
+ mailer_class = mailer_class_name.constantize
35
+ mailer_class.instance_methods(false).map do |m|
36
+ <<-RUBY
37
+ def #{m}
38
+ #{mailer_class_name}.#{m.to_s} #{mailer_class.instance_method(m).parameters.map(&:second) * ', '}
39
+ end
40
+ RUBY
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,6 +1,7 @@
1
1
  module ::RailsEmailPreview
2
2
  class Engine < Rails::Engine
3
3
  isolate_namespace RailsEmailPreview
4
+ load_generators
4
5
 
5
6
  class << self
6
7
  attr_accessor :root
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_email_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Mazovetskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-12 00:00:00.000000000 Z
11
+ date: 2013-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: |-
70
84
  Implemented as a rails engine with a simple UI for previewing your app emails,
71
85
  I18n support, easy premailer integration and editing integration via comfortable_mexican_sofa CMS.
@@ -85,10 +99,13 @@ files:
85
99
  - app/views/rails_email_preview/emails/_options.html.slim
86
100
  - app/views/rails_email_preview/emails/index.html.slim
87
101
  - app/views/rails_email_preview/emails/show.html.slim
102
+ - lib/generators/rails_email_preview/install_generator.rb
103
+ - lib/generators/rails_email_preview/update_previews_generator.rb
88
104
  - lib/rails_email_preview/engine.rb
89
105
  - lib/rails_email_preview/integrations/comfortable_mexica_sofa.rb
90
106
  - lib/rails_email_preview/version.rb
91
107
  - lib/rails_email_preview.rb
108
+ - config/initializers/rails_email_preview.rb
92
109
  - config/routes.rb
93
110
  - MIT-LICENSE
94
111
  - Rakefile