rails_email_preview 0.2.4 → 0.2.5

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.
@@ -1,4 +1,43 @@
1
1
  module RailsEmailPreview::EmailsHelper
2
+ def current_email_name
3
+ "#{preview_class_human_name}: #{@mail_action.to_s.humanize}"
4
+ end
5
+
6
+ def preview_class_human_name(preview_class = @preview_class)
7
+ preview_class.to_s.underscore.sub(/(_mailer)?_preview$/, '').humanize
8
+ end
9
+
10
+ def change_locale_attr(locale)
11
+ {href: rails_email_preview.rep_email_url(params.merge(part_type: @part_type, email_locale: locale)),
12
+ class: ('active' if @email_locale == locale.to_s)}
13
+ end
14
+
15
+ def change_format_attr(mime)
16
+ {href: rails_email_preview.rep_email_url(params.merge(part_type: mime)),
17
+ class: ('active' if @part_type == mime)}
18
+ end
19
+
20
+ def locale_name(locale)
21
+ if defined?(TwitterCldr)
22
+ TwitterCldr::Shared::LanguageCodes.to_language(locale.to_s, :bcp_47)
23
+ else
24
+ locale.to_s
25
+ end
26
+ end
27
+
28
+ def headers_name_value
29
+ I18n.with_locale @email_locale do
30
+ {
31
+ 'Subject' => @mail.subject || '(no subject)',
32
+ 'From' => @mail.from,
33
+ 'Reply to' => @mail.reply_to,
34
+ 'To' => @mail.to,
35
+ 'CC' => @mail.cc,
36
+ 'BCC' => @mail.bcc
37
+ }.delete_if { |k, v| v.blank? }
38
+ end
39
+ end
40
+
2
41
  def format_header(value)
3
42
  if value.is_a?(Array)
4
43
  value.map(&:to_s) * ', '
@@ -12,8 +51,8 @@ module RailsEmailPreview::EmailsHelper
12
51
  end
13
52
 
14
53
  def split_in_halves(elements, &weight)
15
- tot_w = elements.map(&weight).sum
16
- cols = [elements.dup, []]
54
+ tot_w = elements.map(&weight).sum
55
+ cols = [elements.dup, []]
17
56
  col2_w = 0
18
57
  cols[0].reverse_each do |cl|
19
58
  n = weight.call(cl)
@@ -1,10 +1,22 @@
1
1
  -# When rendering inside rails_email_preview hide nav, and hide irrelevant things from the form
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
9
+ end
2
10
  javascript:
