rails_email_preview 2.1.0 → 2.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
  SHA256:
3
- metadata.gz: e22e1348c59f3f6a444e25518c42514a9bccd2a333fa0afcb16329ebef234a37
4
- data.tar.gz: 80e80c700d50247becc34c2c66e04ed3ec2107ccd97ffb70280726a6f7de2c82
3
+ metadata.gz: c4b2792359dab619a4a3d002e0e988589d22f608e4fe03e91781203179ed8bce
4
+ data.tar.gz: b95c10950a144e7974fc80c38707aa1b257f4683dd1c45732d7e43c8c63ef9f2
5
5
  SHA512:
6
- metadata.gz: 33e4f34d7576808b4bf4d00984b7514c15e41bca036a1f77f47947ba548643ce2198068bd1fca1bfbf0a9c6abf5265b00ddae43180bcd4514ba3caafb10dd880
7
- data.tar.gz: 066b971beadb78d38bf0019dda18716a7405d5fa84bd3a587f3c545adb3a3bce3c587ec93934028754321a72472f6407d142dd9fabaab84e6c5ffb955d671e3a
6
+ metadata.gz: 8427304dba19af417e56d27a538e11e7fc91e6e0f03f2edd26ce3efe5c44109d2067512e0faa7715cf4adbae7f19e8d2e6a8ccbbf5242204f7c0cf3a601af44f
7
+ data.tar.gz: 7a2b96a6aa5010ff8b24aec87f6cdf54cc69eaa0cf4324ecd123b3157fd42ca3ea296a025383cd82b77876159618d738ce7786a241726d131061daac2398f003
data/README.md CHANGED
@@ -17,7 +17,7 @@ REP comes with two themes: a simple standalone theme, and a theme that uses [Boo
17
17
  Add [![Gem Version][gem-badge]][gem] to Gemfile:
18
18
 
19
19
  ```ruby
20
- gem 'rails_email_preview', '~> 2.1.0'
20
+ gem 'rails_email_preview', '~> 2.2.0'
21
21
  ```
22
22
 
23
23
  Add an initializer and the routes:
@@ -1,4 +1,5 @@
1
1
  // Bootstrap 3 theme for Rails Email Preview
2
+ @import "rails_email_preview/iframe"
2
3
 
3
4
  .rep--email-headers
4
5
  @extend .col-md-8
@@ -1,4 +1,5 @@
1
1
  // A standalone theme for Rails Email Preview
2
+ @import "rails_email_preview/iframe"
2
3
 
3
4
  $rep-brand-color: #4a90e2 !default
4
5
  $rep-link-color: $rep-brand-color !default
@@ -0,0 +1,15 @@
1
+ #rep-src-iframe-container {
2
+ min-height: 450px;
3
+ position: relative;
4
+ > .progress-bar {
5
+ width: 100%;
6
+ }
7
+ }
8
+
9
+ #rep-src-iframe {
10
+ width: 100%;
11
+ border: none;
12
+ padding: 0;
13
+ margin: 0;
14
+ height: 0;
15
+ }
@@ -14,8 +14,10 @@
14
14
  data-view-link-label="<%= t '.view_link' %>"
15
15
  data-edit-email-label="<%= t '.edit_email'%>"></div>
16
16
  <% if adapter.cms_v2_plus? %>
17
- <script><%= render file: 'integrations/cms/comfy_v2_integration.js' %></script>
17
+ <%= javascript_tag render(file: 'integrations/cms/comfy_v2_integration.js'),
18
+ **({nonce: true} if RailsEmailPreview.rails_supports_csp_nonce?) %>
18
19
  <% else # CMS v1 %>
19
- <script><%= render file: 'integrations/cms/comfy_v1_integration.js' %></script>
20
+ <%= javascript_tag render(file: 'integrations/cms/comfy_v1_integration.js'),
21
+ **({nonce: true} if RailsEmailPreview.rails_supports_csp_nonce?) %>
20
22
  <% end %>
21
23
  <% end %>
@@ -2,8 +2,11 @@
2
2
  <html>
3
3
  <head>
4
4
  <title><%= t('.head_title') %></title>
5
- <%= stylesheet_link_tag 'rails_email_preview/application' %>
6
- <%= javascript_include_tag 'rails_email_preview/application' %>
5
+ <%= stylesheet_link_tag 'rails_email_preview/application', 'data-turbolinks-track': 'reload' %>
6
+ <%= csrf_meta_tag %>
7
+ <%= csp_meta_tag if RailsEmailPreview.rails_supports_csp_nonce? %>
8
+ <%= javascript_include_tag 'rails_email_preview/application',
9
+ 'data-turbolinks-track': 'reload' %>
7
10
  <%= favicon_link_tag 'rails_email_preview/favicon.png' %>
8
11
  <%= yield(:head) %>
9
12
  </head>
