rails_email_preview 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37429c25c79cc3521d73fd094b946a741c9637b2
4
- data.tar.gz: 794cf5bcd0462c1017692c7ff6a05480dd840ad3
3
+ metadata.gz: d66ba0f93f6cd3a1832c10f9b0ee96d264cbcc1c
4
+ data.tar.gz: 5e2869ecf1bf1882d35c0717b30d2eeac3611ec1
5
5
  SHA512:
6
- metadata.gz: 8b53a55a392237946c38ca1a4c10e859fa7dd8127be1d2dd944717cbf0c6db32e59eeea55ccf91d6a7ba7628a0e5f9d23321b0e7aa771b1aa7e07dec254515c9
7
- data.tar.gz: b7deed111d4fd2c3c04e8823cf3cae7efbebbf5cf54c27f4dc13c7fe712e9e2f9a55fb665f57975d44ece9feb1d8ddf713ced42e3fef12126692d799933ad692
6
+ metadata.gz: ea278d1bc029a4691f8e1ade7943b62f7685c4f44fda6599c310776d9fa1d5f153abcd8c92a180ac8a6503eb6f329c394c5591af4329d6a2619d05ca57eb3708
7
+ data.tar.gz: 60d526c9f9686bd64ce7cac42d71b908d991fca59a7efca29555779c3881cb70f7c7ce640904f2559df643d755d6f80871de09046c880643ad1f1c8a6c232a96
data/README.md CHANGED
@@ -17,7 +17,7 @@ How to
17
17
 
18
18
  Add to Gemfile
19
19
 
20
- gem 'rails_email_preview', '~> 0.2'
20
+ gem 'rails_email_preview', '~> 0.2.10'
21
21
 
22
22
  REP handles setup for you:
23
23
 
@@ -119,10 +119,10 @@ Views
119
119
 
