@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
``` ruby
28
28
require ' mrml'
29
29
30
- template = <<-HTML
30
+ mjml = <<-HTML
31
31
<mjml >
32
32
<mj-head >
33
33
<mj-title >Newsletter Title</mj-title >
@@ -43,14 +43,64 @@ template = <<-HTML
43
43
</mjml >
44
44
HTML
45
45
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
48
50
49
- # Generate the preview from mjml
50
- MRML .to_preview(template )
51
+ # Using Template class
52
+ template = MRML :: Template . new (mjml )
51
53
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
54
104
```
55
105
56
106
## Development
@@ -63,7 +113,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
63
113
64
114
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/mrml-ruby .
65
115
66
-
67
116
## License
68
117
69
118
The gem is available as open source under the terms of the [ MIT License] ( https://opensource.org/licenses/MIT ) .
0 commit comments