Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#117 Warning about MJML missing when using MRML #118

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/mjml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def self.valid_mjml_binary
check_for_custom_mjml_binary ||
check_for_yarn_mjml_binary ||
check_for_npm_mjml_binary ||
check_for_global_mjml_binary
check_for_global_mjml_binary ||
check_for_mrml_binary

return @@valid_mjml_binary if @@valid_mjml_binary

Expand Down Expand Up @@ -102,6 +103,13 @@ def self.check_for_global_mjml_binary
return mjml_bin if mjml_bin.present? && check_version(mjml_bin)
end

def self.check_for_mrml_binary
MRML.present?
rescue NameError
Mjml.mjml_binary_error_string = 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
false
end

def self.discover_mjml_bin
logger.warn('`Mjml.discover_mjml_bin` is deprecated and has no effect anymore! ' \
'Please use `Mjml.mjml_binary=` to set a custom MJML binary.')
Expand Down
16 changes: 16 additions & 0 deletions test/mjml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ class NotifierMailerTest < ActiveSupport::TestCase
before do
Mjml.mjml_binary = nil
Mjml.valid_mjml_binary = nil
Mjml.use_mrml = nil
end

after do
Mjml.mjml_binary = nil
Mjml.valid_mjml_binary = nil
Mjml.use_mrml = nil
end

it 'can be set to a custom value with mjml_binary if version is correct' do
Expand Down Expand Up @@ -156,5 +158,19 @@ class NotifierMailerTest < ActiveSupport::TestCase
assert(err.message.start_with?("MJML.mjml_binary is set to 'set by mjml_binary' " \
'but MJML-Rails could not validate that it is a valid MJML binary'))
end

it 'can use MRML and check for a valid binary' do
Mjml.use_mrml = true
Mjml.stubs(:check_for_custom_mjml_binary).returns(false)
Mjml.stubs(:check_for_yarn_mjml_binary).returns(false)
Mjml.stubs(:check_for_npm_mjml_binary).returns(false)
Mjml.stubs(:check_for_global_mjml_binary).returns(false)
expect(Mjml.valid_mjml_binary).must_equal(true)

Mjml.valid_mjml_binary = nil
MRML.stubs(:present?).raises(NameError)
assert_nil(Mjml.valid_mjml_binary)
expect(Mjml.mjml_binary_error_string).must_equal 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?'
end
end
end