rails_email_preview 0.2.31 → 1.0.0

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -8
  3. data/app/assets/stylesheets/rails_email_preview/application.css.sass +228 -3
  4. data/app/assets/stylesheets/rails_email_preview/bootstrap3.css.sass +68 -0
  5. data/app/controllers/rails_email_preview/emails_controller.rb +14 -6
  6. data/app/helpers/rails_email_preview/emails_helper.rb +1 -14
  7. data/app/views/integrations/cms/{_customize_cms_for_rails_email_preview.html.slim → _customize_cms_for_rails_email_preview.html.erb} +16 -12
  8. data/app/views/layouts/rails_email_preview/_flash_notices.html.erb +7 -0
  9. data/app/views/layouts/rails_email_preview/application.html.erb +15 -0
  10. data/app/views/layouts/rails_email_preview/email.html.erb +30 -0
  11. data/app/views/rails_email_preview/emails/{_email_iframe.html.slim → _email_iframe.html.erb} +17 -14
  12. data/app/views/rails_email_preview/emails/_format_nav.html.erb +4 -0
  13. data/app/views/rails_email_preview/emails/_headers.html.erb +10 -0
  14. data/app/views/rails_email_preview/emails/_headers_and_nav.html.erb +12 -0
  15. data/app/views/rails_email_preview/emails/_i18n_nav.html.erb +3 -0
  16. data/app/views/rails_email_preview/emails/_nav.html.erb +18 -0
  17. data/app/views/rails_email_preview/emails/_send_form.html.erb +11 -0
  18. data/app/views/rails_email_preview/emails/index.html.erb +36 -0
  19. data/app/views/rails_email_preview/emails/show.html.erb +23 -0
  20. data/lib/rails_email_preview.rb +11 -12
  21. data/lib/rails_email_preview/version.rb +1 -1
  22. metadata +15 -32
  23. data/app/assets/stylesheets/rails_email_preview/_bootstrap.css.scss +0 -7844
  24. data/app/assets/stylesheets/rails_email_preview/_bootstrap_theme.css.scss +0 -345
  25. data/app/assets/stylesheets/rails_email_preview/_layout.css.sass +0 -13
  26. data/app/views/layouts/rails_email_preview/_flash_notices.html.slim +0 -5
  27. data/app/views/layouts/rails_email_preview/application.html.slim +0 -12
  28. data/app/views/layouts/rails_email_preview/email.html.slim +0 -28
  29. data/app/views/rails_email_preview/emails/_format_nav.html.slim +0 -6
  30. data/app/views/rails_email_preview/emails/_headers.html.slim +0 -6
  31. data/app/views/rails_email_preview/emails/_headers_and_nav.html.slim +0 -8
  32. data/app/views/rails_email_preview/emails/_headers_content.html.slim +0 -0
  33. data/app/views/rails_email_preview/emails/_i18n_nav.html.slim +0 -5
  34. data/app/views/rails_email_preview/emails/_nav.html.slim +0 -13
  35. data/app/views/rails_email_preview/emails/_send_form.html.slim +0 -6
  36. data/app/views/rails_email_preview/emails/index.html.slim +0 -21
  37. data/app/views/rails_email_preview/emails/show.html.slim +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90e5262b6ef9d3bf7b55df8ca3bb46004103bd9b
4
- data.tar.gz: 1d96c1d2a68c9602040875d45557d50d55d03d00
3
+ metadata.gz: 02bcd4fe9bb7401449acd3b44245c93f8d5ab360
4
+ data.tar.gz: 5b7c64b281650e047e113cb020f83c4050156e20
5
5
  SHA512:
6
- metadata.gz: 188be5c4b3ce2c18818b83766abcd008b28704f66aefc8c45861f8f8b81dfcbc16efcbb0f9167655d52c2666e8c110719e33f9fd9004c6223229402731c1501b
7
- data.tar.gz: 8f8c7888f0c9681d02f0f65b4df9d113e6da8203ee8c969d487d7f212770f2c05747d0e363d3420b9ea1eaa38f30d152878aab91e941d20d6cf3c5b0d488d0bf
6
+ metadata.gz: 081630f21830afb463670897d4517670bc890a9ff47b927e0a035dbec1f0baf5866bec0ac4ef99d7d27527996a79d9cbf744c476f7ccd76fa82a19acc18c642f
7
+ data.tar.gz: 26f7398c358fa2b9041ba6a9bb0af737b87397c5ed2ce81f769d0d63bd6ccbe73fe922476e81464e4bf395b789a447ed64992290916366e0830fed3e0b1131f6
data/README.md CHANGED
@@ -2,21 +2,22 @@
2
2
 