120
120
  You can render all REP views inside your app layout (this will need styling to look nice if you don't use bootstrap):
121
121
 
122
- # # Use admin layout with REP:
123
- # RailsEmailPreview::EmailsController.layout 'admin'
124
- # # If you are using a custom layout, you will want to make app routes available to REP:
125
- # Rails.application.config.to_prepare { RailsEmailPreview.inline_main_app_routes! }
122
+ Rails.application.config.to_prepare do
123
+ # Use admin layout with REP (this will also make app routes accessible within REP):
124
+ RailsEmailPreview.layout = 'admin'
125
+ end
126
126
 
127
127
  REP allows you to customize some of the element classes via `RailsEmailPreview.style`:
128
128
 
@@ -150,7 +150,7 @@ Authentication & authorization
150
150
  ------------------------------
151
151
 
152
152
  You can specify the parent controller for REP controller, and it will inherit all before filters.
153
- Note that this must be placed before any other references to REP application controller in the initializer:
153
+ Note that this must be placed before any other references to REP application controller in the initializer (and before `layout=` call):
154
154
 
155
155
  RailsEmailPreview.parent_controller = 'Admin::ApplicationController' # default: '::ApplicationController'
156
156
 
@@ -1,33 +1,34 @@
1
1
  -# When rendering inside rails_email_preview hide nav, and hide irrelevant things from the form
2
2
  ruby:
3
3
  snippet = @snippet || @record.is_a?(Cms::Snippet) && @record
4
- if snippet
5
- p = ::RailsEmailPreview::Integrations::ComfortableMexicanSofa.rep_email_params_from_snippet(snippet)
4
+ if snippet && (p = ::RailsEmailPreview::Integrations::ComfortableMexicanSofa.rep_email_params_from_snippet(snippet))
6
5
  show_url = rails_email_preview.rep_raw_email_url(p.merge part_type: 'text/html')
7
6
  end
8
- javascript:
9
- jQuery(function($) {
10
- if (window.parent && /email/.test(parent.location.href)) {
11
- // Hide nav:
12
- $('.left-column,.right-column').hide();
13
- $('.center-column').css('margin', 0);
14
- $('.page-header h2').html(
15
- "Editing email" +
16
- " <a class='btn btn-primary' href='#{show_url}'>#{t 'rep.view_link'}</a>"
17
- )
18
7
 
19
- // Snippet form:
20
- var control = function(name) { return $('[name^="snippet[' + name + ']"]').closest('.control-group'); };
8
+ - if show_url.present?
9
+ javascript:
10
+ jQuery(function($) {
11
+ if (window.parent && (new RegExp('#{rails_email_preview.rep_root_path}')).test(parent.location.href)) {
12
+ // Hide nav:
13
+ $('.left-column,.right-column').hide();
14
+ $('.center-column').css('margin', 0);
15
+ $('.page-header h2').html(
16
+ "Editing email" +
17
+ " <a class='btn btn-primary' href='#{show_url}'>#{t 'rep.view_link'}</a>"
18
+ )
21
19
 
22
- // retext labels
23
- control('label').find('.control-label').text("Subject");
24
- control('content').find('.control-label').text("Body");
20
+ // Snippet form:
21
+ var control = function(name) { return $('[name^="snippet[' + name + ']"]').closest('.control-group'); };
25
22
 
26
- // hide identifier and categories
27
- control('identifier').hide();
28
- control('category_ids').hide()
23
+ // retext labels
24
+ control('label').find('.control-label').text("Subject");
25
+ control('content').find('.control-label').text("Body");
29
26
 
30
- // Do not mess with identifier
31
- $('[data-slug]').removeAttr('data-slug');
32
- }
33
- });
27
+ // hide identifier and categories
28
+ control('identifier').hide();
29
+ control('category_ids').hide()
30
+
31
+ // Do not mess with identifier
32
+ $('[data-slug]').removeAttr('data-slug');
33
+ }
34
+ });
@@ -13,6 +13,9 @@ require 'rails_email_preview'
13
13
  #
14
14
  # # do not show Send Email button
15
15
  # config.enable_send_email = false
16
+ #
17
+ # # You can specify a controller for RailsEmailPreview::ApplicationController to inherit from:
18
+ # config.parent_controller = 'Admin::ApplicationController' # default: '::ApplicationController'
16
19
  #end
17
20
 
18
21
  #= REP + Comfortable Mexican Sofa integration
@@ -20,17 +23,10 @@ require 'rails_email_preview'
20
23
  # # enable comfortable_mexican_sofa integration:
21
24
  # require 'rails_email_preview/integrations/comfortable_mexica_sofa'
22
25
 
23
- #= Application-specific (layout, permissions, customizations)
24
- #
25
- # # You can specify a controller for RailsEmailPreview::ApplicationController to inherit from:
26
- # RailsEmailPreview.parent_controller = 'Admin::ApplicationController' # default: '::ApplicationController'
27
- #
28
- # # Render REP inside a custom layout (set to 'application' to use app layout, default is REP's own layout)
29
- # RailsEmailPreview::EmailsController.layout 'admin'
30
-
31
26
  Rails.application.config.to_prepare do
32
- # # If you use a *custom layout*, make route helpers available to REP:
33
- # RailsEmailPreview.inline_main_app_routes!
27
+ # Render REP inside a custom layout (set to 'application' to use app layout, default is REP's own layout)
28
+ # This will also make application routes accessible from within REP:
29
+ # RailsEmailPreview.layout = 'admin'
34
30
 
35
31
  # Auto-load preview classes from:
36
32
  RailsEmailPreview.preview_classes = Dir[Rails.root.join 'app/mailer_previews/*_preview.rb'].map { |p|
@@ -37,6 +37,14 @@ module RailsEmailPreview
37
37
  }
38
38
 
39
39
  class << self
40
+ def layout=(layout)
41
+ [::RailsEmailPreview::ApplicationController, ::RailsEmailPreview::EmailsController].each { |ctrl| ctrl.layout layout }
42
+ if layout && layout !~ %r(^rails_email_preview/)
43
+ # inline application routes if using an app layout
44
+ inline_main_app_routes!
45
+ end
46
+ end
47
+
40
48
  def run_before_render(mail, preview_class_name, mailer_action)
41
49
  (defined?(@hooks) && @hooks[:before_render] || []).each do |block|
42
50
  block.call(mail, preview_class_name, mailer_action)
@@ -48,7 +56,10 @@ module RailsEmailPreview
48
56
  end
49
57
 
50
58
  def inline_main_app_routes!
51
- ::RailsEmailPreview::ApplicationController.helper ::RailsEmailPreview::MainAppRouteDelegator
59
+ unless ::RailsEmailPreview::EmailsController.instance_variable_get(:@inlined_routes)
60
+ ::RailsEmailPreview::EmailsController.helper ::RailsEmailPreview::MainAppRouteDelegator
61
+ ::RailsEmailPreview::EmailsController.instance_variable_set(:@inlined_routes, true)
62
+ end
52
63
  end
53
64
 
54
65
  def setup
@@ -17,6 +17,7 @@ module RailsEmailPreview
17
17
  # cms_email_subject(name: "Alice") #=> "Welcome, Alice!"
18
18
  def cms_email_subject(interpolation = {})
19
19
  snippet_id = "email-#{cms_email_id}"
20
+ return '(no subject)' unless Cms::Snippet.where(identifier: snippet_id).exists?
20
21
  [I18n.locale, I18n.default_locale].compact.each do |locale|
21
22
  site = Cms::Site.find_by_locale(locale)
22
23
  snippet = site.snippets.find_by_identifier(snippet_id)
@@ -44,14 +45,17 @@ module RailsEmailPreview
44
45
  # Will also render an "✎ Edit text" link if used from
45
46
  def cms_email_snippet(snippet_id = self.cms_email_id)
46
47
  snippet_id = "email-#{snippet_id}"
47
- site = Cms::Site.find_by_locale(I18n.locale)
48
-
49
- # Fallback default locale: (# prefill)
50
- unless (content = cms_snippet_content(snippet_id, site).presence)
51
- default_site = Cms::Site.find_by_locale(I18n.default_locale)
52
- fallback_content = cms_snippet_content(snippet_id, default_site).presence
48
+ if Cms::Snippet.where(identifier: snippet_id).exists?
49
+ site = Cms::Site.find_by_locale(I18n.locale)
50
+ # Fallback default locale: (# prefill)
51
+ unless (content = cms_snippet_content(snippet_id, site).presence)
52
+ default_site = Cms::Site.find_by_locale(I18n.default_locale)
53
+ fallback_content = cms_snippet_content(snippet_id, default_site).presence
54
+ end
55
+ result = (content || fallback_content).to_s
56
+ else
57
+ result = ''
53
58
  end
54
- result = (content || fallback_content).to_s
55
59
 
56
60
  # If rendering in preview from admin, add edit/create lnk
57
61
  if cms_email_edit_link?
@@ -73,10 +77,8 @@ module RailsEmailPreview
73
77
  })
