mrml 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 698a5cbddf2e1321636928ab0c6bb5edf1e8909173a516de3b9c7d7059122a15
4
+ data.tar.gz: 13f6b2ae6f0c74c712b66fc481dd13481a4060cf33889fef66b5a277e715eedf
5
+ SHA512:
6
+ metadata.gz: 1639da3c3ab01afe8ca6930d5f487debff86b67f73469e59611a4198447caa1a2c3771904d5361e8a57dce43ced08aea29fc4bf43bd48e5d6c7a0bbd4fca9933
7
+ data.tar.gz: 19a0e0f5c8cf10e0c8a10aa73324d5690dc8ddf2c886fc59bd54c2b2acf729206534812b5c0602d2e8ba10e464f756548e3291bd7f990dbcc49c3f9f1c246791
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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 ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
data/Cargo.toml ADDED
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "mrml"
3
+ version = "0.1.0"
4
+ authors = ["Jonian Guveli <jonian@hardpixel.eu>"]
5
+ edition = "2018"
6
+
7
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+ [dependencies]
9
+ ruru = "0.9.3"
10
+ mrml = "0.4.0"
11
+
12
+ [lib]
13
+ name = "mrml"
14
+ crate-type = ["cdylib"]
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mrml.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'minitest', '~> 5.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 jonian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # MRML Ruby
2
+
3
+ Ruby wrapper for [MRML](https://github.com/jdrouet/mrml), the [MJML](https://mjml.io) parser implementation in Rust. Rust must be available on your system to install this gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mrml'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mrml
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'mrml'
25
+
26
+ template = <<-HTML
27
+ <mjml>
28
+ <mj-head>
29
+ <mj-title>Newsletter Title</mj-title>
30
+ </mj-head>
31
+ <mj-body>
32
+ <mj-section>
33
+ <mj-column>
34
+ <mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello World</mj-text>
35
+ </mj-column>
36
+ </mj-section>
37
+ </mj-body>
38
+ </mjml>
39
+ HTML
40
+
41
+ # Generate the title from mjml
42
+ MRML.to_title(template)
43
+
44
+ # Generate the preview from mjml
45
+ MRML.to_preview(template)
46
+
47
+ # Generate the html from mjml
48
+ MRML.to_html(template)
49
+ ```
50
+
51
+ ## To Do
52
+
53
+ Add support for options.
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/mrml-ruby.
64
+
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
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 => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
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 ADDED
@@ -0,0 +1,8 @@
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 ADDED
@@ -0,0 +1,6 @@
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.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'ffi'
2
+ require 'mrml/version'
3
+
4
+ module MRML
5
+ class Error < StandardError
6
+ end
7
+
8
+ class << self
9
+ extend FFI::Library
10
+
11
+ ffi_lib File.expand_path("mrml.#{FFI::Platform::LIBSUFFIX}", __dir__)
12
+
13
+ attach_function :__to_title, :to_title, [:string], :string
14
+ attach_function :__to_preview, :to_preview, [:string], :string
15
+ attach_function :__to_html, :to_html, [:string], :string
16
+
17
+ private :__to_title
18
+ private :__to_preview
19
+ private :__to_html
20
+
21
+ def to_title(template)
22
+ call(:__to_title, template)
23
+ end
24
+
25
+ def to_preview(template)
26
+ call(:__to_preview, template)
27
+ end
28
+
29
+ def to_html(template)
30
+ call(:__to_html, template)
31
+ end
32
+
33
+ private
34
+
35
+ def call(method, template)
36
+ return if template.nil?
37
+
38
+ result = send(method, template)
39
+ raise Error, result if result.start_with?('Error')
40
+
41
+ result
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module MRML
2
+ VERSION = '0.1.0'
3
+ end
data/mrml.gemspec ADDED
@@ -0,0 +1,29 @@
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 ADDED
@@ -0,0 +1,38 @@
1
+ use std::os::raw::c_char;
2
+ use std::ffi::{CStr, CString};
3
+
4
+ use mrml;
5
+
6
+ fn to_string(input: *const c_char) -> String {
7
+ unsafe {
8
+ CStr::from_ptr(input).to_string_lossy().into_owned()
9
+ }
10
+ }
11
+
12
+ fn to_char(str: &str) -> *const c_char {
13
+ CString::new(str).unwrap().into_raw()
14
+ }
15
+
16
+ #[no_mangle]
17
+ pub extern "C" fn to_title(input: *const c_char) -> *const c_char {
18
+ match mrml::to_title(&to_string(input), mrml::Options::default()) {
19
+ Ok(html) => return to_char(&html),
20
+ Err(err) => return to_char(&format!("Error: {:?}", err)),
21
+ }
22
+ }
23
+
24
+ #[no_mangle]
25
+ pub extern "C" fn to_preview(input: *const c_char) -> *const c_char {
26
+ match mrml::to_preview(&to_string(input), mrml::Options::default()) {
27
+ Ok(html) => return to_char(&html),
28
+ Err(err) => return to_char(&format!("Error: {:?}", err)),
29
+ }
30
+ }
31
+
32
+ #[no_mangle]
33
+ pub extern "C" fn to_html(input: *const c_char) -> *const c_char {
34
+ match mrml::to_html(&to_string(input), mrml::Options::default()) {
35
+ Ok(html) => return to_char(&html),
36
+ Err(err) => return to_char(&format!("Error: {:?}", err)),
37
+ }
38
+ }
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mrml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonian Guveli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
+ dependencies:
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
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ description: This project is a reimplementation of the nice MJML markup language in
84
+ Rust.
85
+ email:
86
+ - jonian@hardpixel.eu
87
+ executables: []
88
+ extensions:
89
+ - ext/Rakefile
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - Cargo.toml
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - ext/Rakefile
102
+ - lib/mrml.rb
103
+ - lib/mrml/version.rb
104
+ - mrml.gemspec
105
+ - src/lib.rs
106
+ homepage: https://github.com/hardpixel/mrml-ruby
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.1.4
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby wrapper for MRML Rust
129
+ test_files: []