3
3
  Preview email in the browser with this Rails engine. Compatible with Rails 3 and 4.
4
4
 
5
- Preview:
5
+ An email review:
6
+
6
7
  ![screenshot][rep-show-screenshot]
7
8
 
8
- List:
9
+ The list of all email previews:
10
+
9
11
  ![screenshot][rep-nav-screenshot]
10
12
 
11
- REP can use your application styles, markup is compatible with [bootstrap 3][rep-show-default-screenshot] by default.
12
- *These screenshots are using a custom Bootstrap theme*
13
+ REP comes with two themes: a simple standalone theme, and a theme that uses [Bootstrap 3][rep-show-default-screenshot].
13
14
 
14
15
  ## Installation
15
16
 
16
17
  Add [![Gem Version][gem-badge]][gem] to Gemfile:
17
18
 
18
19
  ```ruby
19
- gem 'rails_email_preview', '~> 0.2.31'
20
+ gem 'rails_email_preview', '~> 1.0.0'
20
21
  ```
21
22
 
22
23
  Add an initializer and the routes:
@@ -154,7 +155,9 @@ RailsEmailPreview.locale = :de
154
155
 
155
156
  ### Views
156
157
 
157
- You can render all REP views inside your app layout (this will need styling to look nice if you don't use bootstrap):
158
+ By default REP views will render inside its own layout.
159
+
160
+ To render all REP views inside your app layout, first set the layout to use in the initializer:
158
161
 
159
162
  ```ruby
160
163
  Rails.application.config.to_prepare do
@@ -163,9 +166,28 @@ Rails.application.config.to_prepare do
163
166
  end
164
167
  ```
165
168
 
166
- You can `//= require 'rails_email_preview/layout'` REP-specific styles (`@import 'rails_email_preview/layout'` for SASS).
169
+ Then, import REP styles into your `application.css.scss`:
170
+
171
+ ```scss
172
+ @import "rails_email_preview/application";
173
+ ```
174
+
175
+ Alternatively, if you are using Bootstrap 3, `@import "rails_email_preview/application"`, and add the following
176
+ to the initializer:
167
177
 
168
- REP also allows you to customize some of the element classes via [`RailsEmailPreview.style`](/lib/rails_email_preview.rb#L34).
178
+ ```ruby
179
+ config.style.merge!(
180
+ btn_active_class_modifier: 'active',
181
+ btn_danger_class: 'btn btn-danger',
182
+ btn_default_class: 'btn btn-default',
183
+ btn_group_class: 'btn-group btn-group-sm',
184
+ btn_primary_class: 'btn btn-primary',
185
+ form_control_class: 'form-control',
186
+ list_group_class: 'list-group',
187
+ list_group_item_class: 'list-group-item',
188
+ row_class: 'row',
189
+ )
190
+ ```
169
191
 
170
192
  You can also override any individual view by placing a file with the same path in your project's `app/views`,
171
193
  e.g. `app/views/rails_email_preview/emails/index.html.slim`.
@@ -1,3 +1,228 @@
1
- @import 'rails_email_preview/bootstrap'
2
- @import 'rails_email_preview/bootstrap_theme'
3
- @import 'rails_email_preview/layout'
1
+ // A standalone theme for Rails Email Preview
2
+
3
+ $rep-brand-color: #4a90e2 !default
4
+ $rep-link-color: $rep-brand-color !default
5
+ $rep-gray: #818a91 !default
6
+ $rep-gray-light: #a6b2bb !default
7
+ $rep-gray-lighter: #f1f3f4 !default
8
+
9
+ $rep-breadcrumb-bg: $rep-gray-lighter !default
10
+
11
+ $rep-grid-gutter: 30px !default
12
+ $rep-grid-breakpoint-sm: 768px !default
13
+ $rep-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif !default
14
+ $rep-font-size-nav: 1.15em !default
15
+ $rep-text-color-secondary: #263238
16
+
17
+ =rep--media-sm-plus
18
+ @media (min-width: $rep-grid-breakpoint-sm)
19
+ @content
20
+
21
+ =clearfix
22
+ &::after
23
+ content: ""
24
+ display: table
25
+ clear: both
26
+
27
+ %rep--link
28
+ color: $rep-link-color
29
+ text-decoration: none
30
+ transition: color 0.1s linear
31
+ &:active, &:focus, &:hover
32
+ color: darken($rep-link-color, 15%)
33
+ &:active
34
+ outline: none
35
+ &:focus
36
+ outline: thin dotted
37
+ outline: 5px auto -webkit-focus-ring-color
38
+ outline-offset: -2px
39
+
40
+ %rep--hr
41
+ margin-top: 20px
42
+ margin-bottom: 20px
43
+ border: 0
44
+ border-top: 1px solid $rep-gray-lighter
45
+
46
+ .rep--main-container
47
+ font-family: $rep-font-family
48
+ box-sizing: border-box
49
+ *, *::before, *::after
50
+ box-sizing: inherit
51
+ a
52
+ @extend %rep--link
53
+ hr
54
+ @extend %rep--hr
55
+
56
+ .rep--row
57
+ margin-left: ($rep-grid-gutter / -2)
58
+ margin-right: ($rep-grid-gutter / -2)
59
+ +clearfix
60
+
61
+ %rep--row__col
62
+ position: relative
63
+ min-height: 1px
64
+ padding-right: ($rep-grid-gutter / 2)
65
+ padding-left: ($rep-grid-gutter / 2)
66
+
67
+ @each $col in (4, 6, 8)
68
+ %rep--row__col-#{$col}
69
+ @extend %rep--row__col
70
+ +rep--media-sm-plus
71
+ float: left
72
+ width: percentage($col / 12)
73
+
74
+ .rep--email-headers
75
+ @extend %rep--row__col-8
76
+
77
+ .rep--email-nav-container
78
+ @extend %rep--row__col-4
79
+
80
+ .rep--email-list-half
81
+ @extend %rep--row__col-6
82
+
83
+ .rep--breadcrumbs
84
+ padding: 0.75rem 1rem
85
+ margin-bottom: 1rem
86
+ font-size: $rep-font-size-nav
87
+ list-style: none
88
+ background-color: $rep-breadcrumb-bg
89
+ .rep--breadcrumbs__breadcrumb
90
+ display: inline-block
91
+ + ::before
92
+ display: inline-block
93
+ padding: 0 0.5em
94
+ color: $rep-gray-light
95
+ content: "/"
96
+ .rep--breadcrumbs__breadcrumb-active
97
+ display: inline-block
98
+
99
+ .rep--headers-list
100
+ margin: 0
101
+ dt
102
+ color: $rep-text-color-secondary
103
+ font-weight: bold
104
+ +rep--media-sm-plus
105
+ float: left
106
+ clear: left
107
+ margin-right: 0.4em
108
+ text-align: right
109
+ width: 4.8em
110
+ dd
111
+ width: auto
112
+ margin-left: 0
113
+ margin-bottom: 0.2em
114
+
115
+ .rep--btn
116
+ appearance: none
117
+ -webkit-font-smoothing: antialiased
118
+ border: 1px solid
119
+ cursor: pointer
120
+ display: inline-block
121
+ font-weight: 600
122
+ padding: 0.75em 1em
123
+ text-decoration: none
124
+ user-select: none
125
+ vertical-align: middle
126
+ text-align: center
127
+ white-space: nowrap
128
+ transition: all .2s ease-in-out
129
+ &:active, &.rep--btn-active
130
+ background-image: none
131
+ outline: 0
132
+ box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125)
133
+ &:focus
134
+ outline: none
135
+
136
+ =rep--btn($color, $background, $border-color: darken($background, 5%))
137
+ color: $color
138
+ background: $background
139
+ border-color: $border-color
140
+ &:hover
141
+ background: darken($background, 10%)
142
+ border-color: darken($border-color, 12%)
143
+ &:focus
144
+ box-shadow: 0 0 3px $background
145
+ background-color: darken($background, 17%)
146
+ border-color: darken($border-color, 25%)
147
+
148
+ .rep--btn-default
149
+ +rep--btn(#111, $rep-gray-lighter)
150
+
151
+ .rep--btn-primary
152
+ +rep--btn(#fff, $rep-brand-color)
153
+
154
+ .rep--btn-danger
155
+ +rep--btn(#fff, #d9534f)
156
+
157
+ .rep--btn-group
158
+ .rep--btn + .rep--btn
159
+ margin-left: -1px
160
+ .rep--btn
161
+ z-index: 1
162
+ &.rep--btn-active
163
+ z-index: 2
164
+ &:focus, &:hover
165
+ z-index: 3
166
+
167
+ .rep--list-group
168
+ font-size: $rep-font-size-nav
169
+
170
+ .rep--list-group__item
171
+ display: block
172
+ padding: 1rem 1.5rem
173
+ &:hover
174
+ background-color: $rep-gray-lighter
175
+ transition: background-color ease-in-out 0.15s, background-color ease-in-out 0.15s
176
+ + .rep--list-group__item
177
+ border-top: 1px solid $rep-gray-light
178
+
179
+ .rep--panel
180
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .125)
181
+ padding: 1.25rem
182
+ margin-bottom: 1rem
183
+
184
+ .rep--email-options
185
+ font-size: 0.875rem
186
+ text-align: left
187
+ p
188
+ margin-top: 0
189
+ +rep--media-sm-plus
190
+ text-align: right
191
+
192
+ .rep--send-to-form
193
+ display: block
194
+ white-space: nowrap
195
+ padding-bottom: 4px
196
+ button, [type="email"]
197
+ display: inline-block
198
+ &:focus, &:active
199
+ z-index: 2
200
+ button
201
+ line-height: 1.25
202
+ padding: 0.5rem
203
+ [type="email"]
204
+ max-width: 135px
205
+ padding: 0.5rem
206
+ border-top-left-radius: 0
207
+ border-bottom-left-radius: 0
208
+
209
+ .rep--form-control
210
+ padding: 0.5rem 0.75rem
211
+ line-height: 1.25
212
+ background-image: none
213
+ background-clip: padding-box
214
+ border: 1px solid rgba(0, 0, 0, 0.15)
215
+ border-radius: 0.25rem
216
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075)
217
+ transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s
218
+ &::placeholder
219
+ color: #999
220
+ opacity: 1
221
+ &:focus
222
+ border-color: lighten($rep-brand-color, 20%)
223
+ outline: none
224
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6)
225
+
226
+ .rep--footer
227
+ text-align: center
228
+ color: $rep-gray
@@ -0,0 +1,68 @@
1
+ // Bootstrap 3 theme for Rails Email Preview
2
+
3
+ .rep--email-headers
4
+ @extend .col-md-8
5
+
6
+ .rep--email-nav-container
7
+ @extend .col-md-4
8
+
9
+ .rep--email-list-half
10
+ @extend .col-md-6
11
+
12
+ .rep--headers-list
13
+ dt
14
+ color: $gray-dark
15
+ @media (min-width: $screen-sm-min)
16
+ float: left
17
+ clear: left
18
+ margin-right: 0.45em
19
+ text-align: right
20
+ width: 100px
21
+ &::after
22
+ content: ":"
23
+ dd
24
+ width: auto
25
+ margin-left: 0
26
+ margin-bottom: 0.3em
27
+
28
+ .rep--email-options
29
+ text-align: right
30
+
31
+ .rep--breadcrumbs
32
+ @extend .breadcrumb
33
+
34
+ .rep--breadcrumbs__breadcrumb-active
35
+ color: $breadcrumb-active-color
36
+
37
+ .rep--panel
38
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .125)
39
+ padding: 15px
40
+ margin-bottom: 20px
41
+
42
+ .rep--send-to-form
43
+ display: block
44
+ white-space: nowrap
45
+ padding-bottom: 4px
46
+ button, [type="email"]
47
+ display: inline-block
48
+ &:focus, &:active
49
+ z-index: 2
50
+ button
51
+ line-height: 1.3
52
+ border-top-right-radius: 0
53
+ border-bottom-right-radius: 0
54
+ [type="email"]
55
+ max-width: 140px
56
+ border-top-left-radius: 0
57
+ border-bottom-left-radius: 0
58
+
59
+ .rep--footer
60
+ text-align: center
61
+ color: $state-info-text
62
+
63
+ .rep--email-headers
64
+ +make-sm-column(8)
65
+ .rep--email-nav-container
66
+ +make-sm-column(4)
67
+ .rep--email-list-half
68
+ +make-sm-column(6)
@@ -5,6 +5,7 @@ module RailsEmailPreview
5
5
  around_filter :set_locale
