Class: MRML::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/mrml/template.rb

Overview

Template object implemented in Rust that can parse MJML templates.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mjml) ⇒ Template

A new instance of Template.

Parameters:

  • mjml (String)

Raises:

  • (Error)

    if mjml is not a valid template



# File 'lib/mrml/template.rb', line 26

Instance Attribute Details

#previewString (readonly)

Gets mj-preview tag value.

Returns:

  • (String)


# File 'lib/mrml/template.rb', line 36

#titleString (readonly)

Gets mj-title tag value.

Returns:

  • (String)


# File 'lib/mrml/template.rb', line 32

Class Method Details

.from_hash(hash) ⇒ Template

A new instance of Template from Hash.

Parameters:

  • hash (Hash)

Returns:

Raises:

  • (Error)

    if hash has invalid format



21
22
23
# File 'lib/mrml/template.rb', line 21

def from_hash(hash)
  from_json(JSON.generate(hash))
end

.from_json(json) ⇒ Template

A new instance of Template from JSON.

Parameters:

  • json (String)

Returns:

Raises:

  • (Error)

    if json has invalid format



# File 'lib/mrml/template.rb', line 9

Instance Method Details

#to_hashHash

Hash representation of the template.

Returns:

  • (Hash)


55
56
57
# File 'lib/mrml/template.rb', line 55

def to_hash
  JSON.parse(to_json)
end

#to_htmlString

HTML representation of the template.

Returns:

  • (String)


# File 'lib/mrml/template.rb', line 48

#to_jsonString

JSON representation of the template.

Returns:

  • (String)


# File 'lib/mrml/template.rb', line 44

#to_mjmlString

MJML representation of the template.

Returns:

  • (String)


# File 'lib/mrml/template.rb', line 40