mjml-ruby 0.3.6 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7814d056c135bbabb9f0554a6721cd1f14fbf40164a1c6e872bc4f78f9938612
4
- data.tar.gz: 3fdcba178c0d33df06bdc12956c3d9b11b67b626996e63b0f2bd6ead3e1dbabf
3
+ metadata.gz: 96c4add1001653162c292dc8b6a9eb99779524e38d55d535ec0cca0254d09ffe
4
+ data.tar.gz: 0420360f77c06f1fb97c918951bdc76acc28bf803278c304664c7a05b53de939
5
5
  SHA512:
6
- metadata.gz: 8c5f594ac30093e702a5ae1b17fcdc9158e0c517e79970ebd0f0f06b488d9d506873490fa264757b64210fc87139ec74f19ea3e3f5684cd5cf0bc4f3767b4f77
7
- data.tar.gz: 0d07e1f0513a737e4c8800afbc64ab083fec039f60836d4e81b07776c6dc8d263dc3f401f9e147f48d2487f34329c6985c0f67ed7610a50b75db2f9f843aaeae
6
+ metadata.gz: cd94cd65669dbd8d8f2a4f923ee0cfc9c58faf46fb657c38017fce48a07267e33697134b3f125272d2f17f81a1f42892dacfdff0be76678880b25c720efb2f80
7
+ data.tar.gz: 964f3295ef5da52ccca28f983e2049e4356652600698e2d054705c317fd1d0e055fa7f83e53956bbebcacc1d7863ea84cc433df16e28beb96171be9fa36a404a
@@ -1,4 +1,3 @@
1
- require 'dry-configurable'
2
1
  require 'mjml/logger'
3
2
  require 'mjml/feature'
4
3
  require 'mjml/parser'
@@ -13,29 +12,32 @@ module MJML
13
12
  VERSION_3_REGEX = /^(\d\.\d\.\d)/i
14
13
  VERSION_4_REGEX = /^mjml-cli: (\d\.\d\.\d)/i
15
14
 
16
- extend Dry::Configurable
17
15
  # Available settings
18
- setting :bin_path
19
- setting :debug
20
- setting :logger
21
- setting :minify_output
22
- setting :validation_level
16
+ module Config
17
+ class << self
18
+ attr_accessor(
19
+ :bin_path,
20
+ :debug,
21
+ :logger,
22
+ :minify_output,
23
+ :validation_level
24
+ )
25
+ end
26
+ end
23
27
 
24
28
  def self.setup!
25
29
  # Init config
26
- configure do |config|
27
- config.bin_path = find_executable
28
- config.debug = nil
29
- config.logger = Logger.setup!(STDOUT)
30
- config.minify_output = false
31
- config.validation_level = :skip
32
- end
30
+ Config.bin_path = find_executable
31
+ Config.debug = nil
32
+ Config.logger = Logger.setup!(STDOUT)
33
+ Config.minify_output = false
34
+ Config.validation_level = :skip
33
35
  end
34
36
 
35
37
  def self.find_executable
36
38
  local_path = File.expand_path('node_modules/.bin/mjml', Dir.pwd)
37
39
  return local_path if File.file?(local_path)
38
- `/usr/bin/env bash -c "which mjml"`.strip
40
+ `/usr/bin/env which mjml`.strip
39
41
  end
40
42
 
41
43
  def self.executable_version
@@ -43,7 +45,7 @@ module MJML
43
45
  end
44
46
 
45
47
  def self.extract_executable_version
46
- ver, _status = Open3.capture2(config.bin_path, '--version')
48
+ ver, _status = Open3.capture2(Config.bin_path, '--version')
47
49
 
48
50
  # mjml 3.x outputs version directly:
49
51
  # 3.3.5
@@ -65,15 +67,16 @@ module MJML
65
67
 
66
68
  match.nil? ? nil : match[1]
67
69
  rescue Errno::ENOENT => _e
68
- raise BinaryNotFound, "mjml binary not found for path '#{config.bin_path}'"
70
+ raise BinaryNotFound, "mjml binary not found for path '#{Config.bin_path}'"
69
71
  end
70
72
 
71
73
  def self.logger
72
- config.logger
74
+ Config.logger
73
75
  end
74
76
  end
75
77
 
76
- MJML.setup!
78
+ # Let Rails take care of the initialization...
79
+ MJML.setup! unless defined?(Rails)
77
80
 
78
81
  require 'tilt/mjml' if defined?(Tilt)
79
82
  require 'sprockets/mjml' if defined?(Sprockets)
@@ -9,14 +9,11 @@ module MJML
9
9
  ROOT_TAGS_REGEX = %r{<mjml.*>.*<\/mjml>}im
10
10
 
11
11
  def initialize
12
- MJML.logger.debug("Path: #{mjml_bin};" \
13
- "Version: #{MJML.executable_version}")
14
12
  raise ExecutableNotFound if MJML.executable_version.nil?
