rails_email_preview 0.2.6 → 0.2.7

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: cdd99b26068ba1bed5683224775565b4542a3b82
4
- data.tar.gz: fa1c1a594e220635f6c90cc8127d88f6c4ed86ef
3
+ metadata.gz: 737f667f2755587a5e1058c0b23ebd67f2b1b9cb
4
+ data.tar.gz: 0501a6d93155acc2cd89b7c7d2d8c50fa28ff92b
5
5
  SHA512:
6
- metadata.gz: d33f26c046cf0ffe23c0cdc040ce2dcb2df2ffe3aad97ce82a4ba96bbf5a2334de544be8581fded6032930d8986174c85b484605379468803aad846eb1e52d6c
7
- data.tar.gz: 565a76ef4e8231d9090e489afa51886b5233ee8f8510e40ec59ac58d090c21a2be07ca8fbbf473d12ead45f954dce2013e559f8a0afe776068a074cb681dc506
6
+ metadata.gz: 70d12a90a5f9a4988fc4374ef33011f88ccd8905d3c505c9f70567549720251fe93fb5e00419cfc5e3c01d637bca5e38db0154006976daadd05332d700a4fac4
7
+ data.tar.gz: d27179e2f3e89963fe4005a48cdfb53d84aa36c10352f88ec972fbb62813e4d3d4b5910659e920cbd0b768cae3014261299adcbed93fb10b26084555f32602e6
data/README.md CHANGED
@@ -9,7 +9,7 @@ Preview:
9
9
  List:
10
10
  ![screenshot][rep-nav-screenshot]
11
11
 
12
- REP can use the application styles and comes with a [simple look][rep-show-default-screenshot] by default (default markup for [twbs/bootstrap](twbs/bootstrap) 3).
12
+ REP can use the application styles and comes with [simple styles][rep-show-default-screenshot] by default (default markup for [twbs/bootstrap](twbs/bootstrap) 3).
13
13
  *These screenshots are from [Zuigo](http://zuigo.com/), a platform to organize & discover events; using REP default markup and app styles*
14
14
 
15
15
  How to
@@ -17,7 +17,7 @@ How to
17
17
 
18
18
  Add to Gemfile
19
19
 
20
- gem 'rails_email_preview', '~> 0.2.0'
20
+ gem 'rails_email_preview', '~> 0.2'
21
21
 
22
22
  REP handles setup for you:
23
23
 
@@ -116,7 +116,24 @@ If you are using `Resque::Mailer` or `Devise::Async`, you can automatically add
116
116
  Views
117
117
  ---------------------
118
118
 
119
- You can render all REP views inside your own layout:
119
+ REP allows you to customize some of the classes via `RailsEmailPreview.style`:
120
+
121
+ {
122
+ btn_default_class: 'btn btn-default',
123
+ btn_active_class: 'btn btn-primary active',
124
+ btn_group_class: 'btn-group',
125
+ list_group_class: 'list-group',
126
+ list_group_item_class: 'list-group-item',
127
+ panel_class: 'panel',
128
+ row_class: 'row',
129
+ column_class: 'col-%{n}'
130
+ }
131
+
132
+ E.g., to change column class from `col-` to `column-` everywhere where REP uses columns:
133
+
134
+ RailsEmailPreview.style[:column_class] = 'column-%{n}'
135
+
136
+ If you want to really integrate REP, ou can render all its views inside your own layout (this will need styling to look nice if you don't use bootstrap):
120
137
 
121
138
  # # Use admin layout with REP:
122
139
  # RailsEmailPreview::ApplicationController.layout 'admin'
@@ -9,12 +9,12 @@ module RailsEmailPreview::EmailsHelper
9
9
 
10
10
  def change_locale_attr(locale)
11
11
  {href: rails_email_preview.rep_email_url(params.merge(part_type: @part_type, email_locale: locale)),
12
- class: ('active btn-primary' if @email_locale == locale.to_s)}
12
+ class: rep_btn_class(@email_locale == locale.to_s)}
13
13
  end
14
14
 
15
15
  def change_format_attr(mime)
16
16
  {href: rails_email_preview.rep_email_url(params.merge(part_type: mime)),
17
- class: ('active btn-primary' if @part_type == mime)}
17
+ class: rep_btn_class(@part_type == mime)}
18
18
  end
19
19
 
20
20
  def locale_name(locale)
