Skip to content

Commit 1b17861

Browse files
committed
update readme
1 parent 8e7f771 commit 1b17861

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

README.md

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Or install it yourself as:
2727
```ruby
2828
require 'mrml'
2929

30-
template = <<-HTML
30+
mjml = <<-HTML
3131
<mjml>
3232
<mj-head>
3333
<mj-title>Newsletter Title</mj-title>
@@ -43,14 +43,64 @@ template = <<-HTML
4343
</mjml>
4444
HTML
4545

46-
# Generate the title from mjml
47-
MRML.to_title(template)
46+
# Using module methods
47+
MRML.to_html(mjml) # Generate html from mjml
48+
MRML.to_json(mjml) # Generate json from mjml
49+
MRML.to_hash(mjml) # Generate hash from mjml
4850

49-
# Generate the preview from mjml
50-
MRML.to_preview(template)
51+
# Using Template class
52+
template = MRML::Template.new(mjml)
5153

52-
# Generate the html from mjml
53-
MRML.to_html(template)
54+
template.title # Get template title
55+
template.preview # Get template preview
56+
57+
template.to_html # Render as html
58+
template.to_json # Render as json
59+
template.to_hash # Render as hash
60+
```
61+
62+
```ruby
63+
require 'mrml'
64+
65+
json = <<-JSON
66+
{
67+
"type": "mjml",
68+
"children": [{
69+
"type": "mj-head",
70+
"children": [{
71+
"type": "mj-title",
72+
"children": "Newsletter Title"
73+
}, {
74+
"type": "mj-preview",
75+
"children": "Newsletter Preview"
76+
}]
77+
}, {
78+
"type": "mj-body",
79+
"children": [{
80+
"type": "mj-section",
81+
"children": [{
82+
"type": "mj-column",
83+
"children": [{
84+
"type": "mj-text",
85+
"attributes": {
86+
"font-size": "20px",
87+
"color": "#F45E43",
88+
"font-family": "helvetica"
89+
},
90+
"children": ["Hello World"]
91+
}]
92+
}]
93+
}]
94+
}]
95+
}
96+
JSON
97+
98+
# Create Template from JSON
99+
template = MRML::Template.from_json(json)
100+
101+
template.to_html # Render as html
102+
template.to_json # Render as json
103+
template.to_hash # Render as hash
54104
```
55105

56106
## Development
@@ -63,7 +113,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
63113

64114
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/mrml-ruby.
65115

66-
67116
## License
68117

69118
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)