mjml-rails 4.4.0 → 4.6.1

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: 88e3f9ecbcbb4ddc89a64ae73dc35f62df462edc2e52a80ffcce8b76b17e7324
4
- data.tar.gz: 44f3771373b38d7ba49ebee9ae6e503a4f094f2c7ab96bb0be88e6b3326ee38d
3
+ metadata.gz: 0a845d39f307dd7d452b0766805154e622aecaed3bbb3b4d392ead880939dc04
4
+ data.tar.gz: 13a7793222a8253ce62dd97f2a225379615515225e7f987deb23f5a93d6dbbfd
5
5
  SHA512:
6
- metadata.gz: 60001f52fd6d52b7ed1babb9e1387e6488b7f05624ddc5565f411caf87c4455c1c92d47466216b84f7aec540ad3e19343c178c9c64f82f8751447f52500e2dce
7
- data.tar.gz: 43df7639a83deb7ffa0fb2e13ce28c5d2e6faa357fb18d7415a1b3a7ea022d25875365653b989783de72d4f4b7a4453cf0bc340e36d4a9f69769807c93e8815e
6
+ metadata.gz: f05c5580304ececa283ea79e17b61c7a281ce9b327d8aa3c73bacbdeaa8873049f3491243f03964e8fe0bf33f4c4e9ff2c0c70c2424100ae23f7d1a26d3322da
7
+ data.tar.gz: 111b70710d670a442564aa877652f3711c0ad9c934e1be8edd24a6fc0011f7019c3c9aaa58abec7cfcc338b7ca5ecac2aa6c3e3bd9af30cbb68402dcfa5a3165
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # MJML-Rails
2
2
 
