Module: MJML

Defined in:
lib/mjml.rb,
lib/mjml/parser.rb

Overview

MJML library for ruby

Defined Under Namespace

Modules: Config Classes: BinaryNotFound, Parser

Constant Summary collapse

MIME_TYPE =

Constants

'text/mjml'.freeze
EXTENSION =
'.mjml'.freeze
VERSION_4_REGEX =
/^mjml-cli: (\d+\.\d+\.\d+)/i

Class Method Summary collapse

Class Method Details

.executable_versionObject



32
33
34
# File 'lib/mjml.rb', line 32

def self.executable_version
  @executable_version ||= extract_executable_version
end

.extract_executable_versionObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mjml.rb', line 36

def self.extract_executable_version
  ver, _status = Open3.capture2(Config.bin_path, '--version')
  # mjml 4.x outputs two rows:
  #   mjml-core: 4.0.0
  #   mjml-cli: 4.0.0
  # --> we take the second number as the version, since we call the cli

  match = ver.match(VERSION_4_REGEX)
  match.nil? ? nil : match[1]
rescue Errno::ENOENT => _e
  raise BinaryNotFound, "mjml binary not found for path '#{Config.bin_path}'"
end

.find_executableObject



26
27
28
29
30
# File 'lib/mjml.rb', line 26

def self.find_executable
  local_path = File.expand_path('node_modules/.bin/mjml', Dir.pwd)
  return local_path if File.file?(local_path)
  `/usr/bin/env which mjml`.strip
end

.setup!Object



20
21
22
23
24
# File 'lib/mjml.rb', line 20

def self.setup!
  # Init config
  Config.bin_path = find_executable
  Config.minify_output = false
end