bootstrap-email 0.1.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41ea3f1a13c0322a61e3589da9572f01660d6185
4
- data.tar.gz: de32a08d6572fc2f167c0ee64972e8ff9c941de6
3
+ metadata.gz: 69618ffcd0a9d016bee9c0d8a820786536cd9584
4
+ data.tar.gz: 99ca47bbf429373499754c2a86aca8498ac6be20
5
5
  SHA512:
6
- metadata.gz: 5c8068a990fdfc0b1d004bc4157a18c045cf781f908e34c200a1c50dd242097fd3ae244c85dcef4446b7dcd54cb42416d5b6a4084f02325bc1961f1f82263ab6
7
- data.tar.gz: 1cd15e6a01d3aaf792cfb89bfc4d82309c55f5634d8d44d075599f6532cb4756e3afd0cc33408a4725f881151b962a514e0cad6b8f8a547d2f79c8a4113647e5
6
+ metadata.gz: e721a9c0d97bebbbce04b01206ac34297b4d32a2082b38a643e16d0d46cfd504b7907e6c6e3eb30ab4a987e0c5332f71920b19b317699e1db8c0e4cf4d8ba747
7
+ data.tar.gz: 5ba5af72c7c6d85b52cb4eb984ae5b1831be86e28954fa4e325219658e5d73d9481733796369770f709fa0de16beb022caceb06f681c042da4ff6bf6da8a3151
@@ -8,10 +8,10 @@ require 'rails'
8
8
 
9
9
  module BootstrapEmail
10
10
  class Compiler
11
-
12
11
  def initialize mail
13
12
  @mail = mail
14
- self.update_doc(@mail.body.raw_source)
13
+ @source = mail.html_part || mail
14
+ update_doc(@source.body.raw_source)
15
15
  end
16
16
 
17
17
  def update_doc source
@@ -42,10 +42,10 @@ module BootstrapEmail
42
42
  end
43
43
 
44
44
  def inline_css!
45
- @mail.body = @doc.to_html
45
+ @source.body = @doc.to_html
46
46
  @mail = Premailer::Rails::Hook.perform(@mail)
47
47
  @mail.header[:skip_premailer] = true
48
- self.update_doc(@mail.html_part.body.raw_source)
48
+ update_doc(@mail.html_part.body.raw_source)
49
49
  end
50
50
 
51
51
  def inject_head!
@@ -81,19 +81,19 @@ module BootstrapEmail
81
81
 
82
82
  def button
83
83
  each_node('.btn') do |node| # move all classes up and remove all classes from the element
84
- node.replace(template('table', {classes: node['class'], contents: node.delete('class') && node.to_html}))
84
+ node.replace(template('table', classes: node['class'], contents: node.delete('class') && node.to_html))
85
85
  end
86
86
  end
87
87
 
88
88
  def badge
89
89
  each_node('.badge') do |node| # move all classes up and remove all classes from the element
90
- node.replace(template('table-left', {classes: node['class'], contents: node.delete('class') && node.to_html}))
90
+ node.replace(template('table-left', classes: node['class'], contents: node.delete('class') && node.to_html))
91
91
  end
92
92
  end
93
93
 
94
94
  def alert
95
95
  each_node('.alert') do |node| # move all classes up and remove all classes from the element
96
- node.replace(template('table', {classes: node['class'], contents: node.delete('class') && node.to_html}))
96
+ node.replace(template('table', classes: node['class'], contents: node.delete('class') && node.to_html))
97
97
  end
98
98
  end
99
99
 
@@ -112,7 +112,7 @@ module BootstrapEmail
112
112
  def align_helper node, klass, template
113
113
  if node.name != 'table' # if it is already on a table, set the proprieties on the current table
114
114
  node['class'] = node['class'].sub(klass, '')
115
- node.replace(template("align-#{template}", {contents: node.to_html}))
115
+ node.replace(template("align-#{template}", contents: node.to_html))
116
116
  else
117
117
  node['align'] = template
118
118
  end
@@ -120,34 +120,34 @@ module BootstrapEmail
120
120
 
121
121
  def card
122
122
  each_node('.card') do |node| # move all classes up and remove all classes from element
123
- node.replace(template('table', {classes: node['class'], contents: node.delete('class') && node.to_html}))
123
+ node.replace(template('table', classes: node['class'], contents: node.delete('class') && node.to_html))
124
124
  end
125
125
  each_node('.card-body') do |node| # move all classes up and remove all classes from element
126
- node.replace(template('table', {classes: node['class'], contents: node.delete('class') && node.to_html}))
126
+ node.replace(template('table', classes: node['class'], contents: node.delete('class') && node.to_html))
127
127
  end
128
128
  end
129
129
 
130
130
  def hr
131
131
  each_node('hr') do |node| # drop hr in place of current
132
- node.replace(template('hr', {classes: "hr #{node['class']}"}))
132
+ node.replace(template('hr', classes: "hr #{node['class']}"))
133
133
  end
134
134
  end
135
135
 
136
136
  def container
137
137
  each_node('.container') do |node|
138
- node.replace(template('container', {classes: node['class'], contents: node.inner_html}))
138
+ node.replace(template('container', classes: node['class'], contents: node.inner_html))
139
139
  end
140
140
  each_node('.container-fluid') do |node|
141
- node.replace(template('table', {classes: node['class'], contents: node.inner_html}))
141
+ node.replace(template('table', classes: node['class'], contents: node.inner_html))
142
142
  end
143
143
  end
144
144
 
145
145
  def grid
