mjml-rails 4.15.0 → 4.16.0

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
  SHA256:
3
- metadata.gz: 7a768bdc7c72cb474b41346d9f48685d46ac7eb477850f417eac944abcfe3289
4
- data.tar.gz: ceca1bd32af0d391c92a5ff0a00a80751e34b069571fe57567fc3b1cfee656ff
3
+ metadata.gz: 2765f5756d63843512d96e8c0dca3d5ae41c132e2e527ffd1d161e963ff39e8c
4
+ data.tar.gz: d7c19dae4feafb3593e4f478463897f1310a0950414811fef87de94323ec8e4d
5
5
  SHA512:
6
- metadata.gz: a2a6098dadd2d9004b7043903b61056da28d2d061bebb391c7ed9ab537f24879dac30b46d08388c41871a74c7a7e4e703d1b206e08f0980aeaeb006e3674ed7c
7
- data.tar.gz: f626fc4c6141133b42cba395e137f557ed3259198a40ab7b445a8ec5b3521cbb74a5a499df5d3e0a176f5f3a8c10e5f933e37fa000d45957784c1d9869b4a778
6
+ metadata.gz: 5d8f725b93ec25cd3102309b453771157971bdf976d4f3f641ef51a78c90f678d518db51119110c1a5df53882e30814a16fcaf8ecef7eae07f59a05700df91ce
7
+ data.tar.gz: 36afdf274545cc6a8222ea86a03d9c020a7b248f8761454e73d4f68d515dfaeb665474a270e80f6ef4822e90d3a8b02275065d96f35fa75b5870cb0e039193c5
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/mjml/handler.rb CHANGED
@@ -17,7 +17,7 @@ module Mjml
17
17
  compiled_source = compile_source(source, template)
18
18
 
19
19
  parser_class = Mjml.use_mrml ? 'MrmlParser' : 'Parser'
20
- template_path = template.virtual_path
20
+ template_path = template.respond_to?(:virtual_path) ? template.virtual_path : template.identifier
21
21
  # Per MJML v4 syntax documentation[0] valid/render'able document MUST start with <mjml> root tag
22
22
  # If we get here and template source doesn't start with one it means
23
23
  # that we are rendering partial named according to legacy naming convention (partials ending with '.mjml')
@@ -2,27 +2,32 @@
2
2
 
3
3
  module Mjml
4
4
  class MrmlParser
5
- attr_reader :input
5
+ attr_reader :template_path, :input
6
6
 
7
7
  # Create new parser
8
8
  #
9
+ # @param template_path [String] The path to the .mjml file
9
10
  # @param input [String] The string to transform in html
10
- def initialize(input)
11
- @input = input
11
+ def initialize(template_path, input)
12
+ @template_path = template_path
13
+ @input = input
14
+ @with_cache = Cache.new(template_path)
12
15
  end
13
16
 
14
17
  # Render mjml template
15
18
  #
16
19
  # @return [String]
17
20
  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
21
+ @with_cache.cache do
22
+ MRML.to_html(input)
23
+ rescue NameError
24
+ Mjml.logger.fatal('MRML is not installed. Please add `gem "mrml"` to your Gemfile.')
25
+ raise
26
+ rescue StandardError
27
+ raise if Mjml.raise_render_exception
24
28
 
25
- ''
29
+ ''
30
+ end
26
31
  end
27
32
  end
28
33
  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.15.0'
5
+ VERSION = '4.16.0'
6
6
  end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class HandlerTest < ActiveSupport::TestCase
