module Mjml
Constants
- VERSION
Version number no longer matches MJML.io version
Attributes
logger[W]
Public Class Methods
check_for_custom_mjml_binary()
click to toggle source
# File lib/mjml.rb, line 60 def self.check_for_custom_mjml_binary if const_defined?('BIN') && Mjml::BIN.present? logger.warn('Setting `Mjml::BIN` is deprecated and will be removed in a future version! ' \ 'Please use `Mjml.mjml_binary=` instead.') self.mjml_binary = Mjml::BIN remove_const 'BIN' end return if mjml_binary.blank? return mjml_binary if check_version(mjml_binary) 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.' end
check_for_global_mjml_binary()
click to toggle source
# File lib/mjml.rb, line 97 def self.check_for_global_mjml_binary stdout, _, status = Open3.capture3('which mjml') return unless status.success? mjml_bin = stdout.chomp return mjml_bin if mjml_bin.present? && check_version(mjml_bin) end
check_for_mjml_package(package_manager, bin_command, binary_path)
click to toggle source
# File lib/mjml.rb, line 76 def self.check_for_mjml_package(package_manager, bin_command, binary_path) stdout, _, status = Open3.capture3("which #{package_manager}") return unless status.success? pm_bin = stdout.chomp stdout, _, status = Open3.capture3("#{pm_bin} #{bin_command}") return unless status.success? mjml_bin = File.join(stdout.chomp, *binary_path) return mjml_bin if check_version(mjml_bin) rescue Errno::ENOENT # package manager is not installed nil end
check_for_mrml_binary()
click to toggle source
# File lib/mjml.rb, line 105 def self.check_for_mrml_binary return unless Mjml.use_mrml MRML.present? rescue NameError Mjml.mjml_binary_error_string = 'Couldn\'t find MRML - did you add \'mrml\' to your Gemfile?' false end
check_for_package_mjml_binary()
click to toggle source
# File lib/mjml.rb, line 91 def self.check_for_package_mjml_binary check_for_mjml_package('bun', 'pm bin', ['mjml']) || check_for_mjml_package('npm', 'root', ['.bin', 'mjml']) || check_for_mjml_package('yarn', 'bin mjml', []) end
check_version(bin)
click to toggle source
# File lib/mjml.rb, line 37 def self.check_version(bin) stdout, _, status = run_mjml('--version', mjml_bin: bin) status.success? && stdout.include?("mjml-core: #{Mjml.mjml_binary_version_supported}") rescue StandardError false end
discover_mjml_bin()
click to toggle source
# File lib/mjml.rb, line 114 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.') end
logger()
click to toggle source
# File lib/mjml.rb, line 126 def logger @logger ||= Logger.new($stdout).tap do |log| log.progname = name end end
run_mjml(args, mjml_bin: valid_mjml_binary)
click to toggle source
# File lib/mjml.rb, line 44 def self.run_mjml(args, mjml_bin: valid_mjml_binary) Open3.capture3("#{mjml_bin} #{args}") end
setup() { |self| ... }
click to toggle source
# File lib/mjml.rb, line 119 def self.setup yield self if block_given? end
valid_mjml_binary()
click to toggle source
# File lib/mjml.rb, line 48 def self.valid_mjml_binary self.valid_mjml_binary = @@valid_mjml_binary || check_for_custom_mjml_binary || check_for_package_mjml_binary || check_for_global_mjml_binary || check_for_mrml_binary return @@valid_mjml_binary if @@valid_mjml_binary puts Mjml.mjml_binary_error_string end