rails_email_preview 0.1.7 → 0.2.0

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: 29c1a27975a3c37570a310cd5fd8fab3efa66c28
4
- data.tar.gz: 254f09df4a0fe63b6e16c6f77d30fcea0fb0cada
3
+ metadata.gz: b9ef1fc8ffd22f2ccd7e15c77984a3daa0ac5acd
4
+ data.tar.gz: d456a66d74d63d7dea3ad69a0e640b2cc2496e92
5
5
  SHA512:
6
- metadata.gz: 12ed93d3d7351dae246a430f2fd06ed69e9a6262b0d2dee452e8f2d24816ce3da2cc4f2e7057dd2feb3c08aa23712beff13107563c0325462b6d7bd79a3529c6
7
- data.tar.gz: 65ca94712efcebb5e8200a7784831f73f6782dd15b0f0b8e2737e22c4cfbfa6a4f2b707942e0da9152d7441b089614eac2f5415734828dae1e04d1c1fd964003
6
+ metadata.gz: 5e86ba0b33764680726530b9fe0061997d0b9fd3ddcf6b7502a811b160ebd0b03b7d6296f493db2a18a92199f81a552969c1d5598d5a00f830746d844dfc96f3
7
+ data.tar.gz: cbcb488141a9ff3249074e6a01e632ab00fa0d01cc399999ce735785b3267226af226d7c7b630034939fdf6c722cf0a46ce8c228bce3aa97f839746e384c48ca
data/Gemfile CHANGED
@@ -2,5 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "capybara", ">= 0.4.0"
6
- gem "sqlite3"
5
+ group :development, :test do
6
+ gem "capybara", ">= 0.4.0"
7
+ gem "sqlite3"
8
+ # a debugger that works with MRI 2.0.0
9
+ gem 'byebug', platforms: :ruby_20
10
+ end
data/README.md CHANGED
@@ -12,7 +12,7 @@ How to
12
12
 
13
13
  Add to Gemfile
14
14
 
15
- gem 'rails_email_preview', '~> 0.1.7'
15
+ gem 'rails_email_preview', '~> 0.2.0'
16
16
 
17
17
  REP handles setup for you:
18
18
 
@@ -55,32 +55,29 @@ Routing
55
55
 
56
56
  You can access REP urls like this:
57
57
 
58
- rails_email_preview.root_url #=> '/emails'
59
-
58
+ # engine root:
59
+ rails_email_preview.rep_root_url
60
+ # list of emails (same as root):
61
+ rails_email_preview.rep_emails_url
62
+ # email show:
63
+ rails_email_preview.rep_email_url(mail_class: "user_mailer", mail_action: "welcome")
64
+
60
65
  Email editing
61
66
  -------------
62
67
 
