Skip to content

Commit

Permalink
Merge pull request #11 from doits/fix_version_check
Browse files Browse the repository at this point in the history
make version check for both mjml 4 and 3
  • Loading branch information
m-basov authored Feb 27, 2018
2 parents 23e3c15 + dd256f6 commit 7a755a2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/mjml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module MJML
# Constants
MIME_TYPE = 'text/mjml'.freeze
EXTENSION = '.mjml'.freeze
VERSION_REGEX = /^\d\.\d\.\d/i
VERSION_3_REGEX = /^(\d\.\d\.\d)/i
VERSION_4_REGEX = /^mjml-cli: (\d\.\d\.\d)/i

extend Dry::Configurable
# Available settings
Expand Down Expand Up @@ -41,7 +42,26 @@ def self.executable_version

def self.extract_executable_version
ver, _status = Open3.capture2(config.bin_path, '-V')
(ver =~ VERSION_REGEX).nil? ? nil : ver

# mjml 3.x outputs version directly:
# 3.3.5
# --> just take this as the 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

case ver.count("\n")
when 1
# one line, mjml 3.x
match = ver.match(VERSION_3_REGEX)
when 2
# two lines, might be 4.x
match = ver.match(VERSION_4_REGEX)
end

match.nil? ? nil : match[1]
end

def self.logger
Expand Down

0 comments on commit 7a755a2

Please sign in to comment.