Class: Mjml::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/mjml/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Parser

Create new parser

Parameters:

  • input (String)

    The string to transform in html



7
8
9
10
11
# File 'lib/mjml/parser.rb', line 7

def initialize input
  file = File.open(in_tmp_file, 'w')
  file.write(input)
  file.close
end

Instance Method Details

#renderString

Render mjml template

Returns:

  • (String)


16
17
18
19
20
21
22
23
# File 'lib/mjml/parser.rb', line 16

def render
  result = run
  remove_tmp_files
  result
rescue

  ""
end

#runString

Exec mjml command

Returns:

  • (String)

    The result as string



28
29
30
31
32
33
34
35
36
# File 'lib/mjml/parser.rb', line 28

def run
  command = "#{mjml_bin} -r #{in_tmp_file} -o #{out_tmp_file}"
  # puts command
  `#{command}`
  file = File.open(out_tmp_file, 'r')
  str  = file.read
  file.close
  str
end