6
+ def setup
7
+ @handler = Mjml::Handler.new
8
+ end
9
+
10
+ test 'uses virtual_path when available' do
11
+ template = mock
12
+ template.stubs(:virtual_path).returns('/path/to/template')
13
+ template.stubs(:respond_to?).with(:virtual_path).returns(true)
14
+
15
+ compiled_source = '<mjml><mj-body><mj-text>Hello</mj-text></mj-body></mjml>'
16
+ @handler.stubs(:compile_source).returns(compiled_source)
17
+
18
+ result = @handler.call(template)
19
+
20
+ assert_includes result, '/path/to/template'
21
+ end
22
+
23
+ test 'falls back to identifier when virtual_path is not available' do
24
+ # Simulate ViewComponent::Template::DataWithSource behavior
25
+ template = mock
26
+ template.stubs(:identifier).returns('/path/to/component/template')
27
+ template.stubs(:respond_to?).with(:virtual_path).returns(false)
28
+
29
+ compiled_source = '<mjml><mj-body><mj-text>Hello</mj-text></mj-body></mjml>'
30
+ @handler.stubs(:compile_source).returns(compiled_source)
31
+
32
+ result = @handler.call(template)
33
+
34
+ assert_includes result, '/path/to/component/template'
35
+ end
36
+
37
+ test 'handles partials without mjml root tag' do
38
+ template = mock
39
+ template.stubs(:virtual_path).returns('/path/to/partial')
40
+ template.stubs(:respond_to?).with(:virtual_path).returns(true)
41
+
42
+ # Partial without <mjml> root tag
43
+ compiled_source = '<mj-text>This is a partial</mj-text>'
44
+ @handler.stubs(:compile_source).returns(compiled_source)
45
+
46
+ result = @handler.call(template)
47
+
48
+ # Should return the compiled source as-is for partials
49
+ assert_equal compiled_source, result
50
+ end
51
+
52
+ test 'processes full MJML documents' do
53
+ template = mock
54
+ template.stubs(:virtual_path).returns('/path/to/template')
55
+ template.stubs(:respond_to?).with(:virtual_path).returns(true)
56
+
57
+ compiled_source = '<mjml><mj-body><mj-text>Full document</mj-text></mj-body></mjml>'
58
+ @handler.stubs(:compile_source).returns(compiled_source)
59
+
60
+ result = @handler.call(template)
61
+
62
+ # Should return parser invocation for full MJML documents
63
+ assert_includes result, "Mjml::Parser.new('/path/to/template'"
64
+ assert_includes result, '.render.html_safe'
65
+ end
66
+
67
+ test 'uses MrmlParser when use_mrml is true' do
68
+ Mjml.stubs(:use_mrml).returns(true)
69
+
70
+ template = mock
71
+ template.stubs(:virtual_path).returns('/path/to/template')
72
+ template.stubs(:respond_to?).with(:virtual_path).returns(true)
73
+
74
+ compiled_source = '<mjml><mj-body><mj-text>Full document</mj-text></mj-body></mjml>'
75
+ @handler.stubs(:compile_source).returns(compiled_source)
76
+
77
+ result = @handler.call(template)
78
+
79
+ assert_includes result, "Mjml::MrmlParser.new('/path/to/template'"
80
+ ensure
81
+ Mjml.unstub(:use_mrml)
82
+ end
83
+ end
@@ -3,7 +3,7 @@
3
3
  require 'test_helper'
4
4
 
5
5
  describe Mjml::MrmlParser do
6
- let(:parser) { Mjml::MrmlParser.new(input) }
6
+ let(:parser) { Mjml::MrmlParser.new('test_template', input) }
7
7
 
8
8
  describe '#render' do
9
9
  describe 'when input is valid' do
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.15.0
4
+ version: 4.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Loffler
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qqk2dn/fFE9vdcl9OaOw2Zizne/1VFL/jkzXLqnLgbKD/q129mVCBgw2CKYnQfMN
36
36
  4RwBjPyqnMxWnSq6Ycn7HdFEkgyf2cAxFfH5QtDsjEuca+/LAJMeAQ==
37
37
  -----END CERTIFICATE-----
38
- date: 2025-04-05 00:00:00.000000000 Z
38
+ date: 1980-01-02 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: byebug
@@ -171,6 +171,7 @@ files:
171
171
  - lib/mjml/railtie.rb
172
172
  - lib/mjml/version.rb
173
173
  - test/generator_test.rb
174
+ - test/handler_test.rb
174
175
  - test/mjml_test.rb
175
176
  - test/mrml_parser_test.rb
176
177
  - test/parser_test.rb
@@ -194,11 +195,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
195
  - !ruby/object:Gem::Version
195
196
  version: '0'
196
197
  requirements: []
197
- rubygems_version: 3.6.2
198
+ rubygems_version: 3.6.9
198
199
  specification_version: 4
199
200
  summary: MJML + ERb templates
200
201
  test_files:
201
202
  - test/generator_test.rb
203
+ - test/handler_test.rb
202
204
  - test/mjml_test.rb
203
205
  - test/mrml_parser_test.rb
204
206
  - test/parser_test.rb
metadata.gz.sig CHANGED
Binary file