mrml 0.2.0 → 0.3.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 +4 -4
- data/Gemfile +0 -3
- data/lib/mrml.rb +10 -20
- data/lib/mrml/error.rb +4 -0
- data/lib/mrml/native.rb +15 -0
- data/lib/mrml/result.rb +9 -0
- data/lib/mrml/version.rb +1 -1
- data/src/lib.rs +25 -20
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 695828a62cfc39187d156c7744d583d1809df22f4c41fe903c7d56eb2b509f37
|
4
|
+
data.tar.gz: 918b732a91c2067a0f94747c1ff2a08d740e4c5a5e2c9db05b3ce8b63fee4dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eb9fd6fbc6598ddc81d446ef85110501641012f2da38db55b1278e0563a616c54beb87409bdee5074cb6bb4abba509ee6850ca22a0a1f1508249bf37acf3f55
|
7
|
+
data.tar.gz: 224d11acaf11a084058fd7b86887280aaaa0944017fa0f872b72bb567a25b75839828de807adf22204421409e47b6605cb00b341cd36c4bd233bf53e4ca7ebe9
|
data/Gemfile
CHANGED
data/lib/mrml.rb
CHANGED
@@ -1,33 +1,21 @@
|
|
1
1
|
require 'ffi'
|
2
|
+
require 'mrml/result'
|
3
|
+
require 'mrml/native'
|
4
|
+
require 'mrml/error'
|
2
5
|
require 'mrml/version'
|
3
6
|
|
4
7
|
module MRML
|
5
|
-
class Error < StandardError
|
6
|
-
end
|
7
|
-
|
8
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
9
|
def to_title(template)
|
22
|
-
call(:
|
10
|
+
call(:to_title, template)
|
23
11
|
end
|
24
12
|
|
25
13
|
def to_preview(template)
|
26
|
-
call(:
|
14
|
+
call(:to_preview, template)
|
27
15
|
end
|
28
16
|
|
29
17
|
def to_html(template)
|
30
|
-
call(:
|
18
|
+
call(:to_html, template)
|
31
19
|
end
|
32
20
|
|
33
21
|
private
|
@@ -35,8 +23,10 @@ module MRML
|
|
35
23
|
def call(method, template)
|
36
24
|
return if template.nil?
|
37
25
|
|
38
|
-
result = send(method, template)
|
39
|
-
|
26
|
+
result = Native.send(method, template)
|
27
|
+
result = result.read_string.force_encoding('UTF-8')
|
28
|
+
|
29
|
+
raise Error, result if result.start_with?(Error.name)
|
40
30
|
|
41
31
|
result
|
42
32
|
end
|
data/lib/mrml/error.rb
ADDED
data/lib/mrml/native.rb
ADDED
@@ -0,0 +1,15 @@
|
|
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
ADDED
data/lib/mrml/version.rb
CHANGED
data/src/lib.rs
CHANGED
@@ -3,36 +3,41 @@ use std::ffi::{CStr, CString};
|
|
3
3
|
|
4
4
|
use mrml;
|
5
5
|
|
6
|
-
fn to_string(
|
7
|
-
unsafe {
|
8
|
-
|
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 to_result(result: Result<String, mrml::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())
|
9
19
|
}
|
10
20
|
}
|
11
21
|
|
12
|
-
|
13
|
-
|
22
|
+
#[no_mangle]
|
23
|
+
pub extern "C" fn to_title(input: *const c_char) -> *mut c_char {
|
24
|
+
to_result(mrml::to_title(&to_string(input), mrml::Options::default()))
|
14
25
|
}
|
15
26
|
|
16
27
|
#[no_mangle]
|
17
|
-
pub extern "C" fn
|
18
|
-
|
19
|
-
Ok(html) => return to_char(&html),
|
20
|
-
Err(err) => return to_char(&format!("Error: {:?}", err)),
|
21
|
-
}
|
28
|
+
pub extern "C" fn to_preview(input: *const c_char) -> *mut c_char {
|
29
|
+
to_result(mrml::to_preview(&to_string(input), mrml::Options::default()))
|
22
30
|
}
|
23
31
|
|
24
32
|
#[no_mangle]
|
25
|
-
pub extern "C" fn
|
26
|
-
|
27
|
-
Ok(html) => return to_char(&html),
|
28
|
-
Err(err) => return to_char(&format!("Error: {:?}", err)),
|
29
|
-
}
|
33
|
+
pub extern "C" fn to_html(input: *const c_char) -> *mut c_char {
|
34
|
+
to_result(mrml::to_html(&to_string(input), mrml::Options::default()))
|
30
35
|
}
|
31
36
|
|
32
37
|
#[no_mangle]
|
33
|
-
pub extern "C" fn
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
}
|
38
|
+
pub extern "C" fn free_result(string: *mut c_char) {
|
39
|
+
unsafe {
|
40
|
+
if string.is_null() { return }
|
41
|
+
CString::from_raw(string)
|
42
|
+
};
|
38
43
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mrml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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: 2021-
|
11
|
+
date: 2021-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -100,6 +100,9 @@ files:
|
|
100
100
|
- bin/setup
|
101
101
|
- ext/Rakefile
|
102
102
|
- lib/mrml.rb
|
103
|
+
- lib/mrml/error.rb
|
104
|
+
- lib/mrml/native.rb
|
105
|
+
- lib/mrml/result.rb
|
103
106
|
- lib/mrml/version.rb
|
104
107
|
- mrml.gemspec
|
105
108
|
- src/lib.rs
|