6
6
  before_filter :set_email_preview_locale
7
7
  helper_method :with_email_locale
8
+ helper_method :preview_params
8
9
 
9
10
  # List of emails
10
11
  def index
@@ -19,7 +20,7 @@ module RailsEmailPreview
19
20
  with_email_locale do
20
21
  if @preview.respond_to?(:preview_mail)
21
22
  @mail, body = mail_and_body
22
- @mail_body_html = render_to_string inline: body, layout: 'rails_email_preview/email'
23
+ @mail_body_html = render_to_string(inline: body, layout: 'rails_email_preview/email')
23
24
  else
24
25
  raise ArgumentError.new("#{@preview} is not a preview class, does not respond_to?(:preview_mail)")
25
26
  end
@@ -47,14 +48,17 @@ module RailsEmailPreview
47
48
 
48
49
  # Download attachment
49
50
  def show_attachment
50
- filename = "#{params[:filename]}.#{params[:format]}"
51
- attachment = preview_mail(false).attachments.find { |a| a.filename == filename }
52
- send_data attachment.body.raw_source, filename: filename
51
+ with_email_locale do
52
+ filename = "#{params[:filename]}.#{params[:format]}"
53
+ attachment = preview_mail(false).attachments.find { |a| a.filename == filename }
54
+ send_data attachment.body.raw_source, filename: filename
55
+ end
53
56
  end