@@ -67,4 +67,25 @@ module RailsEmailPreview::EmailsHelper
67
67
  cols[1].reverse!
68
68
  cols
69
69
  end
70
+
71
+ # style
72
+ def rep_style
73
+ RailsEmailPreview.style
74
+ end
75
+
76
+ def rep_btn_class(active = false)
77
+ rep_style[:"btn_#{active ? 'active' : 'default'}_class"]
78
+ end
79
+
80
+ def rep_row_class
81
+ rep_style[:row_class]
82
+ end
83
+
84
+ def rep_col_class(n)
85
+ rep_style[:column_class] % {n: n}
86
+ end
87
+
88
+ def rep_btn_group_class
89
+ rep_style[:btn_group_class]
90
+ end
70
91
  end
@@ -1,11 +1,9 @@
1
1
  -# When rendering inside rails_email_preview hide nav, and hide irrelevant things from the form
2
2
  ruby:
3
- prefix = 'email-'
4
- if @snippet && @snippet.identifier.try(:start_with?, prefix) && %w(new edit create update).include?(params[:action])
5
- url_params = {part_type: 'text/html'}
6
- url_params[:mail_class], url_params[:mail_action] = @snippet.identifier[prefix.length..-1].split('-')
7
- url_params[:mail_class] += '_preview'
8
- show_url = rails_email_preview.rep_raw_email_url url_params
3
+ snippet = @snippet || @record.is_a?(Cms::Snippet) && @record
4
+ if snippet
5
+ p = ::RailsEmailPreview::Integrations::ComfortableMexicanSofa.rep_email_params_from_snippet(snippet)
6
+ show_url = rails_email_preview.rep_raw_email_url(p.merge part_type: 'text/html')
9
7
  end
10
8
  javascript:
