mjml-rails 4.8.0 → 4.10.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: 79d635939113a77bdcfa96934cafa71e52a13c71171eb36c138250952e0df2de
4
- data.tar.gz: 5943d70d89ef0d1ce8ba63c32dd72e6837982938b4fbe59e6e4cf5088f04b16b
3
+ metadata.gz: e787307cfcd482f30208f9e38c0ec246b1670ef56bd36fd158d1c84f9b05430a
4
+ data.tar.gz: 7cc87eadbc13039cf2348cc3e5dc08313a751bf6360c403bfa4b545d628864c7
5
5
  SHA512:
6
- metadata.gz: 00a5e9270464c12f16f0b7b8f3e32dc9c0c20413d34063c33c4b86bec08eb7df1c2d5ae20beb61d9f708242203c6c33b663652a207e135ef658cc6636497dcec
7
- data.tar.gz: bab11c714982bca667864e180e9c6066c4a22221dff010a19ffd179b25f79dff8a9de4809af5217ec82d62291835aecf231d79b6ecd255f5bd71e4ba3829365e
6
+ metadata.gz: 38927fca73bc05d06f51a749176b1d8a93e9f08d30ebecd7b1a904f10093111d8239f368cd4ae0c428a15aaad4412f09442767bb60c621b6508917620f3c2d3a
7
+ data.tar.gz: 05cf3a1528c6375c7dd526d1952b589625af2b1a9c974d35a067f64a54bab3bd8eb3f9cbb8ae0bee17411a53e9c0efc83d08999e7c28f0d8dd3807ec3e149543
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -54,6 +54,8 @@ end
54
54
 
55
55
  ## Installation
56
56
 
57
+ ### Using MJML NPM package
58
+
57
59
  Add it to your Gemfile.
58
60
 
59
61
  ```ruby
@@ -72,6 +74,9 @@ Add the MJML parser to your project with your favourite package manager:
72
74
  # with npm
73
75
  npm install mjml
74
76
 
77
+ # or install it globally (The best way for Rails 7.x.x with importmaps)
78
+ npm install -g mjml
79
+
75
80
  # with yarn
76
81
  yarn add mjml
77
82
  ```
@@ -80,6 +85,34 @@ MJML-Rails falls back to a global installation of MJML but it is strongly recomm
80
85
 
81
86
  You'll need at least Node.js version 6 for MJML to function properly.
82
87
 