54
57
 
55
58
  # Render headers partial. Used by the CMS integration to refetch headers after editing.
56
59
  def show_headers
57
- render partial: 'rails_email_preview/emails/headers', locals: {mail: mail_and_body.first}
60
+ mail = with_email_locale { mail_and_body.first }
61
+ render partial: 'rails_email_preview/emails/headers', locals: {mail: mail}
58
62
  end
59
63
 
60
64
  # Render email body iframe HTML. Used by the CMS integration to provide a link back to Show from Edit.
@@ -69,6 +73,10 @@ module RailsEmailPreview
69
73
 
70
74
  private
71
75
 
76
+ def preview_params
77
+ params.except(*(request.path_parameters.keys - [:email_locale]))
78
+ end
79
+
72
80
  def deliver_email!(mail)
73
81
  if mail.respond_to?(:deliver_now!)
74
82
  # Rails 4.2+
@@ -92,7 +100,7 @@ module RailsEmailPreview
92
100
  # @param [Boolean] run_handlers whether to run the registered handlers for Mail object
93
101
  # @return [Mail]
94
102
  def preview_mail(run_handlers = true)
95
- @preview.preview_mail(run_handlers, params.except(*request.path_parameters.keys))
103
+ @preview.preview_mail(run_handlers, preview_params)
96
104
  end
97
105
 
98
106
  # @param [Mail] mail
@@ -57,27 +57,14 @@ module RailsEmailPreview::EmailsHelper
57
57
  RailsEmailPreview.style
58
58
  end
59
59
 
60
- def preview_params
61
- params.except(*request.path_parameters.keys)
62
- end
63
-
64
60
  def rep_btn_class(active = false)
65
- rep_style[:"btn_#{active ? 'active' : 'default'}_class"]
66
- end
67
-
68
- def rep_row_class
69
- rep_style[:row_class]
70
- end
71
-
72
- def rep_col_class(n)
73
- rep_style[:column_class] % {n: n}
61
+ [rep_style[:btn_default_class], (rep_style[:btn_active_class_modifier] if active)].compact * ' '
74
62
  end
75
63
 
76
64
  def rep_btn_group_class
77
65
  rep_style[:btn_group_class]
78
66
  end
79
67
 
80
-
81
68
  def with_index_hook(key, &block)
82
69
  render_hook key, list: @list, previews: @previews, &block
83
70
  end