146
146
  each_node('.row') do |node|
147
- node.replace(template('row', {classes: node['class'], contents: node.inner_html}))
147
+ node.replace(template('row', classes: node['class'], contents: node.inner_html))
148
148
  end
149
149
  each_node('*[class*=col]') do |node|
150
- node.replace(template('col', {classes: node['class'], contents: node.inner_html}))
150
+ node.replace(template('col', classes: node['class'], contents: node.inner_html))
151
151
  end
152
152
  end
153
153
 
@@ -157,7 +157,7 @@ module BootstrapEmail
157
157
  padding_regex = /(p[trblxy]?-\d)/
158
158
  classes = node['class'].scan(padding_regex).join(' ')
159
159
  node['class'] = node['class'].gsub(padding_regex, '')
160
- node.replace(template('table', {classes: classes, contents: node.to_html}))
160
+ node.replace(template('table', classes: classes, contents: node.to_html))
161
161
  end
162
162
  end
163
163
  end
@@ -169,11 +169,11 @@ module BootstrapEmail
169
169
  node['class'] = node['class'].gsub(/(m[tby]{1}-(lg-)?\d)/, '')
170
170
  html = ''
171
171
  if top_class
172
- html += template('div', {classes: "s-#{top_class.gsub(/m[ty]{1}-/, '')}", contents: nil})
172
+ html += template('div', classes: "s-#{top_class.gsub(/m[ty]{1}-/, '')}", contents: nil)
173
173
  end
174
174
  html += node.to_html
175
175
  if bottom_class
176
- html += template('div', {classes: "s-#{bottom_class.gsub(/m[by]{1}-/, '')}", contents: nil})
176
+ html += template('div', classes: "s-#{bottom_class.gsub(/m[by]{1}-/, '')}", contents: nil)
177
177
  end
178
178
  node.replace(html)
179
179
  end
@@ -189,7 +189,7 @@ module BootstrapEmail
189
189
  '5' => (16 * 3)
190
190
  }
191
191
  each_node('*[class*=s-]') do |node|
192
- temp = Nokogiri::HTML::DocumentFragment.parse(template('table', {classes: node['class'] + ' w-100', contents: " "}))
192
+ temp = Nokogiri::HTML::DocumentFragment.parse(template('table', classes: node['class'] + ' w-100', contents: ' '))
193
193
  temp.at_css('td')['height'] = spacers[node['class'].gsub(/s-/, '')].to_i
194
194
  node.replace(temp)
195
195
  end
@@ -197,7 +197,7 @@ module BootstrapEmail
197
197
 
198
198
  def table
199
199
  @doc.css('table').each do |node|
200
- #border="0" cellpadding="0" cellspacing="0"
200
+ # border="0" cellpadding="0" cellspacing="0"
201
201
  node['border'] = 0
202
202
  node['cellpadding'] = 0
203
203
  node['cellspacing'] = 0
@@ -206,7 +206,7 @@ module BootstrapEmail
206
206
 
207
207
  def body
208
208
  @doc.css('body').each do |node|
209
- node.replace( '<body>' + preview_text.to_s + template('table', {classes: "#{node['class']} body", contents: "#{node.inner_html}"}) + '</body>' )
209
+ node.replace('<body>' + preview_text.to_s + template('body', classes: "#{node['class']} body", contents: node.inner_html.to_s) + '</body>')
210
210
  end
211
211
  end
212
212
 
@@ -214,13 +214,12 @@ module BootstrapEmail
214
214
  preview_node = @doc.at_css('preview')
215
215
  if preview_node.present?
216
216
  # apply spacing after the text max of 100 characters so it doesn't show body text
217
- preview_node.content += "&nbsp;" * (100 - preview_node.content.length.to_i)
218
- node = template('div', {classes: 'preview', contents: preview_node.content})
217
+ preview_node.content += '&nbsp;' * (100 - preview_node.content.length.to_i)
218
+ node = template('div', classes: 'preview', contents: preview_node.content)
219
219
  preview_node.remove
220
220
  return node
221
221
  end
222
222
  end
223
-
224
223
  end
225
224
  end
226
225
 
@@ -5,4 +5,9 @@ class ActionMailer::Base
5
5
  bootstrap = BootstrapEmail::Compiler.new(mail(*args) { |format| format.html { render layout: 'layouts/bootstrap-mailer.html.erb' } } )
6
6
  bootstrap.perform_full_compile
7
7
  end
8
+
9
+ def make_bootstrap_mail *args, &block
10
+ bootstrap = BootstrapEmail::Compiler.new(mail(*args, &block))
11
+ bootstrap.perform_full_compile
12
+ end
8
13
  end
@@ -0,0 +1,5 @@
1
+ class PremailerRailtie < Rails::Railtie
2
+ initializer 'premailer_railtie.configure_rails_initialization' do
3
+ Premailer::Rails.config.merge!(adapter: :nokogiri, preserve_reset: false, output_encoding: 'UTF-8')
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Yamartino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-14 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: premailer-rails
@@ -87,8 +87,9 @@ files:
87
87
  - lib/bootstrap-email.rb
88
88
  - lib/bootstrap-email/action_mailer.rb
89
89
  - lib/bootstrap-email/engine.rb
90
+ - lib/bootstrap-email/premailer_railtie.rb
90
91
  - lib/bootstrap-email/version.rb
91
- homepage: https://github.com/stuyam/bootstrap-email
92
+ homepage: https://bootstrapemail.com
92
93
  licenses:
93
94
  - MIT
94
95
  metadata: {}