88
+ ### Using MRML with included binaries
89
+
90
+ If for some reason you can't or don't want to run JS code in your production environment, you can use [MRML](https://github.com/hardpixel/mrml-ruby). It ships with already compiled binaries for Rust implementation of MJML so it has no external dependencies.
91
+
92
+ Add `mjml-rails` and `mrml` to your Gemfile.
93
+
94
+ ```ruby
95
+ gem 'mjml-rails'
96
+ gem 'mrml'
97
+ ```
98
+
99
+ Run the following command to install it:
100
+
101
+ ```console
102
+ bundle install
103
+ ```
104
+
105
+ Set `use_mrml` option to `true` in your initializer:
106
+
107
+ ```ruby
108
+ # config/initializers/mjml.rb
109
+ Mjml.setup do |config|
110
+ config.use_mrml = true
111
+ end
112
+ ```
113
+
114
+ **Note**: MRML does not fully support all MJML functionalities, see [Missing implementations](https://github.com/jdrouet/mrml#missing-implementations)
115
+
83
116
  ## Configuration
84
117
 
85
118
  MJML-Rails has the following settings with defaults:
@@ -112,10 +145,12 @@ MJML-Rails has the following settings with defaults:
112
145
 
113
146
  This can be used to specify the path to a custom MJML binary if it is not detected automatically (shouldn't be needed).
114
147
 
115
- - `mjml_binary_version_support: "4."`
148
+ - `mjml_binary_version_supported: "4."`
116
149
 
117
150
  MJML-Rails checks the version of the MJML binary and fails if it does not start with this version, e.g. if an old version is installed by accident.
118
151
 
152
+ - `use_mrml: false`
153
+ Enabling this will allow you to use Rust implementation of MJML via the `mrml` gem. It comes with prebuilt binaries instead of having to install MJML along with Node. When enabled the options `mjml_binary_version_supported`, `mjml_binary`, `minify`, `beautify` and `validation_level` are ignored.
119
154
 
120
155
  ```ruby
121
156
  # config/initializers/mjml.rb
@@ -133,6 +168,9 @@ Mjml.setup do |config|
133
168
  # Render MJML templates with errors
134
169
  config.validation_level = "soft"
135
170
 
171
+ # Use MRML instead of MJML, false by default
172
+ config.use_mrml = false
173
+
136
174
  # Use custom MJML binary with custom version
137
175
  config.mjml_binary = "/path/to/custom/mjml"
138
176
  config.mjml_binary_version_supported = "3.3.5"
data/lib/mjml/handler.rb CHANGED
@@ -16,6 +16,7 @@ module Mjml
16
16
  def call(template, source = nil)
17
17
  compiled_source = compile_source(source, template)
18
18
 
19
+ parser_class = Mjml.use_mrml ? 'MrmlParser' : 'Parser'
19
20
  # Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
20
21
  # If we get here and template source doesn't start with one it means
21
22
  # that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
@@ -24,7 +25,7 @@ module Mjml
24
25
  #
25
26
  # [0] - https://github.com/mjmlio/mjml/blob/master/doc/components_1.md#mjml
26
27
  if /<mjml.*?>/i.match?(compiled_source)
27
- "Mjml::Parser.new(begin;#{compiled_source};end).render.html_safe"
28
+ "Mjml::#{parser_class}.new(begin;#{compiled_source};end).render.html_safe"
28
29
  else
29
30
  compiled_source
30
31
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mjml
4
+ class MrmlParser
5
+ attr_reader :input
6
+
7
+ # Create new parser
8
+ #
9
+ # @param input [String] The string to transform in html
10
+ def initialize(input)
11
+ @input = input
12
+ end
13
+
14
+ # Render mjml template
15
+ #
16
+ # @return [String]
17
+ def render
18
+ MRML.to_html(input)
19
+ rescue NameError
20
+ Mjml.logger.fatal('MRML is not installed. Please add `gem "mrml"` to your Gemfile.')
21
+ raise
22
+ rescue StandardError
23
+ raise if Mjml.raise_render_exception
24
+
25
+ ''
26
+ end
27
+ end
28
+ end
data/lib/mjml/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mjml
4
4
  # Version number no longer matches MJML.io version
5
- VERSION = '4.8.0'
5
+ VERSION = '4.10.0'
6
6
  end
data/lib/mjml.rb CHANGED
@@ -5,7 +5,7 @@ require 'open3'
5
5
 
6
6
  require 'mjml/handler'
7
7
  require 'mjml/parser'
8
-
8
+ require 'mjml/mrml_parser'
9
9
  require 'mjml/railtie' if defined?(Rails)
10
10
 
11
11
  module Mjml
@@ -17,7 +17,8 @@ module Mjml
17
17
  :mjml_binary_version_supported,
18
18
  :raise_render_exception,
19
19
  :template_language,
20
- :validation_level
20
+ :validation_level,
21
+ :use_mrml
21
22
 
22
23
  mattr_writer :valid_mjml_binary
23
24
 
@@ -29,6 +30,7 @@ module Mjml
29
30
  self.beautify = true
30
31
  self.minify = false
31
32
  self.validation_level = 'strict'
33
+ self.use_mrml = false
32
34
 
33
35
  def self.check_version(bin)
34
36
  stdout, _, status = run_mjml('--version', mjml_bin: bin)
@@ -71,18 +73,28 @@ module Mjml
71
73
 
72
74
  def self.check_for_yarn_mjml_binary
73
75
  yarn_bin = `which yarn`.chomp
74
- return unless yarn_bin.present? && (installer_path = bin_path_from(yarn_bin)).present?
76
+ return if yarn_bin.blank?
77
+
78
+ stdout, _, status = Open3.capture3("#{yarn_bin} bin mjml")
79
+ return unless status.success?
75
80
 
76
- mjml_bin = File.join(installer_path, 'mjml')
81
+ mjml_bin = stdout.chomp
77
82
  return mjml_bin if check_version(mjml_bin)
83
+ rescue Errno::ENOENT # package manager is not installed
84
+ nil
78
85
  end
79
86
 
80
87
  def self.check_for_npm_mjml_binary
81
88
  npm_bin = `which npm`.chomp
82
- return unless npm_bin.present? && (installer_path = bin_path_from(npm_bin)).present?
89
+ return if npm_bin.blank?
90
+
91
+ stdout, _, status = Open3.capture3("#{npm_bin} root")
92
+ return unless status.success?
83
93
 
84
- mjml_bin = File.join(installer_path, 'mjml')
94
+ mjml_bin = File.join(stdout.chomp, '.bin', 'mjml')
85
95
  return mjml_bin if check_version(mjml_bin)
96
+ rescue Errno::ENOENT # package manager is not installed
97
+ nil
86
98
  end
87
99
 
88
100
  def self.check_for_global_mjml_binary
@@ -90,16 +102,6 @@ module Mjml
90
102
  return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
91
103
  end
92
104
 
93
- def self.bin_path_from(package_manager)
94
- stdout, _, status = Open3.capture3("#{package_manager} bin")
95
-
96
- return unless status.success?
97
-
98
- stdout.chomp
99
- rescue Errno::ENOENT # package manager is not installed
100
- nil
101
- end
102
-
103
105
  def self.discover_mjml_bin
104
106
  logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! ' \
105
107
  'Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ describe Mjml::MrmlParser do
6
+ let(:parser) { Mjml::MrmlParser.new(input) }
7
+
8
+ describe '#render' do
9
+ describe 'when input is valid' do
10
+ let(:input) { '<mjml><mj-body><mj-text>Hello World</mj-text></mj-body></mjml>' }
11
+
12
+ it 'returns html' do
13
+ expect(parser.render).must_include 'Hello World</div>'
14
+ end
15
+ end
16
+
17
+ describe 'when exception is raised' do
18
+ let(:input) { '<mjml><body><mj-text>Hello World</mj-text></body></mjml>' }
19
+
20
+ it 'raises exception with render exception enabled' do
21
+ with_settings(raise_render_exception: true) do
22
+ expect { parser.render }.must_raise(MRML::Error)
23
+ end
24
+ end
25
+
26
+ it 'returns empty string with exception raising disabled' do
27
+ with_settings(raise_render_exception: false) do
28
+ expect(parser.render).must_equal ''
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
data/test/test_helper.rb CHANGED
@@ -5,6 +5,7 @@ require 'bundler'
5
5
  Bundler.setup
6
6
 
7
7
  require 'minitest/autorun'
8
+ require 'active_support'
8
9
  require 'active_support/test_case'
9
10
 
10
11
  require 'action_mailer'
@@ -13,6 +14,7 @@ require 'rails/generators'
13
14
  require 'rails/generators/test_case'
14
15
  require 'mocha/minitest'
15
16
  require 'byebug'
17
+ require 'mrml'
16
18
 
17
19
  # require "minitest/reporters"
18
20
  # Minitest::Reporters.use!
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mjml-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Loffler
@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tWWoR2alg8kKc6yLx
37
+ P5J+9tLKId50fAv4voQg//wRwePPNiWIXsLUa1LPYWTAznKTvi3dAQ==
37
38
  -----END CERTIFICATE-----
38
- date: 2022-10-02 00:00:00.000000000 Z
39
+ date: 2024-01-18 00:00:00.000000000 Z
39
40
  dependencies:
40
41
  - !ruby/object:Gem::Dependency
41
42
  name: byebug
@@ -57,14 +58,28 @@ dependencies:
57
58
  requirements:
58
59
  - - '='
59
60
  - !ruby/object:Gem::Version
60
- version: 1.4.0
61
+ version: 2.1.0
61
62
  type: :development
62
63
  prerelease: false
63
64
  version_requirements: !ruby/object:Gem::Requirement
64
65
  requirements:
65
66
  - - '='
66
67
  - !ruby/object:Gem::Version
67
- version: 1.4.0
68
+ version: 2.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: mrml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.4.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.4.2
68
83
  - !ruby/object:Gem::Dependency
69
84
  name: rails
70
85
  requirement: !ruby/object:Gem::Requirement
@@ -149,11 +164,13 @@ files:
149
164
  - lib/mjml-rails.rb
150
165
  - lib/mjml.rb
151
166
  - lib/mjml/handler.rb
167
+ - lib/mjml/mrml_parser.rb
152
168
  - lib/mjml/parser.rb
153
169
  - lib/mjml/railtie.rb
154
170
  - lib/mjml/version.rb
155
171
  - test/generator_test.rb
156
172
  - test/mjml_test.rb
173
+ - test/mrml_parser_test.rb
157
174
  - test/parser_test.rb
158
175
  - test/test_helper.rb
159
176
  homepage: https://github.com/sighmon/mjml-rails
@@ -175,12 +192,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
192
  - !ruby/object:Gem::Version
176
193
  version: '0'
177
194
  requirements: []
178
- rubygems_version: 3.1.6
195
+ rubygems_version: 3.4.10
179
196
  signing_key:
180
197
  specification_version: 4
181
198
  summary: MJML + ERb templates
182
199
  test_files:
183
200
  - test/generator_test.rb
184
- - test/parser_test.rb
185
201
  - test/mjml_test.rb
202
+ - test/mrml_parser_test.rb
203
+ - test/parser_test.rb
186
204
  - test/test_helper.rb
metadata.gz.sig CHANGED
Binary file