15
13
  end
16
14
 
17
15
  def call(template)
18
- @template = template
19
- exec!
16
+ call!(template)
20
17
  rescue InvalidTemplate
21
18
  nil
22
19
  end
@@ -29,20 +26,21 @@ module MJML
29
26
  private
30
27
 
31
28
  def exec!
32
- MJML.logger.debug("Template:\n #{@template}")
33
29
  raise InvalidTemplate if @template.empty?
34
30
 
35
- MJML.logger.debug("Partial: #{partial?}")
36
31
  return @template if partial?
37
32
 
38
33
  out, err = should_get_outpout_from_file? ? output_from_file : output_from_memory
39
34
  parsed = parse_output(out)
40
35
 
41
- MJML.logger.debug("Output:\n #{parsed[:output]}")
42
36
  MJML.logger.error(err) unless err.empty?
43
37
  MJML.logger.warn(parsed[:warnings]) unless parsed[:warnings].empty?
44
38
 
45
- raise InvalidTemplate unless err.empty?
39
+ unless err.empty?
40
+ message = [err, parsed[:warnings]].reject(&:empty?).join("\n")
41
+ raise InvalidTemplate.new(message)
42
+ end
43
+
46
44
  parsed[:output]
47
45
  end
48
46
 
@@ -51,7 +49,7 @@ module MJML
51
49
  end
52
50
 
53
51
  def mjml_bin
54
- MJML.config.bin_path
52
+ MJML::Config.bin_path
55
53
  end
56
54
 
57
55
  def cmd(file_path = nil)
@@ -67,11 +65,11 @@ module MJML
67
65
  end
68
66
 
69
67
  def minify_output
70
- '--min' if MJML.config.minify_output
68
+ '--min' if MJML::Config.minify_output
71
69
  end
72
70
 
73
71
  def validation_level
74
- "--level=#{MJML.config.validation_level}" if MJML::Feature.available?(:validation_level)
72
+ "--level=#{MJML::Config.validation_level}" if MJML::Feature.available?(:validation_level)
75
73
  end
76
74
 
77
75
  def output_from_file
@@ -103,7 +101,7 @@ module MJML
103
101
  end
104
102
  end
105
103
 
106
- { warnings: warnings.join, output: output.join }
104
+ { warnings: warnings.join("\n"), output: output.join }
107
105
  end
108
106
  end
109
107
  end
@@ -7,10 +7,12 @@ module MJML
7
7
  # Rails plugin for MJML ruby
8
8
  class Railtie < ::Rails::Railtie
9
9
  # Config
10
- config.mjml = MJML.config
10
+ config.mjml = MJML::Config
11
11
 
12
12
  # Initializers
13
13
  initializer 'mjml.register_extension' do
14
+ MJML.setup!
15
+
14
16
  unless Mime::Type.lookup ::MJML::MIME_TYPE
15
17
  Mime::Type.register ::MJML::MIME_TYPE, :mjml
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module MJML
2
- VERSION = '0.3.6'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,37 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mjml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mykola Basov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-15 00:00:00.000000000 Z
11
+ date: 2020-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: dry-configurable
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
20
24
  - - ">="
21
25
  - !ruby/object:Gem::Version
22
- version: 0.1.3
23
- type: :runtime
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6'
34
+ type: :development
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
38
  - - "~>"
28
39
  - !ruby/object:Gem::Version
29
- version: '0.1'
30
- - - ">="
40
+ version: '6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionmailer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
31
46
  - !ruby/object:Gem::Version
32
- version: 0.1.3
47
+ version: '6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6'
33
55
  - !ruby/object:Gem::Dependency
34
- name: rake
56
+ name: tzinfo-data
35
57
  requirement: !ruby/object:Gem::Requirement
36
58
  requirements:
37
59
  - - ">="
@@ -124,7 +146,7 @@ dependencies:
124
146
  - - ">="
125
147
  - !ruby/object:Gem::Version
126
148
  version: '9.0'
127
- description:
149
+ description:
128
150
  email:
129
151
  - kolybasov@gmail.com
130
152
  executables: []
@@ -144,7 +166,7 @@ homepage: https://github.com/kolybasov/mjml-ruby
144
166
  licenses:
145
167
  - MIT
146
168
  metadata: {}
147
- post_install_message: Don't forget to run $ npm install -g mjml@^3.0
169
+ post_install_message:
148
170
  rdoc_options: []
149
171
  require_paths:
150
172
  - lib
@@ -159,8 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
181
  - !ruby/object:Gem::Version
160
182
  version: '0'
161
183
  requirements: []
162
- rubygems_version: 3.1.2
163
- signing_key:
184
+ rubygems_version: 3.1.4
185
+ signing_key:
164
186
  specification_version: 4
165
187
  summary: MJML parser and template engine for Ruby
166
188
  test_files: []