Module: MRML

Defined in:
lib/mrml.rb,
lib/mrml/error.rb,
lib/mrml/version.rb,
lib/mrml/template.rb

Overview

Module that renders MJML templates into HTML/JSON using MRML, a reimplementation of the MJML markup language in Rust.

Defined Under Namespace

Classes: Error, Template

Constant Summary collapse

VERSION =
'1.6.2'

Class Method Summary collapse

Class Method Details

.to_hash(mjml) ⇒ Hash

Render template as Hash.

Parameters:

  • mjml (String)

Returns:

  • (Hash)

Raises:

  • (Error)

    if mjml is not a valid template



47
48
49
50
51
52
# File 'lib/mrml.rb', line 47

def to_hash(mjml)
  return if mjml.nil?

  template = Template.new(mjml)
  template.to_hash
end

.to_html(mjml) ⇒ String

Render template as HTML.

Parameters:

  • mjml (String)

Returns:

  • (String)

Raises:

  • (Error)

    if mjml is not a valid template



23
24
25
26
27
28
# File 'lib/mrml.rb', line 23

def to_html(mjml)
  return if mjml.nil?

  template = Template.new(mjml)
  template.to_html
end

.to_json(mjml) ⇒ String

Render template as JSON.

Parameters:

  • mjml (String)

Returns:

  • (String)

Raises:

  • (Error)

    if mjml is not a valid template



35
36
37
38
39
40
# File 'lib/mrml.rb', line 35

def to_json(mjml)
  return if mjml.nil?

  template = Template.new(mjml)
  template.to_json
end