email_stylist 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 +7 -0
- data/.editorconfig +6 -0
- data/.github/workflows/ci.yml +36 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +6 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +244 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/Rakefile +12 -0
- data/email_stylist.gemspec +28 -0
- data/lib/email_stylist/styled_erb_template.rb +114 -0
- data/lib/email_stylist/version.rb +7 -0
- data/lib/email_stylist.rb +4 -0
- metadata +83 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4a7dbc9ec3839af59fa380ebf99de6823ccb7a7f07744c64ee0f263a241b3185
|
|
4
|
+
data.tar.gz: a34457684d2d8fbace05babc07d0accccf184347a516af56657e6b0945a26a4c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 87ad996ca3c16a2294a84de2ec0a0fa18090862d498c8963cd1996c00302a18f5d6bffe74ed1d524bfa565cf28ec800df17213b3b19e53f926f92b900aacbdbc
|
|
7
|
+
data.tar.gz: 1238d1d52d270bfa5d2bda9ffe5ea55596baa6926589e4c4d662bab159b5ad84b44cce5920dbed8497da9c8ce4c2a331d024ecdf83d703e16796208729af6c72
|
data/.editorconfig
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Email Stylist Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
name: Ruby ${{ matrix.ruby }}
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
ruby: ["2.7"]
|
|
16
|
+
experimental: [false]
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v2
|
|
19
|
+
- uses: ruby/setup-ruby@v1
|
|
20
|
+
with:
|
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
|
22
|
+
- name: Bundler cache
|
|
23
|
+
uses: actions/cache@v2
|
|
24
|
+
with:
|
|
25
|
+
path: vendor/bundle
|
|
26
|
+
key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
|
27
|
+
restore-keys: |
|
|
28
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-
|
|
29
|
+
- name: Setup gems
|
|
30
|
+
run: |
|
|
31
|
+
bundle config path vendor/bundle
|
|
32
|
+
bundle install --jobs 4
|
|
33
|
+
- name: Tests
|
|
34
|
+
run: bundle exec rspec -f d
|
|
35
|
+
- name: Rubocop
|
|
36
|
+
run: bundle exec rubocop
|
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in tracer_client.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
gem 'combustion', '~> 1.3'
|
|
9
|
+
gem 'pry', '~> 0.12'
|
|
10
|
+
gem 'rake', '~> 13.0'
|
|
11
|
+
gem 'rspec', '~> 3.9'
|
|
12
|
+
gem 'rspec-rails', '~> 3.9'
|
|
13
|
+
gem 'rubocop-gp', github: 'corp-gp/rubocop-gp'
|
|
14
|
+
gem 'tilt'
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
GIT
|
|
2
|
+
remote: https://github.com/corp-gp/rubocop-gp.git
|
|
3
|
+
revision: e3d33016bb3b9945ce9d8d22e77825a223de1a5c
|
|
4
|
+
specs:
|
|
5
|
+
rubocop-gp (0.0.4)
|
|
6
|
+
rubocop
|
|
7
|
+
rubocop-capybara
|
|
8
|
+
rubocop-factory_bot
|
|
9
|
+
rubocop-performance
|
|
10
|
+
rubocop-rails
|
|
11
|
+
rubocop-rspec
|
|
12
|
+
rubocop-rspec_rails
|
|
13
|
+
|
|
14
|
+
PATH
|
|
15
|
+
remote: .
|
|
16
|
+
specs:
|
|
17
|
+
email_stylist (0.2.1)
|
|
18
|
+
inky-rb
|
|
19
|
+
premailer
|
|
20
|
+
|
|
21
|
+
GEM
|
|
22
|
+
remote: https://rubygems.org/
|
|
23
|
+
specs:
|
|
24
|
+
actionpack (8.1.3)
|
|
25
|
+
actionview (= 8.1.3)
|
|
26
|
+
activesupport (= 8.1.3)
|
|
27
|
+
nokogiri (>= 1.8.5)
|
|
28
|
+
rack (>= 2.2.4)
|
|
29
|
+
rack-session (>= 1.0.1)
|
|
30
|
+
rack-test (>= 0.6.3)
|
|
31
|
+
rails-dom-testing (~> 2.2)
|
|
32
|
+
rails-html-sanitizer (~> 1.6)
|
|
33
|
+
useragent (~> 0.16)
|
|
34
|
+
actionview (8.1.3)
|
|
35
|
+
activesupport (= 8.1.3)
|
|
36
|
+
builder (~> 3.1)
|
|
37
|
+
erubi (~> 1.11)
|
|
38
|
+
rails-dom-testing (~> 2.2)
|
|
39
|
+
rails-html-sanitizer (~> 1.6)
|
|
40
|
+
activesupport (8.1.3)
|
|
41
|
+
base64
|
|
42
|
+
bigdecimal
|
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
44
|
+
connection_pool (>= 2.2.5)
|
|
45
|
+
drb
|
|
46
|
+
i18n (>= 1.6, < 2)
|
|
47
|
+
json
|
|
48
|
+
logger (>= 1.4.2)
|
|
49
|
+
minitest (>= 5.1)
|
|
50
|
+
securerandom (>= 0.3)
|
|
51
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
52
|
+
uri (>= 0.13.1)
|
|
53
|
+
addressable (2.9.0)
|
|
54
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
55
|
+
ast (2.4.3)
|
|
56
|
+
base64 (0.3.0)
|
|
57
|
+
bigdecimal (4.1.2)
|
|
58
|
+
builder (3.3.0)
|
|
59
|
+
coderay (1.1.3)
|
|
60
|
+
combustion (1.5.0)
|
|
61
|
+
activesupport (>= 3.0.0)
|
|
62
|
+
railties (>= 3.0.0)
|
|
63
|
+
thor (>= 0.14.6)
|
|
64
|
+
concurrent-ruby (1.3.7)
|
|
65
|
+
connection_pool (3.0.2)
|
|
66
|
+
crass (1.0.7)
|
|
67
|
+
css_parser (3.0.0)
|
|
68
|
+
addressable
|
|
69
|
+
ssrf_filter (~> 1.5)
|
|
70
|
+
diff-lcs (1.6.2)
|
|
71
|
+
drb (2.2.3)
|
|
72
|
+
erb (6.0.4)
|
|
73
|
+
erubi (1.13.1)
|
|
74
|
+
foundation_emails (2.2.1.0)
|
|
75
|
+
htmlentities (4.4.2)
|
|
76
|
+
i18n (1.15.2)
|
|
77
|
+
concurrent-ruby (~> 1.0)
|
|
78
|
+
inky-rb (1.4.2.1)
|
|
79
|
+
foundation_emails (~> 2)
|
|
80
|
+
nokogiri
|
|
81
|
+
io-console (0.8.2)
|
|
82
|
+
irb (1.18.0)
|
|
83
|
+
pp (>= 0.6.0)
|
|
84
|
+
prism (>= 1.3.0)
|
|
85
|
+
rdoc (>= 4.0.0)
|
|
86
|
+
reline (>= 0.4.2)
|
|
87
|
+
json (2.20.0)
|
|
88
|
+
language_server-protocol (3.17.0.6)
|
|
89
|
+
lint_roller (1.1.0)
|
|
90
|
+
logger (1.7.0)
|
|
91
|
+
loofah (2.25.1)
|
|
92
|
+
crass (~> 1.0.2)
|
|
93
|
+
nokogiri (>= 1.12.0)
|
|
94
|
+
method_source (1.1.0)
|
|
95
|
+
minitest (6.0.6)
|
|
96
|
+
drb (~> 2.0)
|
|
97
|
+
prism (~> 1.5)
|
|
98
|
+
nokogiri (1.19.4-arm64-darwin)
|
|
99
|
+
racc (~> 1.4)
|
|
100
|
+
parallel (2.1.0)
|
|
101
|
+
parser (3.3.11.1)
|
|
102
|
+
ast (~> 2.4.1)
|
|
103
|
+
racc
|
|
104
|
+
pp (0.6.4)
|
|
105
|
+
prettyprint
|
|
106
|
+
premailer (1.29.0)
|
|
107
|
+
addressable
|
|
108
|
+
css_parser (>= 1.19.0)
|
|
109
|
+
htmlentities (>= 4.0.0)
|
|
110
|
+
prettyprint (0.2.0)
|
|
111
|
+
prism (1.9.0)
|
|
112
|
+
pry (0.16.0)
|
|
113
|
+
coderay (~> 1.1)
|
|
114
|
+
method_source (~> 1.0)
|
|
115
|
+
reline (>= 0.6.0)
|
|
116
|
+
public_suffix (7.0.5)
|
|
117
|
+
racc (1.8.1)
|
|
118
|
+
rack (3.2.6)
|
|
119
|
+
rack-session (2.1.2)
|
|
120
|
+
base64 (>= 0.1.0)
|
|
121
|
+
rack (>= 3.0.0)
|
|
122
|
+
rack-test (2.2.0)
|
|
123
|
+
rack (>= 1.3)
|
|
124
|
+
rackup (2.3.1)
|
|
125
|
+
rack (>= 3)
|
|
126
|
+
rails-dom-testing (2.3.0)
|
|
127
|
+
activesupport (>= 5.0.0)
|
|
128
|
+
minitest
|
|
129
|
+
nokogiri (>= 1.6)
|
|
130
|
+
rails-html-sanitizer (1.7.0)
|
|
131
|
+
loofah (~> 2.25)
|
|
132
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
133
|
+
railties (8.1.3)
|
|
134
|
+
actionpack (= 8.1.3)
|
|
135
|
+
activesupport (= 8.1.3)
|
|
136
|
+
irb (~> 1.13)
|
|
137
|
+
rackup (>= 1.0.0)
|
|
138
|
+
rake (>= 12.2)
|
|
139
|
+
thor (~> 1.0, >= 1.2.2)
|
|
140
|
+
tsort (>= 0.2)
|
|
141
|
+
zeitwerk (~> 2.6)
|
|
142
|
+
rainbow (3.1.1)
|
|
143
|
+
rake (13.4.2)
|
|
144
|
+
rbs (4.0.3)
|
|
145
|
+
logger
|
|
146
|
+
prism (>= 1.6.0)
|
|
147
|
+
tsort
|
|
148
|
+
rdoc (8.0.0)
|
|
149
|
+
erb
|
|
150
|
+
prism (>= 1.6.0)
|
|
151
|
+
rbs (>= 4.0.0)
|
|
152
|
+
tsort
|
|
153
|
+
regexp_parser (2.12.0)
|
|
154
|
+
reline (0.6.3)
|
|
155
|
+
io-console (~> 0.5)
|
|
156
|
+
rspec (3.9.0)
|
|
157
|
+
rspec-core (~> 3.9.0)
|
|
158
|
+
rspec-expectations (~> 3.9.0)
|
|
159
|
+
rspec-mocks (~> 3.9.0)
|
|
160
|
+
rspec-core (3.9.3)
|
|
161
|
+
rspec-support (~> 3.9.3)
|
|
162
|
+
rspec-expectations (3.9.4)
|
|
163
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
164
|
+
rspec-support (~> 3.9.0)
|
|
165
|
+
rspec-mocks (3.9.1)
|
|
166
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
167
|
+
rspec-support (~> 3.9.0)
|
|
168
|
+
rspec-rails (3.9.1)
|
|
169
|
+
actionpack (>= 3.0)
|
|
170
|
+
activesupport (>= 3.0)
|
|
171
|
+
railties (>= 3.0)
|
|
172
|
+
rspec-core (~> 3.9.0)
|
|
173
|
+
rspec-expectations (~> 3.9.0)
|
|
174
|
+
rspec-mocks (~> 3.9.0)
|
|
175
|
+
rspec-support (~> 3.9.0)
|
|
176
|
+
rspec-support (3.9.4)
|
|
177
|
+
rubocop (1.88.1)
|
|
178
|
+
json (~> 2.3)
|
|
179
|
+
language_server-protocol (~> 3.17.0.2)
|
|
180
|
+
lint_roller (~> 1.1.0)
|
|
181
|
+
parallel (>= 1.10)
|
|
182
|
+
parser (>= 3.3.0.2)
|
|
183
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
184
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
185
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
186
|
+
ruby-progressbar (~> 1.7)
|
|
187
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
188
|
+
rubocop-ast (1.50.0)
|
|
189
|
+
parser (>= 3.3.7.2)
|
|
190
|
+
prism (~> 1.7)
|
|
191
|
+
rubocop-capybara (3.0.0)
|
|
192
|
+
lint_roller (~> 1.1)
|
|
193
|
+
rubocop (~> 1.81)
|
|
194
|
+
rubocop-factory_bot (2.28.0)
|
|
195
|
+
lint_roller (~> 1.1)
|
|
196
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
197
|
+
rubocop-performance (1.26.1)
|
|
198
|
+
lint_roller (~> 1.1)
|
|
199
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
200
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
201
|
+
rubocop-rails (2.35.5)
|
|
202
|
+
activesupport (>= 4.2.0)
|
|
203
|
+
lint_roller (~> 1.1)
|
|
204
|
+
rack (>= 1.1)
|
|
205
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
206
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
|
207
|
+
rubocop-rspec (3.10.2)
|
|
208
|
+
lint_roller (~> 1.1)
|
|
209
|
+
regexp_parser (>= 2.0)
|
|
210
|
+
rubocop (~> 1.86, >= 1.86.2)
|
|
211
|
+
rubocop-rspec_rails (2.32.0)
|
|
212
|
+
lint_roller (~> 1.1)
|
|
213
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
214
|
+
rubocop-rspec (~> 3.5)
|
|
215
|
+
ruby-progressbar (1.13.0)
|
|
216
|
+
securerandom (0.4.1)
|
|
217
|
+
ssrf_filter (1.5.0)
|
|
218
|
+
thor (1.5.0)
|
|
219
|
+
tilt (2.7.0)
|
|
220
|
+
tsort (0.2.0)
|
|
221
|
+
tzinfo (2.0.6)
|
|
222
|
+
concurrent-ruby (~> 1.0)
|
|
223
|
+
unicode-display_width (3.2.0)
|
|
224
|
+
unicode-emoji (~> 4.1)
|
|
225
|
+
unicode-emoji (4.2.0)
|
|
226
|
+
uri (1.1.1)
|
|
227
|
+
useragent (0.16.11)
|
|
228
|
+
zeitwerk (2.8.2)
|
|
229
|
+
|
|
230
|
+
PLATFORMS
|
|
231
|
+
arm64-darwin-24
|
|
232
|
+
|
|
233
|
+
DEPENDENCIES
|
|
234
|
+
combustion (~> 1.3)
|
|
235
|
+
email_stylist!
|
|
236
|
+
pry (~> 0.12)
|
|
237
|
+
rake (~> 13.0)
|
|
238
|
+
rspec (~> 3.9)
|
|
239
|
+
rspec-rails (~> 3.9)
|
|
240
|
+
rubocop-gp!
|
|
241
|
+
tilt
|
|
242
|
+
|
|
243
|
+
BUNDLED WITH
|
|
244
|
+
2.7.2
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 corp-gp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Precompiles mailers views using inky-rb and premailer gems. On average, before using this script, 100 emails were sent in 14 seconds. With this script, 100 emails are sent in 2.2 seconds.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
|
|
6
|
+
# Default directory to look in is `/specs`
|
|
7
|
+
# Run with `rake spec`
|
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
|
9
|
+
task.rspec_opts = ['--color', '--format', 'documentation']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task default: :spec
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'email_stylist/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.required_ruby_version = '>= 2.5.0'
|
|
9
|
+
spec.name = 'email_stylist'
|
|
10
|
+
spec.version = EmailStylist::VERSION
|
|
11
|
+
spec.authors = ['ermolaev']
|
|
12
|
+
spec.email = ['andrey@ermolaev.me']
|
|
13
|
+
|
|
14
|
+
spec.summary = 'Email Stylist'
|
|
15
|
+
spec.description = 'GP email stylist.'
|
|
16
|
+
spec.homepage = 'https://gitlab.groupprice.ru/gp-corp/email_stylist'
|
|
17
|
+
spec.license = 'MIT'
|
|
18
|
+
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
spec.bindir = 'exe'
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ['lib']
|
|
23
|
+
|
|
24
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
25
|
+
|
|
26
|
+
spec.add_dependency 'inky-rb'
|
|
27
|
+
spec.add_dependency 'premailer'
|
|
28
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'inky'
|
|
4
|
+
require 'premailer'
|
|
5
|
+
require 'net/http'
|
|
6
|
+
|
|
7
|
+
module EmailStylist
|
|
8
|
+
class StyledErbTemplate
|
|
9
|
+
|
|
10
|
+
# GVL может переключить поток между чтением и записью в любой момент — без мьютекса
|
|
11
|
+
# потоки гонятся компилировать одновременно
|
|
12
|
+
MUTEX = Mutex.new
|
|
13
|
+
|
|
14
|
+
def self.render( # rubocop:disable Metrics/ParameterLists
|
|
15
|
+
template_path:,
|
|
16
|
+
layout_path: nil,
|
|
17
|
+
compiled_path: nil,
|
|
18
|
+
css_string: nil,
|
|
19
|
+
disable_caching: false,
|
|
20
|
+
view_context: nil
|
|
21
|
+
)
|
|
22
|
+
template_id = "#{layout_path}#{template_path}"
|
|
23
|
+
|
|
24
|
+
@cache ||= {}
|
|
25
|
+
|
|
26
|
+
erb_template =
|
|
27
|
+
MUTEX.synchronize do
|
|
28
|
+
@cache[template_id] = nil if disable_caching
|
|
29
|
+
|
|
30
|
+
@cache[template_id] ||=
|
|
31
|
+
begin
|
|
32
|
+
html = compile(template_path, layout_path).gsub(/<%.*?%>/m) { |s| "base64___#{Base64.strict_encode64(s)}___base64" }
|
|
33
|
+
|
|
34
|
+
html = Inky::Core.new.release_the_kraken(html)
|
|
35
|
+
|
|
36
|
+
pm = Premailer.new(
|
|
37
|
+
html,
|
|
38
|
+
css_string: css_string,
|
|
39
|
+
with_html_string: true,
|
|
40
|
+
include_link_tags: true,
|
|
41
|
+
adapter: :nokogiri,
|
|
42
|
+
generate_text_part: false,
|
|
43
|
+
css_to_attributes: false,
|
|
44
|
+
remove_scripts: false,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
html = pm.to_inline_css.force_encoding('ASCII-8BIT').gsub(/base64___(.+?)___base64/) { Base64.strict_decode64(Regexp.last_match(1)) }
|
|
48
|
+
|
|
49
|
+
if compiled_path
|
|
50
|
+
write_compiled_erb(html, compiled_path)
|
|
51
|
+
Tilt::ERBTemplate.new(compiled_path)
|
|
52
|
+
else
|
|
53
|
+
Tilt::ERBTemplate.new { html }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
erb_template.render(view_context)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class << self
|
|
62
|
+
|
|
63
|
+
private def write_compiled_erb(html, compiled_path)
|
|
64
|
+
dir_name = File.dirname(compiled_path)
|
|
65
|
+
FileUtils.mkdir_p(dir_name)
|
|
66
|
+
|
|
67
|
+
# MUTEX защищает только потоки одного процесса, а файл общий для всех
|
|
68
|
+
# процессов. Пишем во временный файл и атомарно переименовываем — читатель
|
|
69
|
+
# никогда не увидит обнулённый File.binwrite другого процесса/потока.
|
|
70
|
+
temp_path = "#{compiled_path}.tmp.#{Process.pid}.#{Thread.current.object_id}"
|
|
71
|
+
File.binwrite(temp_path, html)
|
|
72
|
+
File.rename(temp_path, compiled_path)
|
|
73
|
+
rescue StandardError
|
|
74
|
+
FileUtils.rm_f(temp_path)
|
|
75
|
+
raise
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private def compile(template, layout)
|
|
79
|
+
html = read_with_lock(layout || template)
|
|
80
|
+
|
|
81
|
+
if layout
|
|
82
|
+
html = html.each_line.map { |s|
|
|
83
|
+
if s.include?('INCLUDE_BODY')
|
|
84
|
+
read_with_lock(template)
|
|
85
|
+
else
|
|
86
|
+
s
|
|
87
|
+
end
|
|
88
|
+
}.join
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
compile_components(html)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
private def read_with_lock(path)
|
|
95
|
+
File.open(path, 'rb') do |f|
|
|
96
|
+
f.flock(File::LOCK_SH)
|
|
97
|
+
f.read
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private def compile_components(html)
|
|
102
|
+
html.each_line.map { |s|
|
|
103
|
+
if (m = s.match(/INCLUDE_COMPONENT.*path="(.*)"/)) && m[1]
|
|
104
|
+
compile_components(read_with_lock(m[1]))
|
|
105
|
+
else
|
|
106
|
+
s
|
|
107
|
+
end
|
|
108
|
+
}.join
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: email_stylist
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ermolaev
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: inky-rb
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: premailer
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
description: GP email stylist.
|
|
41
|
+
email:
|
|
42
|
+
- andrey@ermolaev.me
|
|
43
|
+
executables: []
|
|
44
|
+
extensions: []
|
|
45
|
+
extra_rdoc_files: []
|
|
46
|
+
files:
|
|
47
|
+
- ".editorconfig"
|
|
48
|
+
- ".github/workflows/ci.yml"
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- ".rspec"
|
|
51
|
+
- ".rubocop.yml"
|
|
52
|
+
- Gemfile
|
|
53
|
+
- Gemfile.lock
|
|
54
|
+
- LICENSE
|
|
55
|
+
- README.md
|
|
56
|
+
- Rakefile
|
|
57
|
+
- email_stylist.gemspec
|
|
58
|
+
- lib/email_stylist.rb
|
|
59
|
+
- lib/email_stylist/styled_erb_template.rb
|
|
60
|
+
- lib/email_stylist/version.rb
|
|
61
|
+
homepage: https://gitlab.groupprice.ru/gp-corp/email_stylist
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata:
|
|
65
|
+
rubygems_mfa_required: 'true'
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 2.5.0
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubygems_version: 3.6.9
|
|
81
|
+
specification_version: 4
|
|
82
|
+
summary: Email Stylist
|
|
83
|
+
test_files: []
|