3
11
  jQuery(function($) {
4
12
  if (window.parent && /email/.test(parent.location.href)) {
5
13
  // Hide nav:
6
14
  $('.left-column,.right-column').hide();
7
15
  $('.center-column').css('margin', 0);
16
+ $('.page-header h2').html(
17
+ "Editing email" +
18
+ " <a href='#{show_url}'>#{t 'rep.view_link'}</a>"
19
+ )
8
20
 
9
21
  // Snippet form:
10
22
  var control = function(name) { return $('[name^="snippet[' + name + ']"]').closest('.control-group'); };
@@ -0,0 +1,5 @@
1
+ .btn-group
2
+ - { 'text/html' => 'HTML', 'text/plain' => 'Text', 'raw' => 'Raw'}.each do |mime, label|
3
+ a.btn.btn-xs *change_format_attr(mime)
4
+ = label
5
+
@@ -1,17 +1,4 @@
1
- ruby:
2
- headers = I18n.with_locale @email_locale do
3
- {
4
- 'Subject' => @mail.subject || '(no subject)',
5
- 'From' => @mail.from,
6
- 'Reply to' => @mail.reply_to,
7
- 'To' => @mail.to,
8
- 'CC' => @mail.cc,
9
- 'BCC' => @mail.bcc
10
- }.delete_if { |k, v| v.blank? }
11
- end
12
-
13
-
14
- dl.inline-dl
15
- - headers.each do |header, value|
16
- dt = header
17
- dd = format_header(value)
1
+ dl.rep-headers-list.dl-horizontal
2
+ - headers_name_value.each do |name, value|
3
+ dt = name
4
+ dd = format_header value
@@ -0,0 +1,5 @@
1
+ .btn-group
2
+ - I18n.available_locales.each do |locale|
3
+ -# href, active class from change_locale_attr(locale)
4
+ a.btn *change_locale_attr(locale)
5
+ = locale_name(locale)
@@ -1,4 +1,4 @@
1
- div style="max-width: 250px"
1
+ .clearfix: .pull-right style="max-width: 250px"
2
2
  = form_tag rails_email_preview.rep_test_deliver_url, method: :post do
3
3
  = hidden_field_tag :email_locale, @email_locale
4
4
  .input-group
@@ -2,7 +2,7 @@ h1 #{t 'rep.list_title'}
2
2
 
3
3
  - previews_group = proc do |m|
4
4
  - capture do
5
- h2= m.underscore.sub(/(_mailer)?_preview$/, '').humanize
5
+ h2 = preview_class_human_name(m)
6
6
  ul.list-group
7
7
  - email_methods(m).each do |method|
8
8
  li.list-group-item
@@ -10,7 +10,7 @@ h1 #{t 'rep.list_title'}
10
10
  = method.to_s.humanize
11
11
 
12
12
  .row
13
- - split_in_halves(@preview_class_names) { |c| email_methods(c).length } .each do |classes|
14
- .col-sm-6
13
+ - split_in_halves(@preview_class_names) { |c| email_methods(c).length }.each do |classes|
14
+ .col-sm-6.col-lg-6
15
15
  - classes.each do |class_name|
16
16
  = previews_group.call(class_name)
@@ -1,14 +1,20 @@
1
- .row
2
- .pull-left
3
- a.btn.btn-link href=rails_email_preview.rep_emails_url(email_locale: @email_locale) « #{t 'rep.back_to_list'}
4
- .margin-right= render 'rails_email_preview/emails/toolbar'
1
+ .rep-email-show#email-show
2
+ .row
3
+ .pull-left
4
+ ul.breadcrumb
5
+ li: a href=rails_email_preview.rep_emails_url(email_locale: @email_locale) #{t 'rep.breadcrumb_list'}
6
+ li.active: a href=(request.url) = current_email_name
5
7
 
6
- #email-show: .row
7
- -# From, To, Subject and other
8
- = render 'rails_email_preview/emails/headers'
9
- -# Locale, format and actions
8
+ .panel: .row
9
+ -# From, To, Subject and other headers
10
+ .col-8= render 'rails_email_preview/emails/headers'
10
11
 
11
- -# actual email content, rendered in an iframe to prevent browser styles from interfering
12
- .row
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'
17
+
18
+ -# actual email content, rendered in an iframe to prevent browser styles from interfering
13
19
  .margin-right
14
20
  = render 'rails_email_preview/emails/email_iframe'
@@ -5,8 +5,9 @@ en:
5
5
  provide_email: Send to which address?
6
6
  sent_notice: "Sent to %{address} via %{delivery_method}"
7
7
  list_title: Application Emails
8
- back_to_list: Back to list
8
+ breadcrumb_list: Emails
9
9
  send_recipient_placeholder: Email
10
10
  send_btn: Send to
11
11
  send_are_you_sure: This will actually send this email. Are you sure?
12
+ view_link: View
12
13
 
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
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.4
4
+ version: 0.2.5
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-05 00:00:00.000000000 Z
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -117,15 +117,17 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - app/assets/stylesheets/rails_email_preview/application.css.sass
120
+ - app/assets/stylesheets/rails_email_preview/bootstrap.css
120
121
  - app/controllers/rails_email_preview/application_controller.rb
121
122
  - app/controllers/rails_email_preview/emails_controller.rb
122
123
  - app/helpers/rails_email_preview/emails_helper.rb
123
124
  - app/views/integrations/cms/_customize_cms_for_rails_email_preview.html.slim
124
125
  - app/views/layouts/rails_email_preview/application.html.slim
125
126
  - app/views/rails_email_preview/emails/_email_iframe.html.slim
127
+ - app/views/rails_email_preview/emails/_format_nav.html.slim
126
128
  - app/views/rails_email_preview/emails/_headers.html.slim
129
+ - app/views/rails_email_preview/emails/_i18n_nav.html.slim
127
130
  - app/views/rails_email_preview/emails/_send_form.html.slim
128
- - app/views/rails_email_preview/emails/_toolbar.html.slim
129
131
  - app/views/rails_email_preview/emails/index.html.slim
130
132
  - app/views/rails_email_preview/emails/show.html.slim
131
133
  - lib/generators/rails_email_preview/install_generator.rb
@@ -1,13 +0,0 @@
1
- .btn-toolbar.pull-right
2
- .btn-group
3
- - I18n.available_locales.each do |locale|
4
- a.btn href=rails_email_preview.rep_email_url(params.merge(part_type: @part_type, email_locale: locale)) class=('active' if @email_locale == locale.to_s)
5
- = locale
6
-
7
- .btn-group
8
- - { 'text/html' => 'HTML', 'text/plain' => 'Text', 'raw' => 'Raw'}.each do |mime, label|
9
- a.btn href=rails_email_preview.rep_email_url(params.merge(part_type: mime)) class=('active' if @part_type == mime)
10
- = label
11
-
12
- - if RailsEmailPreview.enable_send_email
13
- .btn-group= render 'rails_email_preview/emails/send_form'