mrml 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 774d9cf97d15b8c4c4f81d2819e93700e13e465481480ac5eedcee56ce4da73e
4
- data.tar.gz: 19f950b1df89858456cca38e5bd456f766177accdcc5ce417357ae97cd4e4add
3
+ metadata.gz: 8d8e39cf3257d1d67531f0c41b8c325c3c7c87736c99d6b6401c56671b56f7a2
4
+ data.tar.gz: 11d3651729b61bbaf4c0897e136474d404e1c24bb86ccb8382ef494eb89f31e1
5
5
  SHA512:
6
- metadata.gz: c1a3dab371786b805f9c889d8fa30796752b6195a572be8f93935706e6e036d3e4063f01f97c84f0d6a8c9b8e1b047aff0ec4ad67f93450b927c097e6e889d7a
7
- data.tar.gz: 5c39b4e44c057a59bcaf08932396f4fe60a9943d290457f9ff3a63847a4a964ff42f050e446dde1d4ac38d1a7efff9cba2bd9ffbf675eff95e9c42e9e234a807
6
+ metadata.gz: b782c0da76a5fe45ac4b83374b84182e8b43136cdd5cdf650952a0f4413e67646f7ae73e104f1164b094bf4634e9562698bfd1c81f70206dcbc5c27f3e345842
7
+ data.tar.gz: 3f11a9e850dc757657259326e312aeb3ceabde71de3afdd0b5cf837f248747144689faaa3fe5fed30d438bdca2526852a4d8bc76b529f59cada7805f340ec208
@@ -0,0 +1,37 @@
1
+ # Code of Conduct
2
+
3
+ All participants of this project are expected to abide by our Code of Conduct, both online and during in-person events that are hosted and/or associated with this project.
4
+
5
+ ## The Pledge
6
+
7
+ In the interest of fostering an open and welcoming environment, we pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
8
+
9
+ ## The Standards
10
+
11
+ Examples of behavior that contributes to creating a positive environment include:
12
+
13
+ * Using welcoming and inclusive language
14
+ * Being respectful of differing viewpoints and experiences
15
+ * Referring to people by their preferred pronouns and using gender-neutral pronouns when uncertain
16
+ * Gracefully accepting constructive criticism
17
+ * Focusing on what is best for the community
18
+ * Showing empathy towards other community members
19
+
20
+ Examples of unacceptable behavior by participants include:
21
+
22
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
23
+ * Trolling, insulting/derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
26
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
27
+ * Dismissing or attacking inclusion-oriented requests
28
+
29
+ ## Enforcement
30
+
31
+ Violations of the Code of Conduct may be reported by sending an email to info@hardpixel.eu. All reports will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Further details of specific enforcement policies may be posted separately.
32
+
33
+ We hold the right and responsibility to remove comments or other contributions that are not aligned to this Code of Conduct, or to suspend temporarily or permanently any members for other behaviors that are inappropriate, threatening, offensive, or harmful.
34
+
35
+ ## Attribution
36
+
37
+ This Code of Conduct is adapted from [dev.to](https://dev.to/code-of-conduct).
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Ruby wrapper for [MRML](https://github.com/jdrouet/mrml), the [MJML](https://mjml.io) markup language implementation in Rust. Rust must be available on your system to install this gem.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/mrml.svg)](https://badge.fury.io/rb/mrml)
6
- [![Build Status](https://travis-ci.org/hardpixel/mrml-ruby.svg?branch=master)](https://travis-ci.org/hardpixel/mrml-ruby)
6
+ [![Build](https://github.com/hardpixel/mrml-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/hardpixel/mrml-ruby/actions/workflows/build.yml)
7
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/7e307214d3c2e4d2056d/maintainability)](https://codeclimate.com/github/hardpixel/mrml-ruby/maintainability)
8
8
 
9
9
  ## Installation
@@ -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,0 +1,548 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "0.7.18"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "ansi_term"
16
+ version = "0.12.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
19
+ dependencies = [
20
+ "winapi",
21
+ ]
22
+
23
+ [[package]]
24
+ name = "atty"
25
+ version = "0.2.14"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
28
+ dependencies = [
29
+ "hermit-abi",
30
+ "libc",
31
+ "winapi",
32
+ ]
33
+
34
+ [[package]]
35
+ name = "bindgen"
36
+ version = "0.59.2"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8"
39
+ dependencies = [
40
+ "bitflags",
41
+ "cexpr",
42
+ "clang-sys",
43
+ "clap",
44
+ "env_logger",
45
+ "lazy_static",
46
+ "lazycell",
47
+ "log",
48
+ "peeking_take_while",
49
+ "proc-macro2",
50
+ "quote",
51
+ "regex",
52
+ "rustc-hash",
53
+ "shlex",
54
+ "which",
55
+ ]
56
+
57
+ [[package]]
58
+ name = "bitflags"
59
+ version = "1.3.2"
60
+ source = "registry+https://github.com/rust-lang/crates.io-index"
61
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
62
+
63
+ [[package]]
64
+ name = "cexpr"
65
+ version = "0.6.0"
66
+ source = "registry+https://github.com/rust-lang/crates.io-index"
67
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
68
+ dependencies = [
69
+ "nom",
70
+ ]
71
+
72
+ [[package]]
73
+ name = "cfg-if"
74
+ version = "1.0.0"
75
+ source = "registry+https://github.com/rust-lang/crates.io-index"
76
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
77
+
78
+ [[package]]
79
+ name = "clang-sys"
80
+ version = "1.3.3"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b"
83
+ dependencies = [
84
+ "glob",
85
+ "libc",
86
+ "libloading",
87
+ ]
88
+
89
+ [[package]]
90
+ name = "clap"
91
+ version = "2.34.0"
92
+ source = "registry+https://github.com/rust-lang/crates.io-index"
93
+ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
94
+ dependencies = [
95
+ "ansi_term",
96
+ "atty",
97
+ "bitflags",
98
+ "strsim 0.8.0",
99
+ "textwrap",
100
+ "unicode-width",
101
+ "vec_map",
102
+ ]
103
+
104
+ [[package]]
105
+ name = "darling"
106
+ version = "0.13.4"
107
+ source = "registry+https://github.com/rust-lang/crates.io-index"
108
+ checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
109
+ dependencies = [
110
+ "darling_core",
111
+ "darling_macro",
112
+ ]
113
+
114
+ [[package]]
115
+ name = "darling_core"
116
+ version = "0.13.4"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
119
+ dependencies = [
120
+ "fnv",
121
+ "ident_case",
122
+ "proc-macro2",
123
+ "quote",
124
+ "strsim 0.10.0",
125
+ "syn",
126
+ ]
127
+
128
+ [[package]]
129
+ name = "darling_macro"
130
+ version = "0.13.4"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
133
+ dependencies = [
134
+ "darling_core",
135
+ "quote",
136
+ "syn",
137
+ ]
138
+
139
+ [[package]]
140
+ name = "either"
141
+ version = "1.8.0"
142
+ source = "registry+https://github.com/rust-lang/crates.io-index"
143
+ checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
144
+
145
+ [[package]]
146
+ name = "env_logger"
147
+ version = "0.9.0"
148
+ source = "registry+https://github.com/rust-lang/crates.io-index"
149
+ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
150
+ dependencies = [
151
+ "atty",
152
+ "humantime",
153
+ "log",
154
+ "regex",
155
+ "termcolor",
156
+ ]
157
+
158
+ [[package]]
159
+ name = "fnv"
160
+ version = "1.0.7"
161
+ source = "registry+https://github.com/rust-lang/crates.io-index"
162
+ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
163
+
164
+ [[package]]
165
+ name = "getrandom"
166
+ version = "0.2.7"
167
+ source = "registry+https://github.com/rust-lang/crates.io-index"
168
+ checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
169
+ dependencies = [
170
+ "cfg-if",
171
+ "libc",
172
+ "wasi",
173
+ ]
174
+
175
+ [[package]]
176
+ name = "glob"
177
+ version = "0.3.0"
178
+ source = "registry+https://github.com/rust-lang/crates.io-index"
179
+ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
180
+
181
+ [[package]]
182
+ name = "hermit-abi"
183
+ version = "0.1.19"
184
+ source = "registry+https://github.com/rust-lang/crates.io-index"
185
+ checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
186
+ dependencies = [
187
+ "libc",
188
+ ]
189
+
190
+ [[package]]
191
+ name = "humantime"
192
+ version = "2.1.0"
193
+ source = "registry+https://github.com/rust-lang/crates.io-index"
194
+ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
195
+
196
+ [[package]]
197
+ name = "ident_case"
198
+ version = "1.0.1"
199
+ source = "registry+https://github.com/rust-lang/crates.io-index"
200
+ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
201
+
202
+ [[package]]
203
+ name = "itoa"
204
+ version = "1.0.3"
205
+ source = "registry+https://github.com/rust-lang/crates.io-index"
206
+ checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
207
+
208
+ [[package]]
209
+ name = "lazy_static"
210
+ version = "1.4.0"
211
+ source = "registry+https://github.com/rust-lang/crates.io-index"
212
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
213
+
214
+ [[package]]
215
+ name = "lazycell"
216
+ version = "1.3.0"
217
+ source = "registry+https://github.com/rust-lang/crates.io-index"
218
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
219
+
220
+ [[package]]
221
+ name = "libc"
222
+ version = "0.2.132"
223
+ source = "registry+https://github.com/rust-lang/crates.io-index"
224
+ checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
225
+
226
+ [[package]]
227
+ name = "libloading"
228
+ version = "0.7.3"
229
+ source = "registry+https://github.com/rust-lang/crates.io-index"
230
+ checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
231
+ dependencies = [
232
+ "cfg-if",
233
+ "winapi",
234
+ ]
235
+
236
+ [[package]]
237
+ name = "log"
238
+ version = "0.4.17"
239
+ source = "registry+https://github.com/rust-lang/crates.io-index"
240
+ checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
241
+ dependencies = [
242
+ "cfg-if",
243
+ ]
244
+
245
+ [[package]]
246
+ name = "magnus"
247
+ version = "0.3.2"
248
+ source = "registry+https://github.com/rust-lang/crates.io-index"
249
+ checksum = "983e15338a2e9644f804de8b5e52fb930bcd53b6859de4f4feb85753532b69d3"
250
+ dependencies = [
251
+ "bindgen",
252
+ "magnus-macros",
253
+ ]
254
+
255
+ [[package]]
256
+ name = "magnus-macros"
257
+ version = "0.1.0"
258
+ source = "registry+https://github.com/rust-lang/crates.io-index"
259
+ checksum = "27968fcabe2ef7e35b8331d71a62882282996f6222c133c0255cf7f33b8d9b48"
260
+ dependencies = [
261
+ "darling",
262
+ "proc-macro2",
263
+ "quote",
264
+ "syn",
265
+ ]
266
+
267
+ [[package]]
268
+ name = "memchr"
269
+ version = "2.5.0"
270
+ source = "registry+https://github.com/rust-lang/crates.io-index"
271
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
272
+
273
+ [[package]]
274
+ name = "minimal-lexical"
275
+ version = "0.2.1"
276
+ source = "registry+https://github.com/rust-lang/crates.io-index"
277
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
278
+
279
+ [[package]]
280
+ name = "mrml"
281
+ version = "0.1.0"
282
+ dependencies = [
283
+ "magnus",
284
+ "mrml 1.2.10",
285
+ "serde",
286
+ "serde_json",
287
+ ]
288
+
289
+ [[package]]
290
+ name = "mrml"
291
+ version = "1.2.10"
292
+ source = "registry+https://github.com/rust-lang/crates.io-index"
293
+ checksum = "b2fd038a54a4b1d0c40c4cea5a1dfc6841ab4824b88f221d197e95a62efc2afc"
294
+ dependencies = [
295
+ "rand",
296
+ "serde",
297
+ "serde_json",
298
+ "xmlparser",
299
+ ]
300
+
301
+ [[package]]
302
+ name = "nom"
303
+ version = "7.1.1"
304
+ source = "registry+https://github.com/rust-lang/crates.io-index"
305
+ checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
306
+ dependencies = [
307
+ "memchr",
308
+ "minimal-lexical",
309
+ ]
310
+
311
+ [[package]]
312
+ name = "peeking_take_while"
313
+ version = "0.1.2"
314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
315
+ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
316
+
317
+ [[package]]
318
+ name = "ppv-lite86"
319
+ version = "0.2.16"
320
+ source = "registry+https://github.com/rust-lang/crates.io-index"
321
+ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
322
+
323
+ [[package]]
324
+ name = "proc-macro2"
325
+ version = "1.0.43"
326
+ source = "registry+https://github.com/rust-lang/crates.io-index"
327
+ checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
328
+ dependencies = [
329
+ "unicode-ident",
330
+ ]
331
+
332
+ [[package]]
333
+ name = "quote"
334
+ version = "1.0.21"
335
+ source = "registry+https://github.com/rust-lang/crates.io-index"
336
+ checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
337
+ dependencies = [
338
+ "proc-macro2",
339
+ ]
340
+
341
+ [[package]]
342
+ name = "rand"
343
+ version = "0.8.5"
344
+ source = "registry+https://github.com/rust-lang/crates.io-index"
345
+ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
346
+ dependencies = [
347
+ "libc",
348
+ "rand_chacha",
349
+ "rand_core",
350
+ ]
351
+
352
+ [[package]]
353
+ name = "rand_chacha"
354
+ version = "0.3.1"
355
+ source = "registry+https://github.com/rust-lang/crates.io-index"
356
+ checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
357
+ dependencies = [
358
+ "ppv-lite86",
359
+ "rand_core",
360
+ ]
361
+
362
+ [[package]]
363
+ name = "rand_core"
364
+ version = "0.6.3"
365
+ source = "registry+https://github.com/rust-lang/crates.io-index"
366
+ checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
367
+ dependencies = [
368
+ "getrandom",
369
+ ]
370
+
371
+ [[package]]
372
+ name = "regex"
373
+ version = "1.6.0"
374
+ source = "registry+https://github.com/rust-lang/crates.io-index"
375
+ checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
376
+ dependencies = [
377
+ "aho-corasick",
378
+ "memchr",
379
+ "regex-syntax",
380
+ ]
381
+
382
+ [[package]]
383
+ name = "regex-syntax"
384
+ version = "0.6.27"
385
+ source = "registry+https://github.com/rust-lang/crates.io-index"
386
+ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
387
+
388
+ [[package]]
389
+ name = "rustc-hash"
390
+ version = "1.1.0"
391
+ source = "registry+https://github.com/rust-lang/crates.io-index"
392
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
393
+
394
+ [[package]]
395
+ name = "ryu"
396
+ version = "1.0.11"
397
+ source = "registry+https://github.com/rust-lang/crates.io-index"
398
+ checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
399
+
400
+ [[package]]
401
+ name = "serde"
402
+ version = "1.0.144"
403
+ source = "registry+https://github.com/rust-lang/crates.io-index"
404
+ checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"
405
+ dependencies = [
406
+ "serde_derive",
407
+ ]
408
+
409
+ [[package]]
410
+ name = "serde_derive"
411
+ version = "1.0.144"
412
+ source = "registry+https://github.com/rust-lang/crates.io-index"
413
+ checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
414
+ dependencies = [
415
+ "proc-macro2",
416
+ "quote",
417
+ "syn",
418
+ ]
419
+
420
+ [[package]]
421
+ name = "serde_json"
422
+ version = "1.0.85"
423
+ source = "registry+https://github.com/rust-lang/crates.io-index"
424
+ checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
425
+ dependencies = [
426
+ "itoa",
427
+ "ryu",
428
+ "serde",
429
+ ]
430
+
431
+ [[package]]
432
+ name = "shlex"
433
+ version = "1.1.0"
434
+ source = "registry+https://github.com/rust-lang/crates.io-index"
435
+ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
436
+
437
+ [[package]]
438
+ name = "strsim"
439
+ version = "0.8.0"
440
+ source = "registry+https://github.com/rust-lang/crates.io-index"
441
+ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
442
+
443
+ [[package]]
444
+ name = "strsim"
445
+ version = "0.10.0"
446
+ source = "registry+https://github.com/rust-lang/crates.io-index"
447
+ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
448
+
449
+ [[package]]
450
+ name = "syn"
451
+ version = "1.0.99"
452
+ source = "registry+https://github.com/rust-lang/crates.io-index"
453
+ checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
454
+ dependencies = [
455
+ "proc-macro2",
456
+ "quote",
457
+ "unicode-ident",
458
+ ]
459
+
460
+ [[package]]
461
+ name = "termcolor"
462
+ version = "1.1.3"
463
+ source = "registry+https://github.com/rust-lang/crates.io-index"
464
+ checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
465
+ dependencies = [
466
+ "winapi-util",
467
+ ]
468
+
469
+ [[package]]
470
+ name = "textwrap"
471
+ version = "0.11.0"
472
+ source = "registry+https://github.com/rust-lang/crates.io-index"
473
+ checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
474
+ dependencies = [
475
+ "unicode-width",
476
+ ]
477
+
478
+ [[package]]
479
+ name = "unicode-ident"
480
+ version = "1.0.3"
481
+ source = "registry+https://github.com/rust-lang/crates.io-index"
482
+ checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
483
+
484
+ [[package]]
485
+ name = "unicode-width"
486
+ version = "0.1.9"
487
+ source = "registry+https://github.com/rust-lang/crates.io-index"
488
+ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
489
+
490
+ [[package]]
491
+ name = "vec_map"
492
+ version = "0.8.2"
493
+ source = "registry+https://github.com/rust-lang/crates.io-index"
494
+ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
495
+
496
+ [[package]]
497
+ name = "wasi"
498
+ version = "0.11.0+wasi-snapshot-preview1"
499
+ source = "registry+https://github.com/rust-lang/crates.io-index"
500
+ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
501
+
502
+ [[package]]
503
+ name = "which"
504
+ version = "4.2.5"
505
+ source = "registry+https://github.com/rust-lang/crates.io-index"
506
+ checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae"
507
+ dependencies = [
508
+ "either",
509
+ "lazy_static",
510
+ "libc",
511
+ ]
512
+
513
+ [[package]]
514
+ name = "winapi"
515
+ version = "0.3.9"
516
+ source = "registry+https://github.com/rust-lang/crates.io-index"
517
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
518
+ dependencies = [
519
+ "winapi-i686-pc-windows-gnu",
520
+ "winapi-x86_64-pc-windows-gnu",
521
+ ]
522
+
523
+ [[package]]
524
+ name = "winapi-i686-pc-windows-gnu"
525
+ version = "0.4.0"
526
+ source = "registry+https://github.com/rust-lang/crates.io-index"
527
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
528
+
529
+ [[package]]
530
+ name = "winapi-util"
531
+ version = "0.1.5"
532
+ source = "registry+https://github.com/rust-lang/crates.io-index"
533
+ checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
534
+ dependencies = [
535
+ "winapi",
536
+ ]
537
+
538
+ [[package]]
539
+ name = "winapi-x86_64-pc-windows-gnu"
540
+ version = "0.4.0"
541
+ source = "registry+https://github.com/rust-lang/crates.io-index"
542
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
543
+
544
+ [[package]]
545
+ name = "xmlparser"
546
+ version = "0.13.3"
547
+ source = "registry+https://github.com/rust-lang/crates.io-index"
548
+ checksum = "114ba2b24d2167ef6d67d7d04c8cc86522b87f490025f39f0303b7db5bf5e3d8"
@@ -4,10 +4,16 @@ version = "0.1.0"
4
4
  authors = ["Jonian Guveli <jonian@hardpixel.eu>"]
5
5
  edition = "2018"
6
6
 
7
- # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
7
  [dependencies]
9
8
  mrml = "1.2.10"
10
- serde = { version = "1.0", features = ["derive"] }
9
+ magnus = "0.3"
10
+
11
+ [dependencies.serde]
12
+ version = "1.0"
13
+ features = ["derive"]
14
+
15
+ [dependencies.serde_json]
16
+ version = "1.0"
11
17
 
12
18
  [lib]
13
19
  name = "mrml"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+ require 'rb_sys/mkmf'
5
+
6
+ create_rust_makefile('mrml/mrml')
@@ -0,0 +1,92 @@
1
+ use magnus::{
2
+ class, define_module, function, method,
3
+ prelude::*, gc::register_mark_object, memoize,
4
+ Error, ExceptionClass, RClass, RModule
5
+ };
6
+
7
+ use mrml::mjml::MJML;
8
+ use mrml::prelude::print::Print;
9
+ use mrml::prelude::render::Options;
10
+
11
+ fn mrml_error() -> ExceptionClass {
12
+ *memoize!(ExceptionClass: {
13
+ let ex: RClass = class::object().const_get::<_, RModule>("MRML").unwrap().const_get("Error").unwrap();
14
+ register_mark_object(ex);
15
+
16
+ ExceptionClass::from_value(*ex).unwrap()
17
+ })
18
+ }
19
+
20
+ #[magnus::wrap(class = "MRML::Template", free_immediatly, size)]
21
+ struct Template {
22
+ res: MJML
23
+ }
24
+
25
+ impl Template {
26
+ fn new(input: String) -> Result<Self, Error> {
27
+ match mrml::parse(&input) {
28
+ Ok(res) => Ok(Self { res }),
29
+ Err(ex) => Err(Error::new(mrml_error(), ex.to_string()))
30
+ }
31
+ }
32
+
33
+ fn from_json(input: String) -> Result<Self, Error> {
34
+ match serde_json::from_str::<MJML>(&input) {
35
+ Ok(res) => Ok(Self { res }),
36
+ Err(ex) => Err(Error::new(mrml_error(), ex.to_string()))
37
+ }
38
+ }
39
+
40
+ fn get_title(&self) -> Option<String> {
41
+ self.res.get_title()
42
+ }
43
+
44
+ fn get_preview(&self) -> Option<String> {
45
+ self.res.get_preview()
46
+ }
47
+
48
+ fn to_mjml(&self) -> String {
49
+ self.res.dense_print()
50
+ }
51
+
52
+ fn to_json(&self) -> Result<String, Error> {
53
+ match serde_json::to_string(&self.res) {
54
+ Ok(res) => Ok(res),
55
+ Err(ex) => Err(Error::new(mrml_error(), ex.to_string()))
56
+ }
57
+ }
58
+
59
+ fn to_html(&self) -> Result<String, Error> {
60
+ match self.res.render(&Options::default()) {
61
+ Ok(res) => Ok(res),
62
+ Err(ex) => Err(Error::new(mrml_error(), ex.to_string()))
63
+ }
64
+ }
65
+ }
66
+
67
+ impl Clone for Template {
68
+ fn clone(&self) -> Self {
69
+ Self::new(self.to_mjml()).unwrap()
70
+ }
71
+ }
72
+
73
+ #[magnus::init]
74
+ fn init() -> Result<(), Error> {
75
+ let module = define_module("MRML")?;
76
+ let class = module.define_class("Template", Default::default())?;
77
+
78
+ class.define_singleton_method("new", function!(Template::new, 1))?;
79
+ class.define_singleton_method("from_json", function!(Template::from_json, 1))?;
80
+
81
+ class.define_method("title", method!(Template::get_title, 0))?;
82
+ class.define_method("preview", method!(Template::get_preview, 0))?;
83
+
84
+ class.define_method("to_mjml", method!(Template::to_mjml, 0))?;
85
+ class.define_method("to_json", method!(Template::to_json, 0))?;
86
+ class.define_method("to_html", method!(Template::to_html, 0))?;
87
+
88
+ class.define_method("clone", method!(Template::clone, 0))?;
89
+ class.define_method("dup", method!(Template::clone, 0))?;
90
+
91
+ Ok(())
92
+ }
data/lib/mrml/error.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MRML
2
4
  class Error < StandardError
3
5
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module MRML
6
+ # Template object implemented in Rust that can parse MJML templates.
7
+ class Template
8
+ class << self
9
+ # @!method from_json(json)
10
+ # A new instance of Template from JSON.
11
+ # @!scope class
12
+ # @param json [String]
13
+ # @return [Template]
14
+ # @raise [Error] if json has invalid format
15
+
16
+ # A new instance of Template from Hash.
17
+ # @param hash [Hash]
18
+ # @return [Template]
19
+ # @raise [Error] if hash has invalid format
20
+
21
+ def from_hash(hash)
22
+ from_json(JSON.generate(hash))
23
+ end
24
+ end
25
+
26
+ # @!method initialize(mjml)
27
+ # A new instance of Template.
28
+ # @param mjml [String]
29
+ # @return [Template]
30
+ # @raise [Error] if mjml is not a valid template
31
+
32
+ # @!attribute [r] title
33
+ # Gets mj-title tag value.
34
+ # @return [String]
35
+
36
+ # @!attribute [r] preview
37
+ # Gets mj-preview tag value.
38
+ # @return [String]
39
+
40
+ # @!method to_mjml
41
+ # MJML representation of the template.
42
+ # @return [String]
43
+
44
+ # @!method to_json
45
+ # JSON representation of the template.
46
+ # @return [String]
47
+
48
+ # @!method to_html
49
+ # HTML representation of the template.
50
+ # @return [String]
51
+
52
+ # Hash representation of the template.
53
+ # @return [Hash]
54
+
55
+ def to_hash
56
+ JSON.parse(to_json)
57
+ end
58
+ end
59
+ end
data/lib/mrml/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MRML
2
- VERSION = '0.8.0'.freeze
4
+ VERSION = '1.0.0'
3
5
  end
data/lib/mrml.rb CHANGED
@@ -1,34 +1,54 @@
1
- require 'ffi'
2
- require 'mrml/result'
3
- require 'mrml/native'
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ RUBY_VERSION =~ /(\d+\.\d+)/
5
+ require "mrml/#{$1}/mrml"
6
+ rescue LoadError
7
+ require 'mrml/mrml'
8
+ end
9
+
4
10
  require 'mrml/error'
11
+ require 'mrml/template'
5
12
  require 'mrml/version'
6
13
 
14
+ # Module that renders MJML templates into HTML/JSON using MRML,
15
+ # a reimplementation of the MJML markup language in Rust.
7
16
  module MRML
8
17
  class << self
9
- def to_title(template)
10
- call(:to_title, template)
11
- end
18
+ # Render template as HTML.
19
+ # @param mjml [String]
20
+ # @return (see Template#to_html)
21
+ # @raise (see Template#initialize)
12
22
 
13
- def to_preview(template)
14
- call(:to_preview, template)
15
- end
23
+ def to_html(mjml)
24
+ return if mjml.nil?
16
25
 
17
- def to_html(template)
18
- call(:to_html, template)
26
+ template = Template.new(mjml)
27
+ template.to_html
19
28
  end
20
29
 
21
- private
30
+ # Render template as JSON.
31
+ # @param mjml [String]
32
+ # @return (see Template#to_json)
33
+ # @raise (see Template#initialize)
34
+
35
+ def to_json(mjml)
36
+ return if mjml.nil?
22
37
 
23
- def call(method, template)
24
- return if template.nil?
38
+ template = Template.new(mjml)
39
+ template.to_json
40
+ end
25
41
 
26
- result = Native.send(method, template)
27
- result = result.read_string.force_encoding('UTF-8')
42
+ # Render template as Hash.
43
+ # @param mjml [String]
44
+ # @return (see Template#to_hash)
45
+ # @raise (see Template#initialize)
28
46
 
29
- raise Error, result if result.start_with?(Error.name)
47
+ def to_hash(mjml)
48
+ return if mjml.nil?
30
49
 
31
- result
50
+ template = Template.new(mjml)
51
+ template.to_hash
32
52
  end
33
53
  end
34
54
  end
metadata CHANGED
@@ -1,31 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-28 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ffi
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: thermite
14
+ name: rb_sys
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
@@ -67,45 +53,38 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: '5.0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: rake
56
+ name: rake-compiler
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '13.0'
61
+ version: '1.2'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '13.0'
83
- description: This project is a reimplementation of the nice MJML markup language in
84
- Rust.
68
+ version: '1.2'
69
+ description: Ruby wrapper for MRML, the MJML parser implementation in Rust.
85
70
  email:
86
71
  - jonian@hardpixel.eu
87
72
  executables: []
88
73
  extensions:
89
- - ext/Rakefile
74
+ - ext/mrml/extconf.rb
90
75
  extra_rdoc_files: []
91
76
  files:
92
- - ".gitignore"
93
- - ".travis.yml"
94
- - Cargo.toml
95
- - Gemfile
77
+ - CODE_OF_CONDUCT.md
96
78
  - LICENSE.txt
97
79
  - README.md
98
- - Rakefile
99
- - bin/console
100
- - bin/setup
101
- - ext/Rakefile
80
+ - ext/mrml/Cargo.lock
81
+ - ext/mrml/Cargo.toml
82
+ - ext/mrml/extconf.rb
83
+ - ext/mrml/src/lib.rs
102
84
  - lib/mrml.rb
103
85
  - lib/mrml/error.rb
104
- - lib/mrml/native.rb
105
- - lib/mrml/result.rb
86
+ - lib/mrml/template.rb
106
87
  - lib/mrml/version.rb
107
- - mrml.gemspec
108
- - src/lib.rs
109
88
  homepage: https://github.com/hardpixel/mrml-ruby
110
89
  licenses:
111
90
  - MIT
@@ -118,14 +97,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
97
  requirements:
119
98
  - - ">="
120
99
  - !ruby/object:Gem::Version
121
- version: '0'
100
+ version: '2.6'
122
101
  required_rubygems_version: !ruby/object:Gem::Requirement
123
102
  requirements:
124
103
  - - ">="
125
104
  - !ruby/object:Gem::Version
126
105
  version: '0'
127
106
  requirements: []
128
- rubygems_version: 3.1.6
107
+ rubygems_version: 3.3.7
129
108
  signing_key:
130
109
  specification_version: 4
131
110
  summary: Ruby wrapper for MRML Rust
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
10
-
11
- # Added by cargo
12
-
13
- /target
14
- Cargo.lock
15
-
16
- /lib/*.so
17
- /mkmf.log
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.2
6
- env:
7
- global:
8
- - RUST_VERSION=stable
9
- before_install:
10
- - if [ ! -e "$HOME/.cargo/bin" ]; then curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $RUST_VERSION -y; fi
11
- - export PATH="$HOME/.cargo/bin:$PATH"
12
- - rustup default $RUST_VERSION
13
- - gem install bundler -v 2.1.4
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in mrml.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
- require "thermite/tasks"
4
-
5
- Thermite::Tasks.new
6
-
7
- Rake::TestTask.new(:test) do |t|
8
- t.libs << "test"
9
- t.libs << "lib"
10
- t.test_files = FileList["test/**/*_test.rb"]
11
- end
12
-
13
- task :default => ['thermite:build', :test]
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'mrml'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require 'pry'
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/ext/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "thermite/tasks"
2
-
3
- project_dir = File.dirname(File.dirname(__FILE__))
4
- Thermite::Tasks.new(cargo_project_path: project_dir, ruby_project_path: project_dir)
5
-
6
- task default: %w(thermite:build)
data/lib/mrml/native.rb DELETED
@@ -1,15 +0,0 @@
1
- module MRML
2
- module Native
3
- extend FFI::Library
4
-
5
- LIBNAME = "mrml.#{FFI::Platform::LIBSUFFIX}".freeze
6
- LIBPATH = File.expand_path('..', __dir__).freeze
7
-
8
- ffi_lib File.expand_path(LIBNAME, LIBPATH)
9
-
10
- attach_function :to_title, :to_title, [:string], Result
11
- attach_function :to_preview, :to_preview, [:string], Result
12
- attach_function :to_html, :to_html, [:string], Result
13
- attach_function :free, :free_result, [Result], :void
14
- end
15
- end
data/lib/mrml/result.rb DELETED
@@ -1,9 +0,0 @@
1
- module MRML
2
- class Result < FFI::AutoPointer
3
- class << self
4
- def release(ptr)
5
- Native.free(ptr)
6
- end
7
- end
8
- end
9
- end
data/mrml.gemspec DELETED
@@ -1,29 +0,0 @@
1
- require_relative 'lib/mrml/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'mrml'
5
- spec.version = MRML::VERSION
6
- spec.authors = ['Jonian Guveli']
7
- spec.email = ['jonian@hardpixel.eu']
8
-
9
- spec.summary = %q{Ruby wrapper for MRML Rust}
10
- spec.description = %q{This project is a reimplementation of the nice MJML markup language in Rust.}
11
- spec.homepage = 'https://github.com/hardpixel/mrml-ruby'
12
- spec.license = 'MIT'
13
-
14
- # Specify which files should be added to the gem when it is released.
15
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- end
19
-
20
- spec.extensions = ['ext/Rakefile']
21
- spec.require_paths = ['lib']
22
-
23
- spec.add_runtime_dependency 'ffi'
24
- spec.add_runtime_dependency 'thermite'
25
-
26
- spec.add_development_dependency 'bundler', '~> 2.0'
27
- spec.add_development_dependency 'minitest', '~> 5.0'
28
- spec.add_development_dependency 'rake', '~> 13.0'
29
- end
data/src/lib.rs DELETED
@@ -1,66 +0,0 @@
1
- use std::os::raw::c_char;
2
- use std::ffi::{CStr, CString};
3
-
4
- use mrml;
5
-
6
- fn to_string(unsafe_string: *const c_char) -> String {
7
- unsafe { CStr::from_ptr(unsafe_string) }.to_str().unwrap().to_string()
8
- }
9
-
10
- fn to_char(string: String) -> *mut c_char {
11
- CString::new(string).unwrap().into_raw()
12
- }
13
-
14
- fn parse_result(result: Result<String, mrml::prelude::render::Error>) -> *mut c_char {
15
- if result.is_err() {
16
- to_char(format!("MRML::Error {:?}", result.unwrap_err()))
17
- } else {
18
- to_char(result.unwrap())
19
- }
20
- }
21
-
22
- fn parse_option(option: Option<String>) -> *mut c_char {
23
- to_char(option.unwrap_or("".to_string()))
24
- }
25
-
26
- #[no_mangle]
27
- pub extern "C" fn to_title(input: *const c_char) -> *mut c_char {
28
- let root = mrml::parse(&to_string(input));
29
-
30
- if root.is_err() {
31
- to_char(format!("MRML::Error {:?}", root.unwrap_err()))
32
- } else {
33
- parse_option(root.unwrap().get_title())
34
- }
35
- }
36
-
37
- #[no_mangle]
38
- pub extern "C" fn to_preview(input: *const c_char) -> *mut c_char {
39
- let root = mrml::parse(&to_string(input));
40
-
41
- if root.is_err() {
42
- to_char(format!("MRML::Error {:?}", root.unwrap_err()))
43
- } else {
44
- parse_option(root.unwrap().get_preview())
45
- }
46
- }
47
-
48
- #[no_mangle]
49
- pub extern "C" fn to_html(input: *const c_char) -> *mut c_char {
50
- let root = mrml::parse(&to_string(input));
51
- let opts = mrml::prelude::render::Options::default();
52
-
53
- if root.is_err() {
54
- to_char(format!("MRML::Error {:?}", root.unwrap_err()))
55
- } else {
56
- parse_result(root.unwrap().render(&opts))
57
- }
58
- }
59
-
60
- #[no_mangle]
61
- pub extern "C" fn free_result(string: *mut c_char) {
62
- unsafe {
63
- if string.is_null() { return }
64
- CString::from_raw(string)
65
- };
66
- }