3
- [![Build Status](https://api.travis-ci.org/sighmon/mjml-rails.svg?branch=master)](http://travis-ci.org/sighmon/mjml-rails) [![Gem Version](https://badge.fury.io/rb/mjml-rails.svg)](https://badge.fury.io/rb/mjml-rails)
3
+ [![Build Status](https://github.com/sighmon/mjml-rails/workflows/test/badge.svg?branch=master)](https://github.com/sighmon/mjml-rails/actions?query=workflow%3Atest+branch%3Amaster) [![Gem Version](https://badge.fury.io/rb/mjml-rails.svg)](https://badge.fury.io/rb/mjml-rails)
4
4
 
5
- **MJML-Rails** allows you to render HTML e-mails from an [MJML](https://mjml.io) template.
5
+ **MJML-Rails** allows you to render HTML emails from an [MJML](https://mjml.io) template.
6
6
 
7
7
  **Note**: As of MJML 4.3.0 you can no longer use `<mj-text>` directly inside an `<mj-body>`, wrap it in `<mj-section><mj-column>`.
8
8
 
@@ -66,57 +66,79 @@ Run the following command to install it:
66
66
  bundle install
67
67
  ```
68
68
 
69
- Install the MJML parser (optional -g to install it globally):
69
+ Add the MJML parser to your project with your favourite package manager:
70
70
 
71
71
  ```console
72
- npm install -g mjml
72
+ # with npm
73
+ npm install mjml
74
+
75
+ # with yarn
76
+ yarn add mjml
73
77
  ```
74
78
 
75
- Note that you'll need at least Node.js version 6 for MJML to function properly.
79
+ MJML-Rails falls back to a global installation of MJML but it is strongly recommended to add MJML directly to your project.
76
80
 
77
- If you're using ```:haml``` or any other Rails template language, create an initializer to set it up:
81
+ You'll need at least Node.js version 6 for MJML to function properly.
78
82
 
79
- ```ruby
80
- # config/initializers/mjml.rb
81
- Mjml.setup do |config|
82
- config.template_language = :erb # :erb (default), :slim, :haml, or any other you are using
83
- end
84
- ```
83
+ ## Configuration
84
+
85
+ MJML-Rails has the following settings with defaults:
86
+
87
+ - `template_language: :erb`
88
+
89
+ ERB can be used inside MJML templates by default. Possible values are all template languages that you have installed, e.g. `:haml` or `:slim`.
90
+
91
+ **Note:** If you’re using Haml/Slim layouts, please don’t put `<mjml>` in comments in your partial. Read more at [#34](https://github.com/sighmon/mjml-rails/issues/34).
92
+
93
+ - `raise_render_exception: true`
94
+
95
+ Exceptions will be raised and passed to your application by default.
96
+
97
+ Beware that setting it to `false` leads to an empty html email when an exception is raised, so only set this to `false` if you do not rely on html (e.g. you have a text fallback for your emails).
98
+
99
+ - `minify: false`
100
+
101
+ - `beautify: true`
85
102
 
86
- **Note:** If you’re using Haml/Slim layouts, please don’t put `<mjml>` in comments in your partial. Read more: [#34](https://github.com/sighmon/mjml-rails/issues/34).
103
+ - `validation_level: "strict"`
104
+
105
+ MJML-Rails will raise an exception on any template error by default.
106
+
107
+ If set to `soft`, MJML will render invalid templates and ignore invalid parts. This means in case of an invalid template those invalid parts will be missing from the output.
108
+
109
+ See [MJML validation documentation](https://github.com/mjmlio/mjml/tree/master/packages/mjml-validator#validating-mjml) for all possible values.
110
+
111
+ - `mjml_binary: nil`
112
+
113
+ This can be used to specify the path to a custom MJML binary if it is not detected automatically (shouldn't be needed).
114
+
115
+ - `mjml_binary_version_support: "4."`
116
+
117
+ 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.
87
118
 
88
- If there are configurations you'd like change:
89
- - render errors: defaults to `true` (errors raised)
90
- - minify: defaults to `false` (not minified)
91
- - beautify: defaults to `true` (beautified)
92
- - validation_level: defaults to `soft` (MJML syntax validation)
93
119
 
94
120
  ```ruby
95
121
  # config/initializers/mjml.rb
96
122
  Mjml.setup do |config|
97
- # set to `false` to ignore errors silently
98
- config.raise_render_exception = true
123
+ # Use :haml as a template language
124
+ config.template_language = :haml
99
125
 
100
- # optimize the size of your email
126
+ # Ignore errors silently
127
+ config.raise_render_exception = false
128
+
129
+ # Optimize the size of your emails
101
130
  config.beautify = false
102
131
  config.minify = true
103
- config.validation_level = "strict"
104
- end
105
- ```
106
132
 
107
- If you’d like to specify a different MJML binary to run other than `4.`:
133
+ # Render MJML templates with errors
134
+ config.validation_level = "soft"
108
135
 
109
- ```ruby
110
- # config/initializers/mjml.rb
111
- Mjml.setup do |config|
136
+ # Use custom MJML binary with custom version
137
+ config.mjml_binary = "/path/to/custom/mjml"
112
138
  config.mjml_binary_version_supported = "3.3.5"
113
139
  end
114
- # If you set a different MJML binary version, you need to re-discover the binary
115
- Mjml::BIN = Mjml.discover_mjml_bin
116
140
  ```
117
141
 
118
- **Note:** If you set a different MJML binary you’ll see warnings in your logs of `already initialized constant Mjml::BIN`. Read more: [#39](https://github.com/sighmon/mjml-rails/issues/39#issuecomment-429151908)
119
-
120
142
  ### MJML v3.x & v4.x support
121
143
 
122
144
  Version 4.x of this gem brings support for MJML 4.x
@@ -1 +1 @@
1
- require "mjml"
1
+ require "mjml"
@@ -1,13 +1,23 @@
1
- require "rails/version"
2
- require "action_view"
3
- require "action_view/template"
4
- require "mjml/mjmltemplate"
5
- require "mjml/railtie"
6
1
  require "rubygems"
7
2
  require "open3"
8
3
 
4
+ require "mjml/handler"
5
+ require "mjml/parser"
6
+
7
+ require "mjml/railtie" if defined?(Rails)
8
+
9
9
  module Mjml
10
- mattr_accessor :template_language, :raise_render_exception, :mjml_binary_version_supported, :mjml_binary_error_string, :beautify, :minify, :validation_level
10
+ mattr_accessor \
11
+ :beautify,
12
+ :minify,
13
+ :mjml_binary,
14
+ :mjml_binary_error_string,
15
+ :mjml_binary_version_supported,
16
+ :raise_render_exception,
17
+ :template_language,
18
+ :validation_level
19
+
20
+ mattr_writer :valid_mjml_binary
11
21
 
12
22
  @@template_language = :erb
13
23
  @@raise_render_exception = true
@@ -15,71 +25,78 @@ module Mjml
15
25
  @@mjml_binary_error_string = "Couldn't find the MJML #{Mjml.mjml_binary_version_supported} binary.. have you run $ npm install mjml?"
16
26
  @@beautify = true
17
27
  @@minify = false
18
- @@validation_level = "soft"
28
+ @@validation_level = "strict"
19
29
 
20
30
  def self.check_version(bin)
21
- IO.popen([bin, '--version']) { |io| io.read.include?("mjml-core: #{Mjml.mjml_binary_version_supported}") }
22
- rescue
31
+ stdout, _, status = run_mjml('--version', mjml_bin: bin)
32
+ status.success? && stdout.include?("mjml-core: #{Mjml.mjml_binary_version_supported}")
33
+ rescue StandardError
23
34
  false
24
35
  end
25
36
 
26
- def self.discover_mjml_bin
27
- # Check for a global install of MJML binary
28
- mjml_bin = 'mjml'
29
- return mjml_bin if check_version(mjml_bin)
37
+ def self.run_mjml(args, mjml_bin: valid_mjml_binary)
38
+ Open3.capture3("#{mjml_bin} #{args}")
39
+ end
40
+
41
+ def self.valid_mjml_binary
42
+ @@valid_mjml_binary ||=
43
+ check_for_custom_mjml_binary ||
44
+ check_for_yarn_mjml_binary ||
45
+ check_for_npm_mjml_binary ||
46
+ check_for_global_mjml_binary
47
+
48
+ return @@valid_mjml_binary if @@valid_mjml_binary
30
49
 
31
- # Check for a local install of MJML binary
32
- installer_path = bin_path_from('npm') || bin_path_from('yarn')
33
- unless installer_path
34
- puts Mjml.mjml_binary_error_string
35
- return nil
50
+ puts Mjml.mjml_binary_error_string
51
+ end
52
+
53
+ def self.check_for_custom_mjml_binary
54
+ if const_defined?('BIN') && Mjml::BIN.present?
55
+ logger.warn('Setting `Mjml::BIN` is deprecated and will be removed in a future version! Please use `Mjml.mjml_binary=` instead.')
56
+ self.mjml_binary = Mjml::BIN
57
+ remove_const 'BIN'
36
58
  end
37
59
 
60
+ return unless mjml_binary.present?
61
+
62
+ return mjml_binary if check_version(mjml_binary)
63
+
64
+ raise "MJML.mjml_binary is set to '#{mjml_binary}' but MJML-Rails could not validate that it is a valid MJML binary. Please check your configuration."
65
+ end
66
+
67
+ def self.check_for_yarn_mjml_binary
68
+ yarn_bin = `which yarn`.chomp
69
+ return unless yarn_bin.present?
70
+
71
+ mjml_bin = "#{yarn_bin} run mjml"
72
+ return mjml_bin if check_version(mjml_bin)
73
+ end
74
+
75
+ def self.check_for_npm_mjml_binary
76
+ npm_bin = `which npm`.chomp
77
+ return unless npm_bin.present? && (installer_path = bin_path_from(npm_bin)).present?
78
+
38
79
  mjml_bin = File.join(installer_path, 'mjml')
39
80
  return mjml_bin if check_version(mjml_bin)
81
+ end
40
82
 
41
- puts Mjml.mjml_binary_error_string
42
- nil
83
+ def self.check_for_global_mjml_binary
84
+ mjml_bin = `which mjml`.chomp
85
+ return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
43
86
  end
44
87
 
45
88
  def self.bin_path_from(package_manager)
46
- _, stdout, _, _ = Open3.popen3("#{package_manager} bin")
47
- stdout.read.chomp
89
+ stdout, _, status = Open3.capture3("#{package_manager} bin")
90
+
91
+ return unless status.success?
92
+
93
+ stdout.chomp
48
94
  rescue Errno::ENOENT # package manager is not installed
49
95
  nil
50
96
  end
51
97
 
52
- BIN = discover_mjml_bin
53
-
54
- class Handler
55
- def template_handler
56
- @_template_handler ||= ActionView::Template.registered_template_handler(Mjml.template_language)
57
- end
58
-
59
- # Optional second source parameter to make it work with Rails >= 6:
60
- # Beginning with Rails 6 template handlers get the source of the template as the second
61
- # parameter.
62
- def call(template, source = nil)
63
- compiled_source =
64
- if Rails::VERSION::MAJOR >= 6
65
- template_handler.call(template, source)
66
- else
67
- template_handler.call(template)
68
- end
69
-
70
- # Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
71
- # If we get here and template source doesn't start with one it means
72
- # that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
73
- # Therefore we skip MJML processing and return raw compiled source. It will be processed
74
- # by MJML library when top-level layout/template is rendered
75
- #
76
- # [0] - https://github.com/mjmlio/mjml/blob/master/doc/guide.md#mjml
77
- if compiled_source =~ /<mjml(.+)?>/i
78
- "Mjml::Mjmltemplate.to_html(begin;#{compiled_source};end).html_safe"
79
- else
80
- compiled_source
81
- end
82
- end
98
+ def self.discover_mjml_bin
99
+ logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
83
100
  end
84
101
 
85
102
  def self.setup
@@ -0,0 +1,36 @@
1
+ require 'action_view'
2
+ require 'action_view/template'
3
+ require 'rails/version'
4
+
5
+ module Mjml
6
+ class Handler
7
+ def template_handler
8
+ @template_handler ||= ActionView::Template.registered_template_handler(Mjml.template_language)
9
+ end
10
+
11
+ # Optional second source parameter to make it work with Rails >= 6:
12
+ # Beginning with Rails 6 template handlers get the source of the template as the second
13
+ # parameter.
14
+ def call(template, source = nil)
15
+ compiled_source =
16
+ if Rails::VERSION::MAJOR >= 6
17
+ template_handler.call(template, source)
18
+ else
19
+ template_handler.call(template)
20
+ end
21
+
22
+ # Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
23
+ # If we get here and template source doesn't start with one it means
24
+ # that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
25
+ # Therefore we skip MJML processing and return raw compiled source. It will be processed
26
+ # by MJML library when top-level layout/template is rendered
27
+ #
28
+ # [0] - https://github.com/mjmlio/mjml/blob/master/doc/guide.md#mjml
29
+ if compiled_source =~ /<mjml.*?>/i
30
+ "Mjml::Parser.new(begin;#{compiled_source};end).render.html_safe"
31
+ else
32
+ compiled_source
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,3 @@
1
- require 'open3'
2
-
3
1
  module Mjml
4
2
  class Parser
5
3
  class ParseError < StandardError; end
@@ -10,7 +8,7 @@ module Mjml
10
8
  #
11
9
  # @param input [String] The string to transform in html
12
10
  def initialize input
13
- raise Mjml.mjml_binary_error_string unless mjml_bin
11
+ raise Mjml.mjml_binary_error_string unless Mjml.valid_mjml_binary
14
12
  @input = input
15
13
  end
16
14
 
@@ -33,22 +31,14 @@ module Mjml
33
31
  # Exec mjml command
34
32
  #
35
33
  # @return [String] The result as string
36
- def run(in_tmp_file, beautify=true, minify=false, validation_level="soft")
34
+ def run(in_tmp_file, beautify=true, minify=false, validation_level="strict")
37
35
  Tempfile.create(["out", ".html"]) do |out_tmp_file|
38
- command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file.path} --config.beautify #{beautify} --config.minify #{minify} --config.validationLevel #{validation_level}"
39
- _, _, stderr, _ = Open3.popen3(command)
40
- raise ParseError.new(stderr.read.chomp) unless stderr.eof?
36
+ command = "-r #{in_tmp_file} -o #{out_tmp_file.path} --config.beautify #{beautify} --config.minify #{minify} --config.validationLevel #{validation_level}"
37
+ _, stderr, status = Mjml.run_mjml(command)
38
+ raise ParseError.new(stderr.chomp) unless status.success?
39
+ Mjml.logger.warn(stderr.chomp) unless stderr.blank?
41
40
  out_tmp_file.read
42
41
  end
43
42
  end
44
-
45
- private
46
-
47
- # Get mjml bin path
48
- #
49
- # @return [String]
50
- def mjml_bin
51
- Mjml::BIN
52
- end
53
43
  end
54
44
  end
@@ -7,5 +7,10 @@ module Mjml
7
7
  ActionView::Template.register_template_handler :mjml, Mjml::Handler.new
8
8
  Mime::Type.register_alias "text/html", :mjml
9
9
  end
10
+
11
+ config.to_prepare do
12
+ # make sure we have a valid mjml binary
13
+ Mjml.valid_mjml_binary
14
+ end
10
15
  end
11
16
  end
@@ -1,4 +1,4 @@
1
1
  module Mjml
2
2
  # Version number no longer matches MJML.io version
3
- VERSION = "4.4.0"
3
+ VERSION = "4.6.1"
4
4
  end
@@ -13,6 +13,15 @@ class NotifierMailer < ActionMailer::Base
13
13
  format.html
14
14
  end
15
15
  end
16
+
17
+ def invalid_template(recipient)
18
+ @recipient = recipient
19
+
20
+ mail(to: @recipient, from: "app@example.com") do |format|
21
+ format.html
22
+ format.text
23
+ end
24
+ end
16
25
  end
17
26
 
18
27
  class NoLayoutMailer < ActionMailer::Base
@@ -58,6 +67,22 @@ class NotifierMailerTest < ActiveSupport::TestCase
58
67
  assert email.text_part.body.match(/We inform you about something/)
59
68
  assert email.text_part.body.match(%r{Please visit https://www.example.com})
60
69
  end
70
+
71
+ test "Invalid template raises error with validation level strict" do
72
+ with_settings(validation_level: 'strict') do
73
+ email = NotifierMailer.invalid_template("user@example.com")
74
+ assert_raise(ActionView::Template::Error) { email.html_part.body.to_s }
75
+ end
76
+ end
77
+
78
+ test "Invalid template gets compiled with validation level soft" do
79
+ with_settings(validation_level: 'soft') do
80
+ email = NotifierMailer.invalid_template("user@example.com")
81
+ assert email.text_part.body.match(/This is valid/)
82
+ assert email.html_part.body.match(/This is valid/)
83
+ refute email.html_part.body.match(/This is invalid/)
84
+ end
85
+ end
61
86
  end
62
87
 
63
88
  class NotifierMailerTest < ActiveSupport::TestCase
@@ -87,3 +112,44 @@ class NotifierMailerTest < ActiveSupport::TestCase
87
112
  refute email.body.match(/tracking-code-123/)
88
113
  end
89
114
  end
115
+
116
+ describe Mjml do
117
+ describe '#valid_mjml_binary' do
118
+ before do
119
+ Mjml.mjml_binary = nil
120
+ Mjml.valid_mjml_binary = nil
121
+ end
122
+
123
+ after do
124
+ Mjml.mjml_binary = nil
125
+ Mjml.valid_mjml_binary = nil
126
+ end
127
+
128
+ it 'can be set to a custom value with mjml_binary if version is correct' do
129
+ Mjml.mjml_binary = 'some custom value'
130
+ Mjml.stub :check_version, true do
131
+ expect(Mjml.valid_mjml_binary).must_equal 'some custom value'
132
+ end
133
+ end
134
+
135
+ it 'raises an error if mjml_binary is invalid' do
136
+ Mjml.mjml_binary = 'some custom value'
137
+ err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
138
+ expect(err.message).must_match(/MJML\.mjml_binary is set to 'some custom value' but MJML-Rails could not validate that it is a valid MJML binary/)
139
+ end
140
+
141
+ it 'honors old Mjml::BIN way of setting custom binary' do
142
+ Mjml::BIN = 'set by old way'
143
+ err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
144
+ expect(err.message).must_match(/MJML\.mjml_binary is set to 'set by old way' but MJML-Rails could not validate that it is a valid MJML binary/)
145
+ end
146
+
147
+ it 'ignores empty Mjml::BIN' do
148
+ Mjml::BIN = ''
149
+ Mjml.mjml_binary = 'set by mjml_binary'
150
+
151
+ err = expect { Mjml.valid_mjml_binary }.must_raise(StandardError)
152
+ expect(err.message).must_match(/MJML\.mjml_binary is set to 'set by mjml_binary' but MJML-Rails could not validate that it is a valid MJML binary/)
153
+ end
154
+ end
155
+ end
@@ -13,61 +13,52 @@ describe Mjml::Parser do
13
13
  parser.stubs(:run).raises(error)
14
14
  end
15
15
 
16
- describe 'when render exception raising is enabled' do
17
- before do
18
- Mjml.setup do |config|
19
- config.raise_render_exception = true
20
- end
21
- end
22
-
23
- it 'raises exception' do
24
- -> { parser.render }.must_raise(custom_error_class, error.message)
16
+ it 'raises exception with render exception enabled' do
17
+ with_settings(raise_render_exception: true) do
18
+ err = expect { parser.render }.must_raise(custom_error_class)
19
+ expect(err.message).must_equal error.message
25
20
  end
26
21
  end
27
22
 
28
- describe 'when render exception raising is disabled' do
29
- before do
30
- Mjml.setup do |config|
31
- config.raise_render_exception = false
32
- end
33
- end
34
-
35
- it 'returns empty string' do
36
- parser.render.must_equal ''
23
+ it 'returns empty string with exception raising disabled' do
24
+ with_settings(raise_render_exception: false) do
25
+ expect(parser.render).must_equal ''
37
26
  end
38
27
  end
39
28
  end
40
29
 
41
30
  describe 'can read beautify, minify, and validation_level configs' do
42
- it 'use defaults if no config is set' do
31
+ it 'uses defaults if no config is set' do
43
32
  expect(Mjml.beautify).must_equal(true)
44
33
  expect(Mjml.minify).must_equal(false)
45
- expect(Mjml.validation_level).must_equal('soft')
34
+ expect(Mjml.validation_level).must_equal('strict')
46
35
  end
47
36
 
48
- it 'use setup config' do
37
+ it 'uses setup config' do
49
38
  Mjml.setup do |config|
50
39
  config.beautify = false
51
40
  config.minify = true
52
- config.validation_level = 'strict'
41
+ config.validation_level = 'soft'
53
42
  end
54
43
 
55
44
  expect(Mjml.beautify).must_equal(false)
56
45
  expect(Mjml.minify).must_equal(true)
57
- expect(Mjml.validation_level).must_equal('strict')
46
+ expect(Mjml.validation_level).must_equal('soft')
47
+
48
+ Mjml.setup do |config|
49
+ config.beautify = true
50
+ config.minify = false
51
+ config.validation_level = 'strict'
52
+ end
58
53
  end
59
54
  end
60
55
  end
61
56
 
62
57
  describe '#run' do
63
- describe 'when shell command is failed' do
64
- let(:error) { 'shell error' }
65
- let(:stderr) { mock('stderr', eof?: false, read: error) }
66
-
67
- before { Open3.stubs(popen3: [nil, nil, stderr, nil]) }
68
-
58
+ describe 'when shell command failed' do
69
59
  it 'raises exception' do
70
- -> { parser.run "/tmp/input_file.mjml" }.must_raise(Mjml::Parser::ParseError, error)
60
+ err = expect { parser.run "/tmp/non_existent_file.mjml" }.must_raise(Mjml::Parser::ParseError)
61
+ expect(err.message).must_include 'Command line error'
71
62
  end
72
63
  end
73
64
  end
@@ -25,3 +25,20 @@ I18n.enforce_available_locales = false
25
25
 
26
26
  ActionMailer::Base.delivery_method = :test
27
27
  ActionMailer::Base.perform_deliveries = true
28
+
29
+ def with_settings(settings)
30
+ original_settings =
31
+ settings.each_with_object({}) do |(key, _), agg|
32
+ agg[key] = Mjml.public_send(key)
33
+ end
34
+
35
+ settings.each do |key, value|
36
+ Mjml.public_send("#{key}=", value)
37
+ end
38
+
39
+ yield
40
+ ensure
41
+ original_settings.each do |key, value|
42
+ Mjml.public_send("#{key}=", value)
43
+ end
44
+ end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mjml-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Loffler
8
8
  - Steven Pickles
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain:
12
12
  - |
13
13
  -----BEGIN CERTIFICATE-----
14
- MIIEPDCCAqSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAkMSIwIAYDVQQDDBlzaWdo
15
- bW9uL0RDPXNpZ2htb24vREM9Y29tMB4XDTE5MDkwMzEwMjAzMFoXDTIwMDkwMjEw
16
- MjAzMFowJDEiMCAGA1UEAwwZc2lnaG1vbi9EQz1zaWdobW9uL0RDPWNvbTCCAaIw
17
- DQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALePOldN5EpBHYLzEl03frx6qnNL
18
- t7FR4L4E18C5nkYui//Qrk3PgIuOROzNYCn/DadpvfrJAXUD483+XZbwhwBKscx6
19
- GPdoYotiH3R5BLvhfPQGI5yz4Dr3W8g5Z3vgtbL+4NS3XCGs3DjdmkLNBIjYJQC9
20
- j8vP1+QChRUZAq7LRmwW4H39qJEEbGasmAfLZIAyzt+B0daUoVvEagOE94taAbYd
21
- FzhBXn0Rkcs2GbCwv9oxbXlhO47wABLB0eOCL6VMZdwrfkML6agw81jnvzs2Dh1W
22
- e2jUX57TpeXKZ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N2lWrqu4fT1MdTmA+hZ
31
+ vhfqJeSuWM5wNsWxA66SgbQe8BMHcsqV1CTG+Ir8FIAHzfa+c7CNke/28htRKYJV
32
+ 6+lk55Ueov5TjjgLTUvjdqbAEtyCZpgxe2e0o3xqKh5d5YjWVQ4mSNvBsqK7UXOx
33
+ MGsePVBV9lnSFEJkGB3iOvavQSVUvqybF+yk6DrJR9iZtKCvAqd96PjkcFoM19dG
34
+ 5ofv88TRZwXM9lWn4UKuekSSF1ElH3UBVDbH4zEHaOzrOvgfnZw3VteDigwfmmwF
35
+ lsAqKbu4nrHhtGhkwdYbflf2URJTUxXGptrnPYV7okmEg4rsykK3RAsZ6kMNdKmx
36
+ DcQ7RSt1TU5eck6c
37
37
  -----END CERTIFICATE-----
38
- date: 2020-04-04 00:00:00.000000000 Z
38
+ date: 2020-12-19 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description: Render MJML + ERb template views in Rails
41
41
  email: sighmon@sighmon.com
@@ -50,20 +50,19 @@ files:
50
50
  - lib/generators/mjml/mailer/templates/view.html.erb
51
51
  - lib/mjml-rails.rb
52
52
  - lib/mjml.rb
53
- - lib/mjml/mjmltemplate.rb
53
+ - lib/mjml/handler.rb
54
54
  - lib/mjml/parser.rb
55
55
  - lib/mjml/railtie.rb
56
56
  - lib/mjml/version.rb
57
57
  - test/generator_test.rb
58
58
  - test/mjml_test.rb
59
59
  - test/parser_test.rb
60
- - test/template_test.rb
61
60
  - test/test_helper.rb
62
61
  homepage: https://github.com/sighmon/mjml-rails
63
62
  licenses:
64
63
  - MIT
65
64
  metadata: {}
66
- post_install_message: "Don't forget to install MJML e.g. \n$ npm install -g mjml"
65
+ post_install_message: "Don't forget to install MJML e.g. \n$ npm install mjml"
67
66
  rdoc_options: []
68
67
  require_paths:
69
68
  - lib
@@ -78,13 +77,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
77
  - !ruby/object:Gem::Version
79
78
  version: '0'
80
79
  requirements: []
81
- rubygems_version: 3.0.6
82
- signing_key:
80
+ rubygems_version: 3.1.4
81
+ signing_key:
83
82
  specification_version: 4
84
83
  summary: MJML + ERb templates
85
84
  test_files:
86
85
  - test/generator_test.rb
87
86
  - test/parser_test.rb
88
87
  - test/mjml_test.rb
89
- - test/template_test.rb
90
88
  - test/test_helper.rb
metadata.gz.sig CHANGED
@@ -1,3 +1 @@
1
- cg4Wj�.@T|}�?��GՓ-���9A���&Ê)E}3(��X��p a4��
2
- �0i�`�Z�ln���culhmE`
3
- /V��iڇv��D'1|� 8(�h�';�"W���N�
1
+ .�%�S��3y���Ԣ7i׹kxhm���T�W���x^�8��`/� �D4�\�F��Ơ\7"�˚/\y�x�E����}l�nF>@�d�Mi��:N$�u-P<��{����j���*ѥ�,\��2�JӇ}�ޮ��9������� C$�k�t�,�JϙMZ�ɒ��t�vpr�v�Ÿ���Mj����\lG���~K:�e�̢l��B�Q�x�>R�� �Z�����6#+,o�� �1��Her�qB�����H�ɟ@���N/v_tҀ�崉�I���l�=�ޫ�0é:�K�O�0@�0!�y��^�@��!ɰ�i������X߂d�+���踟, F��k�k1S��9��dT<ee��!�N
@@ -1,12 +0,0 @@
1
- require "mjml/parser"
2
-
3
- module Mjml
4
- mattr_accessor :processing_options, :renderer
5
- @@processing_options = {}
6
-
7
- class Mjmltemplate
8
- def self.to_html(compiled_source)
9
- Mjml::Parser.new(compiled_source).render.html_safe
10
- end
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- require "test_helper"
2
-
3
- class MjmlTest < ActiveSupport::TestCase
4
-
5
- test 'with Mjmltemplate processor' do
6
- assert_not_equal "<mj-body></mj-body>", Mjml::Mjmltemplate.to_html("<mjml><mj-body><mj-section><mj-column></mj-column></mj-section></mj-body></mjml>").strip
7
- end
8
-
9
- end