diff --git a/lib/mjml.rb b/lib/mjml.rb index d8c7b54..4149803 100644 --- a/lib/mjml.rb +++ b/lib/mjml.rb @@ -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 @@ -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.') diff --git a/test/mjml_test.rb b/test/mjml_test.rb index 0281629..1af85b4 100644 --- a/test/mjml_test.rb +++ b/test/mjml_test.rb @@ -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 @@ -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