11
9
  jQuery(function($) {
@@ -15,7 +13,7 @@ javascript:
15
13
  $('.center-column').css('margin', 0);
16
14
  $('.page-header h2').html(
17
15
  "Editing email" +
18
- " <a href='#{show_url}'>#{t 'rep.view_link'}</a>"
16
+ " <a class='btn btn-primary' href='#{show_url}'>#{t 'rep.view_link'}</a>"
19
17
  )
20
18
 
21
19
  // Snippet form:
@@ -1,5 +1,5 @@
1
- .btn-group
1
+ div class=rep_btn_group_class
2
2
  - { 'text/html' => 'HTML', 'text/plain' => 'Text', 'raw' => 'Raw'}.each do |mime, label|
3
- a.btn.btn-xs *change_format_attr(mime)
3
+ a.btn-xs *change_format_attr(mime)
4
4
  = label
5
5
 
@@ -1,4 +1,4 @@
1
- .btn-group
1
+ div class=rep_btn_group_class
2
2
  - I18n.available_locales.each do |locale|
3
3
  -# href, active class from change_locale_attr(locale)
4
4
  a.btn *change_locale_attr(locale)
@@ -4,15 +4,15 @@ h1
4
4
  - previews_group = proc do |m|
5
5
  - capture do
6
6
  h2 = preview_class_human_name(m)
7
- ul.list-group
7
+ ul class=rep_style[:list_group_class]
8
8
  - email_methods(m).each do |method|
9
- li.list-group-item
9
+ li class=rep_style[:list_group_item_class]
10
10
  a href=rails_email_preview.rep_email_url(mail_class: m.to_s.underscore, mail_action: method.to_s, email_locale: @email_locale)
11
11
  = method.to_s.humanize
12
12
 
13
- .row
13
+ div class=rep_row_class
14
14
  - split_in_halves(@preview_class_names) { |c| email_methods(c).length }.each do |classes|
15
- .col-sm-6.col-lg-6
15
+ div class=rep_col_class(6)
16
16
  - classes.each do |class_name|
17
17
  = previews_group.call(class_name)
18
18
 
@@ -1,19 +1,21 @@
1
1
  .rep-email-show#email-show
2
- .row
2
+ div class=rep_row_class
3
3
  .pull-left
4
4
  ul.breadcrumb
5
5
  li: a href=rails_email_preview.rep_emails_url(email_locale: @email_locale) #{t 'rep.breadcrumb_list'}
6
6
  li.active: a href=(request.url) = current_email_name
7
7
 
8
- .panel: .row
9
- -# From, To, Subject and other headers
10
- .col-8= render 'rails_email_preview/emails/headers'
11
-
12
- -# Locale, format and actions
13
- .col-4: ul.list-unstyled.text-right.rep-email-options
14
- li= render 'rails_email_preview/emails/i18n_nav'
15
- li= render 'rails_email_preview/emails/send_form' if RailsEmailPreview.enable_send_email
16
- li= render 'rails_email_preview/emails/format_nav'
8
+ div class=rep_style[:panel_class]
9
+ div class=rep_style[:row_class]
10
+ -# From, To, Subject and other headers
11
+ div class=rep_col_class(8)
12
+ = render 'rails_email_preview/emails/headers'
13
+ -# Locale, format and actions
14
+ div class=rep_col_class(4)
15
+ ul.list-unstyled.text-right.rep-email-options
16
+ li= render 'rails_email_preview/emails/i18n_nav'
17
+ li= render 'rails_email_preview/emails/send_form' if RailsEmailPreview.enable_send_email
18
+ li= render 'rails_email_preview/emails/format_nav'
17
19
 
18
20
  -# actual email content, rendered in an iframe to prevent browser styles from interfering
19
21
  .margin-right
@@ -20,6 +20,19 @@ module RailsEmailPreview
20
20
  mattr_accessor :enable_send_email
21
21
  self.enable_send_email = true
22
22
 
23
+ # some easy visual settings
24
+ mattr_accessor :style
25
+ self.style = {
26
+ btn_default_class: 'btn btn-default',
27
+ btn_active_class: 'btn btn-primary active',
28
+ btn_group_class: 'btn-group',
29
+ list_group_class: 'list-group',
30
+ list_group_item_class: 'list-group-item',
31
+ panel_class: 'panel',
32
+ row_class: 'row',
33
+ column_class: 'col-%{n}'
34
+ }
35
+
23
36
  class << self
24
37
  def run_before_render(mail, preview_class_name, mailer_action)
25
38
  (defined?(@hooks) && @hooks[:before_render] || []).each do |block|
@@ -18,15 +18,15 @@ module RailsEmailPreview
18
18
  def cms_email_subject(interpolation = {})
19
19
  snippet_id = "email-#{cms_email_id}"
20
20
  [I18n.locale, I18n.default_locale].compact.each do |locale|
21
- site = Cms::Site.find_by_locale(locale)
21
+ site = Cms::Site.find_by_locale(locale)
22
22
  snippet = site.snippets.find_by_identifier(snippet_id)
23
23
  next unless snippet.try(:content).present?
24
24
 
25
25
  # interpolate even if keys/values are missing
26
- title = snippet.label.to_s
26
+ title = snippet.label.to_s
27
27
  interpolation = interpolation.stringify_keys
28
28
  # set all missing values to ''
29
- title.scan(/%{([^}]+)}/) { |m| interpolation[m[0]] ||= ''}
29
+ title.scan(/%{([^}]+)}/) { |m| interpolation[m[0]] ||= '' }
30
30
  # remove all missing keys
31
31
  subject = title % interpolation.symbolize_keys.delete_if { |k, v| title !~ /%{#{k}}/ }
32
32
 
@@ -60,7 +60,7 @@ module RailsEmailPreview
60
60
 
61
61
  cms_path = if snippet
62
62
  unless content
63
- fallback_snippet = default_site.snippets.find_by_identifier(snippet_id)
63
+ fallback_snippet = default_site.snippets.find_by_identifier(snippet_id)
64
64
  prefill_from_default = {label: fallback_snippet.label, content: fallback_snippet.content}
65
65
  end
66
66
  edit_cms_admin_site_snippet_path(site_id: site.id, id: snippet.id,
@@ -84,6 +84,16 @@ module RailsEmailPreview
84
84
  def cms_edit_email_snippet_link(path)
85
85
  link_to(RailsEmailPreview.edit_link_text, path, style: RailsEmailPreview.edit_link_style.html_safe, 'onClick' => '')
86
86
  end
87
+
88
+ def self.rep_email_params_from_snippet(snippet)
89
+ id_prefix = 'email-'
90
+ return unless snippet && snippet.identifier.starts_with?(id_prefix)
91
+ mailer_cl, act = snippet.identifier[id_prefix.length..-1].split('-')
92
+ mailer_cl += '_preview'
93
+ { mail_class: mailer_cl,
94
+ mail_action: act,
95
+ email_locale: snippet.site.locale}
96
+ end
87
97
  end
88
98
  end
89
99
  end
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_email_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Mazovetskiy