63
68
  You can use [comfortable_mexican_sofa](https://github.com/comfy/comfortable-mexican-sofa) for storing and editing emails.
64
- REP comes with a CMS integration, see [ComfortableMexicanSofa integration guide](https://github.com/glebm/rails_email_preview/wiki/Edit-Emails-with-Comfortable-Mexican-Sofa).
69
+ REP comes with an integration for it -- see [CMS Guide](https://github.com/glebm/rails_email_preview/wiki/Edit-Emails-with-Comfortable-Mexican-Sofa).
65
70
 
66
71
  ![CMS integration screenshot](http://screencloud.net//img/screenshots/b000595dbd13ae061373fd1473f113ba.png)
67
72
 
68
73
 
69
- Premailer integration
74
+ Premailer
70
75
  ---------------------
71
76
 
72
77
  [Premailer](https://github.com/alexdunae/premailer) automatically translates standard CSS rules into old-school inline styles. Integration can be done by using the <code>before_render</code> hook.
73
78
 
74
79
  To integrate Premailer with your Rails app you can use either [actionmailer_inline_css](https://github.com/ndbroadbent/actionmailer_inline_css) or [premailer-rails](https://github.com/fphilipe/premailer-rails).
75
-
76
- For [actionmailer_inline_css](https://github.com/ndbroadbent/actionmailer_inline_css), add to `RailsEmailPreview.setup`:
77
-
78
- config.before_render { |message| ActionMailer::InlineCssHook.delivering_email(message) }
79
-
80
- For [premailer-rails](https://github.com/fphilipe/premailer-rails), add to `RailsEmailPreview.setup`:
81
-
82
- config.before_render { |message| Premailer::Rails::Hook.delivering_email(message) }
83
-
80
+ Simply uncomment the relevant options in [the initializer](https://github.com/glebm/rails_email_preview/blob/master/config/initializers/rails_email_preview.rb). *initializer is generated during `rails g rails_email_preview:install`*
84
81
 
85
82
  I18n
86
83
  -------------
@@ -102,30 +99,31 @@ Views
102
99
 
103
100
  You can render all REP views inside your own layout:
104
101
 
105
- Rails.application.config.to_prepare do
106
- RailsEmailPreview::ApplicationController.layout 'admin'
107
- end
108
-
109
- When using a layout other than the default, that layout has to access all route helpers via `main_app`, e.g. `main_app.login_url`.
110
- This is due to how [isolated engines](http://edgeapi.rubyonrails.org/classes/Rails/Engine.html#label-Isolated+Engine) work in Rails.
111
-
112
- You can also override any individual view by placing a file with the same path in your project's `app/views`, e.g. `app/views/rails_email_preview/emails/index.html.slim`.
113
-
114
- *Pull requests adding view hooks are welcome!*
102
+ # # Use admin layout with REP:
103
+ # RailsEmailPreview::ApplicationController.layout 'admin'
104
+ # # If you are using a custom layout, you will want to make app routes available to REP:
105
+ # Rails.application.config.to_prepare { RailsEmailPreview.inline_main_app_routes! }
115
106
 
107
+ You can also override any individual view by placing a file with the same path in your project's `app/views`,
108
+ e.g. `app/views/rails_email_preview/emails/index.html.slim`. *PRs accepted* if you need hooks.
116
109
 
117
110
  Authentication & authorization
118
111
  ------------------------------
119
112
 
120
- To only allow certain users view emails add a before filter to `RailsEmailPreview::ApplicationController`, e.g.:
113
+ You can specify the parent controller for REP controller, and it will inherit all before filters.
114
+ Note that this must be placed before any other references to REP application controller in the initializer:
115
+
116
+ RailsEmailPreview.parent_controller = 'Admin::ApplicationController' # default: '::ApplicationController'
117
+
118
+ Alternatively, to have custom rules just for REP you can:
121
119
 
122
120
  Rails.application.config.to_prepare do
123
121
  RailsEmailPreview::ApplicationController.module_eval do
124
- before_filter :check_permissions
122
+ before_filter :check_rep_permissions
125
123
 
126
124
  private
127
- def check_permissions
128
- render status: 403 unless current_user.try(:admin?)
125
+ def check_rep_permissions
126
+ render status: 403 unless current_user && can_manage_emails?(current_user)
129
127
  end
130
128
  end
131
129
  end
@@ -1,5 +1,5 @@
1
1
  module RailsEmailPreview
2
- class ApplicationController < ::ApplicationController
2
+ class ApplicationController < ::RailsEmailPreview.parent_controller.constantize
3
3
 
4
4
  end
5
- end
5
+ end
@@ -1,4 +1,4 @@
1
- class RailsEmailPreview::EmailsController < RailsEmailPreview::ApplicationController
1
+ class RailsEmailPreview::EmailsController < ::RailsEmailPreview::ApplicationController
2
2
  include ERB::Util
3
3
  before_filter :load_preview_class, except: :index
4
4
  before_filter :set_email_preview_locale
@@ -0,0 +1,10 @@
1
+ module RepUrlsHelper
2
+ # to make it easy to change root url without breaking backwards compatibility, declare them here as aliases
3
+ def rep_root_url
4
+ rails_email_preview.rep_emails_url
5
+ end
6
+
7
+ def rep_root_path
8
+ rails_email_preview.rep_emails_path
9
+ end
10
+ end
@@ -12,5 +12,5 @@ javascript:
12
12
  }
13
13
 
14
14
  pre#loading-el.lead #{icon 'spinner', 'spin'} Loading...
15
- iframe#src-iframe[src=rails_email_preview.raw_email_url(params.slice(:mail_class, :mail_action, :part_type).merge(email_locale: @email_locale))
15
+ iframe#src-iframe[src=rails_email_preview.rep_raw_email_url(params.slice(:mail_class, :mail_action, :part_type).merge(email_locale: @email_locale))
16
16
  width="100%" height=1 onLoad="iFrameLoad('src-iframe')" style="border:none;padding:0;margin:0"]
@@ -1,9 +1,9 @@
1
1
  p.btn-group
2
2
  - { 'text/html' => 'HTML', 'text/plain' => 'Text', 'raw' => 'Raw'}.each do |mime, label|
3
- a.btn.btn-link href=rails_email_preview.email_url(params.merge(part_type: mime)) class=('active' if @part_type == mime)
3
+ a.btn.btn-link href=rails_email_preview.rep_email_url(params.merge(part_type: mime)) class=('active' if @part_type == mime)
4
4
  = label
5
5
  br
6
6
  p.btn-group
7
7
  - I18n.available_locales.each do |locale|
8
- a.btn.btn-link href=rails_email_preview.email_url(params.merge(part_type: @part_type, email_locale: locale)) class=('active' if @email_locale == locale.to_s)
8
+ a.btn.btn-link href=rails_email_preview.rep_email_url(params.merge(part_type: @part_type, email_locale: locale)) class=('active' if @email_locale == locale.to_s)
9
9
  = locale
@@ -6,5 +6,5 @@ ul.list-unstyled
6
6
  ul.list-group
7
7
  - m.constantize.instance_methods(false).map(&:to_s).each do |method|
8
8
  li.list-group-item
9
- a href=rails_email_preview.email_url(mail_class: m.to_s.underscore, mail_action: method.to_s, email_locale: @email_locale)
9
+ a href=rails_email_preview.rep_email_url(mail_class: m.to_s.underscore, mail_action: method.to_s, email_locale: @email_locale)
10
10
  = method.to_s.humanize
@@ -1,4 +1,4 @@
1
- a.btn.btn-link href=rails_email_preview.root_url(email_locale: @email_locale) &laquo; Back to list
1
+ a.btn.btn-link href=rails_email_preview.rep_emails_url(email_locale: @email_locale) &laquo; Back to list
2
2
 
3
3
  #email-show
4
4
  -# email format and language
@@ -1,29 +1,31 @@
1
1
  require 'rails_email_preview'
2
2
 
3
- # Add this to process preview with premailer-rails
3
+ #= Premailer
4
+ #
5
+ # # process preview with premailer-rails:
4
6
  # RailsEmailPreview.before_render { |message| Premailer::Rails::Hook.delivering_email(message) }
5
-
6
- # with actionmailer-inline-css
7
+ # # process preview with actionmailer-inline-css:
7
8
  # RailsEmailPreview.before_render { |message| ActionMailer::InlineCssHook.delivering_email(message) }
8
9
 
10
+ #= Comfortable Mexican Sofa
11
+ #
12
+ # # enable comfortable_mexican_sofa integration:
13
+ # require 'rails_email_preview/integrations/comfortable_mexica_sofa'
14
+
15
+ #= Application-specific
16
+ #
17
+ # # You can specify a controller for RailsEmailPreview::ApplicationController to inherit from:
18
+ # RailsEmailPreview.parent_controller = 'Admin::ApplicationController' # default: '::ApplicationController'
19
+ #
20
+ # # Render REP inside a custom layout (set to 'application' to use app layout, default is REP's own layout)
21
+ # RailsEmailPreview::ApplicationController.layout 'admin'
22
+
9
23
  Rails.application.config.to_prepare do
10
- # Choose where to load preview_classes from:
24
+ # # If you use a *custom layout*, make route helpers available to REP:
25
+ # RailsEmailPreview.inline_main_app_routes!
26
+
27
+ # Auto-load preview classes from:
11
28
  RailsEmailPreview.preview_classes = Dir['app/mailer_previews/*_preview.rb'].map { |p|
12
29
  File.basename(p, '.rb').camelize
13
30
  }
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
31
  end
27
-
28
- # Uncomment this to enable comfortable_mexican_sofa integration
29
- # require 'rails_email_preview/integrations/comfortable_mexica_sofa'
data/config/routes.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  RailsEmailPreview::Engine.routes.draw do
2
- root :to => 'emails#index'
3
- get 'raw/:mail_class/:mail_action',
4
- :as => :raw_email,
5
- :to => 'emails#show_raw',
6
- :mail_class => %r([\w/]+)
7
- get ':mail_class/:mail_action',
8
- :as => :email,
9
- :to => 'emails#show',
10
- :mail_class => %r([\w/]+)
2
+ get '/' => 'emails#index', as: :rep_emails
3
+
4
+ get 'raw/:mail_class/:mail_action' => 'emails#show_raw', as: :rep_raw_email
5
+ get ':mail_class/:mail_action' => 'emails#show', as: :rep_email
6
+
7
+ # define alias for the root url as part of stable api
8
+ get '/' => 'emails#index', as: :rep_root
11
9
  end
@@ -10,8 +10,7 @@ module RailsEmailPreview
10
10
 
11
11
  def generate_routing
12
12
  route "mount RailsEmailPreview::Engine, at: 'emails'"
13
- log "# You can access REP urls like this:
14
- rails_email_preview.root_url #=> '/emails'"
13
+ log "# You can access REP urls like this: rails_email_preview.rep_emails_url #=> '/emails'"
15
14
  end
16
15
  end
17
16
  end
@@ -1,6 +1,13 @@
1
1
  require 'rails_email_preview/engine'
2
+ require 'rails_email_preview/main_app_route_delegator'
3
+ require 'rails_email_preview/version'
2
4
 
3
5
  module RailsEmailPreview
6
+
7
+ mattr_accessor :parent_controller
8
+ self.parent_controller = '::ApplicationController'
9
+
10
+ # auto-loading configured in initializer
4
11
  mattr_accessor :preview_classes
5
12
 
6
13
  class << self
@@ -14,6 +21,10 @@ module RailsEmailPreview
14
21
  ((@hooks ||= {})[:before_render] ||= []) << block
15
22
  end
16
23
 
24
+ def inline_main_app_routes!
25
+ ::RailsEmailPreview::ApplicationController.helper ::RailsEmailPreview::MainAppRouteDelegator
26
+ end
27
+
17
28
  def setup
18
29
  yield self
19
30
  end
@@ -22,7 +33,7 @@ module RailsEmailPreview
22
33
  # = Editing settings
23
34
  # edit link is rendered inside an iframe, so these options are provided for simple styling
24
35
  mattr_accessor :edit_link_text
25
- self.edit_link_text = '✎ Edit Text'
36
+ self.edit_link_text = '✎ Edit Text'
26
37
  mattr_accessor :edit_link_style
27
38
  self.edit_link_style = <<-CSS.strip.gsub(/\n+/m, ' ')
28
39
  display: block;
@@ -0,0 +1,14 @@
1
+ module RailsEmailPreview::MainAppRouteDelegator
2
+ # delegate url helpers to main_app
3
+ def method_missing(method, *args, &block)
4
+ if method.to_s =~ /_(?:path|url)$/ && main_app.respond_to?(method)
5
+ main_app.send(method, *args)
6
+ else
7
+ super
8
+ end
9
+ end
10
+
11
+ def respond_to?(method)
12
+ super || main_app.respond_to?(method)
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '0.1.7'
2
+ VERSION = '0.2.0'
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.7
4
+ version: 0.2.0
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-14 00:00:00.000000000 Z
11
+ date: 2013-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -106,6 +106,7 @@ files:
106
106
  - app/controllers/rails_email_preview/application_controller.rb
107
107
  - app/controllers/rails_email_preview/emails_controller.rb
108
108
  - app/helpers/rails_email_preview/emails_helper.rb
109
+ - app/helpers/rails_email_preview/rep_urls_helper.rb
109
110
  - app/views/integrations/cms/_customize_cms_for_rails_email_preview.html.slim
110
111
  - app/views/layouts/rails_email_preview/application.html.slim
111
112
  - app/views/rails_email_preview/emails/_email_iframe.html.slim
@@ -117,6 +118,7 @@ files:
117
118
  - lib/generators/rails_email_preview/update_previews_generator.rb
118
119
  - lib/rails_email_preview/engine.rb
119
120
  - lib/rails_email_preview/integrations/comfortable_mexica_sofa.rb
121
+ - lib/rails_email_preview/main_app_route_delegator.rb
120
122
  - lib/rails_email_preview/version.rb
121
123
  - lib/rails_email_preview.rb
122
124
  - config/initializers/rails_email_preview.rb