74
78
  end
75
79
 
76
- result = safe_join ["<table class='rep-edit-link'><tr><td>".html_safe,
77
- cms_edit_email_snippet_link(cms_path),
78
- "</td></tr></table>".html_safe,
79
- "\n\n", result]
80
+ result = safe_join ["<table class='rep-edit-link'><tr><td>".html_safe, cms_edit_email_snippet_link(cms_path),
81
+ "</td></tr></table>".html_safe, "\n\n", result]
80
82
  end
81
83
  result
82
84
  end
@@ -87,7 +89,7 @@ module RailsEmailPreview
87
89
 
88
90
  def self.rep_email_params_from_snippet(snippet)
89
91
  id_prefix = 'email-'
90
- return unless snippet && snippet.identifier.starts_with?(id_prefix)
92
+ return unless snippet && snippet.identifier && snippet.identifier.starts_with?(id_prefix)
91
93
  mailer_cl, act = snippet.identifier[id_prefix.length..-1].split('-')
92
94
  mailer_cl += '_preview'
93
95
  { mail_class: mailer_cl,
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '0.2.9'
2
+ VERSION = '0.2.10'
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.2.9
4
+ version: 0.2.10
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-08-22 00:00:00.000000000 Z
11
+ date: 2013-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -136,8 +136,8 @@ dependencies:
136
136
  - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: A Rails Engine to preview plain text and html email in your browser.
140
- Test send, i18n support, premailer integration, etc...
139
+ description: Rails engine to preview, test send, and edit application email in browser.
140
+ i18n support, premailer integration, and more.
141
141
  email: glex.spb@gmail.com
142
142
  executables: []
143
143
  extensions: []