@@ -21,7 +21,9 @@
21
21
  background-color: white;
22
22
  }
23
23
  </style>
24
- <script>document.addEventListener('DOMContentLoaded', window.parent.rep.iframeOnDOMContentLoaded, true);</script>
24
+ <%= javascript_tag **({nonce: true} if RailsEmailPreview.rails_supports_csp_nonce?) do %>
25
+ document.addEventListener('DOMContentLoaded', window.parent.rep.iframeOnDOMContentLoaded, true);
26
+ <% end %>
25
27
  </head>
26
28
  <body>
27
29
  <div id="content" class="container">
@@ -1,88 +1,12 @@
1
- <script>
2
- (function (doc) {
3
- var rep = window['rep'] || (window['rep'] = { resizeAttached: false });
4
- rep.loaded = false;
5
-
6
- function findIframe() {
7
- return doc.getElementById('src-iframe');
8
- }
9
-
10
- function resizeIframe() {
11
- var el = findIframe();
12
- if (!el) {
13
- rep.loaded = false;
14
- return;
15
- }
16
- var iframeBody = el.contentWindow.document.body;
17
- if (iframeBody) {
18
- el.style.height = (getBodyHeight(iframeBody)) + "px";
19
- }
20
- }
21
-
22
- function getBodyHeight(body) {
23
- var boundingRect = body.getBoundingClientRect();
24
- var style = body.ownerDocument.defaultView.getComputedStyle(body);
25
- var marginY = parseInt(style['margin-bottom'], 10) +
26
- parseInt(style['margin-top'], 10);
27
- // There may be a horizontal scrollbar adding to the height.
28
- var scrollbarHeight = 17;
29
- return scrollbarHeight + marginY + Math.max(
30
- body.scrollHeight, body.offsetHeight, body.clientHeight,
31
- boundingRect.height + boundingRect.top) +
32
- // no idea why these 4px are needed:
33
- 4;
34
- }
35
-
36
- function fetchHeaders() {
37
- var headersView = doc.getElementById('email-headers'),
38
- xhr = new XMLHttpRequest();
39
- xhr.open('GET', headersView.getAttribute('data-url'), true);
40
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
41
- xhr.send(null);
42
- xhr.onreadystatechange = function () {
43
- if (xhr.readyState === 4) {
44
- headersView.innerHTML = xhr.responseText;
45
- }
46
- }
47
- }
48
-
49
- // Called from the iframe via window.parent
50
- rep.iframeOnDOMContentLoaded = function () {
51
- rep.loaded = true;
52
- resizeIframe();
53
- // CMS refresh headers hook
54
- if (rep.fetchHeadersOnNextLoad) {
55
- rep.fetchHeadersOnNextLoad = false;
56
- fetchHeaders();
57
- }
58
- };
59
-
60
- // This is only called back once the iframe has finished loading everything, including images
61
- rep.iframeOnLoad = resizeIframe;
62
-
63
- // Resize on window resize
64
- if (!rep.resizeAttached) {
65
- window.addEventListener('resize', function () {
66
- if (rep.loaded) resizeIframe();
67
- }, true);
68
- rep.resizeAttached = true
69
- }
70
-
71
- // Only show progress bar after some time to avoid flashing
72
- setTimeout(function () {
73
- doc.getElementById('email-progress-bar').style.display = 'block';
74
- }, 350);
75
- })(document);
76
- </script>
77
-
78
- <div style="min-height: 450px; position: relative">
1
+ <div id="rep-src-iframe-container">
79
2
  <div id="email-progress-bar" class="progress"
80
3
  style="display: none; position: absolute; z-index: -1; width: 100%; text-align: center">
81
- <div class="progress-bar progress-bar-striped active" style='width:100%'>
4
+ <div class="progress-bar progress-bar-striped active">
82
5
  <%= t 'rep.base.loading' %>
83
6
  </div>
84
7
  </div>
85
8
 
86
- <iframe id="src-iframe" srcdoc="<%= @mail_body_html.to_str %>" seamless="seamless" onload="rep.iframeOnLoad()"
87
- style="width:100%;border:none;padding:0;margin:0;height:0"></iframe>
9
+ <iframe id="rep-src-iframe" srcdoc="<%= @mail_body_html.to_str %>" seamless="seamless"></iframe>
10
+ <%= javascript_tag render(file: 'rails_email_preview/emails/email_iframe.js'),
11
+ **({nonce: true} if RailsEmailPreview.rails_supports_csp_nonce?) %>
88
12
  </div>
