Class: Mjml::MrmlParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path, input) ⇒ MrmlParser

Create new parser

Parameters:

  • template_path (String)

    The path to the .mjml file

  • input (String)

    The string to transform in html



11
12
13
14
15
# File 'lib/mjml/mrml_parser.rb', line 11

def initialize(template_path, input)
  @template_path = template_path
  @input         = input
  @with_cache    = Cache.new(template_path)
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



5
6
7
# File 'lib/mjml/mrml_parser.rb', line 5

def input
  @input
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



5
6
7
# File 'lib/mjml/mrml_parser.rb', line 5

def template_path
  @template_path
end

Instance Method Details

#renderString

Render mjml template

Returns:

  • (String)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mjml/mrml_parser.rb', line 20

def render
  @with_cache.cache do
    MRML.to_html(input)
  rescue NameError
    Mjml.logger.fatal('MRML is not installed. Please add `gem "mrml"` to your Gemfile.')
    raise
  rescue StandardError
    raise if Mjml.raise_render_exception

    ''
  end
end