@@ -0,0 +1,77 @@
1
+ (function (doc) {
2
+ var rep = window['rep'] || (window['rep'] = { resizeAttached: false });
3
+ rep.loaded = false;
4
+
5
+ function findIframe() {
6
+ return doc.getElementById('rep-src-iframe');
7
+ }
8
+
9
+ function resizeIframe() {
10
+ var el = findIframe();
11
+ if (!el) {
12
+ rep.loaded = false;
13
+ return;
14
+ }
15
+ var iframeBody = el.contentWindow.document.body;
16
+ if (iframeBody) {
17
+ el.style.height = (getBodyHeight(iframeBody)) + "px";
18
+ }
19
+ }
20
+
21
+ function getBodyHeight(body) {
22
+ var boundingRect = body.getBoundingClientRect();
23
+ var style = body.ownerDocument.defaultView.getComputedStyle(body);
24
+ var marginY = parseInt(style['margin-bottom'], 10) +
25
+ parseInt(style['margin-top'], 10);
26
+ // There may be a horizontal scrollbar adding to the height.
27
+ var scrollbarHeight = 17;
28
+ return scrollbarHeight + marginY + Math.max(
29
+ body.scrollHeight, body.offsetHeight, body.clientHeight,
30
+ boundingRect.height + boundingRect.top) +
31
+ // no idea why these 4px are needed:
32
+ 4;
33
+ }
34
+
35
+ function fetchHeaders() {
36
+ var headersView = doc.getElementById('email-headers'),
37
+ xhr = new XMLHttpRequest();
38
+ xhr.open('GET', headersView.getAttribute('data-url'), true);
39
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
40
+ xhr.send(null);
41
+ xhr.onreadystatechange = function () {
42
+ if (xhr.readyState === 4) {
43
+ headersView.innerHTML = xhr.responseText;
44
+ }
45
+ }
46
+ }
47
+
48
+ // Called from the iframe via window.parent
49
+ rep.iframeOnDOMContentLoaded = function () {
50
+ rep.loaded = true;
51
+ resizeIframe();
52
+ // CMS refresh headers hook
53
+ if (rep.fetchHeadersOnNextLoad) {
54
+ rep.fetchHeadersOnNextLoad = false;
55
+ fetchHeaders();
56
+ }
57
+ };
58
+
59
+ // This is only called back once the iframe has finished loading everything, including images
60
+ rep.iframeOnLoad = resizeIframe;
61
+
62
+ // Resize on window resize
63
+ if (!rep.resizeAttached) {
64
+ window.addEventListener('resize', function () {
65
+ if (rep.loaded) resizeIframe();
66
+ }, true);
67
+ rep.resizeAttached = true
68
+ }
69
+
70
+ // Only show progress bar after some time to avoid flashing
71
+ setTimeout(function () {
72
+ doc.getElementById('email-progress-bar').style.display = 'block';
73
+ }, 350);
74
+
75
+ findIframe().addEventListener('load', resizeIframe);
76
+ resizeIframe();
77
+ })(document);
@@ -85,6 +85,12 @@ module RailsEmailPreview
85
85
  def setup
86
86
  yield self
87
87
  end
88
+
89
+ # @api private
90
+ def rails_supports_csp_nonce?
91
+ @rails_supports_csp_nonce = (Rails.gem_version >= Gem::Version.new('5.2.0')) if @rails_supports_csp_nonce.nil?
92
+ @rails_supports_csp_nonce
93
+ end
88
94
  end
89
95
 
90
96
  # = Editing settings
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '2.1.0'
2
+ VERSION = '2.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: 2.1.0
4
+ version: 2.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: 2018-11-08 00:00:00.000000000 Z
11
+ date: 2019-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -150,6 +150,7 @@ files:
150
150
  - app/assets/javascripts/rails_email_preview/application.js
151
151
  - app/assets/stylesheets/rails_email_preview/_bootstrap3.sass
152
152
  - app/assets/stylesheets/rails_email_preview/_default.sass
153
+ - app/assets/stylesheets/rails_email_preview/_iframe.scss
153
154
  - app/assets/stylesheets/rails_email_preview/application.scss
154
155
  - app/controllers/rails_email_preview/application_controller.rb
155
156
  - app/controllers/rails_email_preview/emails_controller.rb
@@ -169,6 +170,7 @@ files:
169
170
  - app/views/rails_email_preview/emails/_i18n_nav.html.erb
170
171
  - app/views/rails_email_preview/emails/_nav.html.erb
171
172
  - app/views/rails_email_preview/emails/_send_form.html.erb
173
+ - app/views/rails_email_preview/emails/email_iframe.js
172
174
  - app/views/rails_email_preview/emails/index.html.erb
173
175
  - app/views/rails_email_preview/emails/show.html.erb
174
176
  - config/i18n-tasks.yml
@@ -207,8 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
209
  - !ruby/object:Gem::Version
208
210
  version: '0'
209
211
  requirements: []
210
- rubyforge_project:
211
- rubygems_version: 2.7.7
212
+ rubygems_version: 3.0.2
212
213
  signing_key:
213
214
  specification_version: 4
214
215
  summary: Preview emails in browser (rails engine)