fulgur 0.8.0 → 0.12.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/Cargo.toml +1 -1
- data/ext/fulgur/Cargo.toml +2 -2
- data/lib/fulgur/version.rb +1 -1
- data/src/asset_bundle.rs +2 -2
- data/src/engine.rs +5 -4
- data/src/error.rs +4 -4
- data/src/lib.rs +2 -2
- data/src/margin.rs +2 -2
- data/src/page_size.rs +11 -7
- data/src/pdf.rs +12 -9
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e8f8d469b4c66f85a50347a85a9ef5f740e911e7af64bbc02755ae92dae2c13
|
|
4
|
+
data.tar.gz: 5672b32788488af9938d70e9db3c0d2f1a3aad4804aefe663f6225eddcc20ea1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d2809932eceae4cb1c4a1f5aa09a81b9d351f714b597723e5addd7e2ddd1e19d298471344af8853bf616fc78eedf142fe54c8ea6f5497d97a9aa88362f8863e4
|
|
7
|
+
data.tar.gz: 7e9aa059550797e7295910e34cd025a1c0c92e2a1e374ff607b898e8052911308f2a5a45c98064fb7e01ba2dcc9ea5633e0bac5b09d29a82ba0aed78243d8ec8
|
data/Cargo.toml
CHANGED
data/ext/fulgur/Cargo.toml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[package]
|
|
4
4
|
name = "fulgur"
|
|
5
|
-
version = "0.
|
|
5
|
+
version = "0.12.0"
|
|
6
6
|
# crates/fulgur-ruby/Cargo.toml と同じ src を共有 (path = "../../src/lib.rs")。
|
|
7
7
|
# workspace と同じ edition 2024 に揃える。
|
|
8
8
|
edition = "2024"
|
|
@@ -22,7 +22,7 @@ ruby-api = ["dep:magnus", "dep:rb-sys"]
|
|
|
22
22
|
# を参照する (release 時は release.yml → release: published → release-ruby.yml の順で
|
|
23
23
|
# 発火するため、この時点で fulgur のバージョンは crates.io に存在する)。
|
|
24
24
|
# release-prepare.yml が sed でこの行のバージョンを同期する。
|
|
25
|
-
fulgur = "0.
|
|
25
|
+
fulgur = "0.12.0"
|
|
26
26
|
base64 = "0.22"
|
|
27
27
|
magnus = { version = "0.7", optional = true }
|
|
28
28
|
rb-sys = { version = "0.9", optional = true }
|
data/lib/fulgur/version.rb
CHANGED
data/src/asset_bundle.rs
CHANGED
|
@@ -66,8 +66,8 @@ impl RbAssetBundle {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
pub fn define(
|
|
70
|
-
let class = fulgur.define_class("AssetBundle",
|
|
69
|
+
pub fn define(ruby: &Ruby, fulgur: &RModule) -> Result<(), Error> {
|
|
70
|
+
let class = fulgur.define_class("AssetBundle", ruby.class_object())?;
|
|
71
71
|
class.define_singleton_method("new", function!(RbAssetBundle::new, 0))?;
|
|
72
72
|
class.define_method("add_css", method!(RbAssetBundle::add_css, 1))?;
|
|
73
73
|
class.define_method("add_css_file", method!(RbAssetBundle::add_css_file, 1))?;
|
data/src/engine.rs
CHANGED
|
@@ -36,8 +36,9 @@ impl RbEngineBuilder {
|
|
|
36
36
|
|
|
37
37
|
fn take(&self) -> Result<EngineBuilder, Error> {
|
|
38
38
|
self.inner.borrow_mut().take().ok_or_else(|| {
|
|
39
|
+
let ruby = Ruby::get().expect("ruby vm");
|
|
39
40
|
Error::new(
|
|
40
|
-
|
|
41
|
+
ruby.exception_runtime_error(),
|
|
41
42
|
"EngineBuilder has already been built",
|
|
42
43
|
)
|
|
43
44
|
})
|
|
@@ -273,8 +274,8 @@ fn engine_builder() -> RbEngineBuilder {
|
|
|
273
274
|
RbEngineBuilder::new()
|
|
274
275
|
}
|
|
275
276
|
|
|
276
|
-
pub fn define(
|
|
277
|
-
let engine = fulgur.define_class("Engine",
|
|
277
|
+
pub fn define(ruby: &Ruby, fulgur: &RModule) -> Result<(), Error> {
|
|
278
|
+
let engine = fulgur.define_class("Engine", ruby.class_object())?;
|
|
278
279
|
engine.define_singleton_method("new", function!(engine_new, -1))?;
|
|
279
280
|
engine.define_singleton_method("builder", function!(engine_builder, 0))?;
|
|
280
281
|
engine.define_method("render_html", method!(RbEngine::render_html, 1))?;
|
|
@@ -283,7 +284,7 @@ pub fn define(_ruby: &Ruby, fulgur: &RModule) -> Result<(), Error> {
|
|
|
283
284
|
method!(RbEngine::render_html_to_file, 2),
|
|
284
285
|
)?;
|
|
285
286
|
|
|
286
|
-
let builder = fulgur.define_class("EngineBuilder",
|
|
287
|
+
let builder = fulgur.define_class("EngineBuilder", ruby.class_object())?;
|
|
287
288
|
builder.define_method("page_size", method!(builder_page_size, 1))?;
|
|
288
289
|
builder.define_method("margin", method!(builder_margin, 1))?;
|
|
289
290
|
builder.define_method("assets", method!(builder_assets, 1))?;
|
data/src/error.rs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
//! `fulgur::Error` の variant に応じて適切な Ruby 例外に変換する。
|
|
6
6
|
|
|
7
7
|
use fulgur::Error as FulgurError;
|
|
8
|
-
use magnus::{Error, ExceptionClass, Module, RModule, Ruby
|
|
8
|
+
use magnus::{Error, ExceptionClass, Module, RModule, Ruby};
|
|
9
9
|
|
|
10
10
|
/// Ruby 側の `Fulgur::<name>` 例外クラスを lookup する。
|
|
11
11
|
fn class(ruby: &Ruby, name: &str) -> Result<ExceptionClass, Error> {
|
|
@@ -28,7 +28,7 @@ pub fn map_fulgur_error(ruby: &Ruby, err: FulgurError) -> Error {
|
|
|
28
28
|
.class_object()
|
|
29
29
|
.const_get::<_, RModule>("Errno")
|
|
30
30
|
.and_then(|m| m.const_get::<_, ExceptionClass>("ENOENT"))
|
|
31
|
-
.unwrap_or_else(|_|
|
|
31
|
+
.unwrap_or_else(|_| ruby.exception_runtime_error());
|
|
32
32
|
Error::new(errno, io_err.to_string())
|
|
33
33
|
}
|
|
34
34
|
_ => render_error(ruby, io_err.to_string()),
|
|
@@ -46,13 +46,13 @@ pub fn map_fulgur_error(ruby: &Ruby, err: FulgurError) -> Error {
|
|
|
46
46
|
fn render_error(ruby: &Ruby, msg: String) -> Error {
|
|
47
47
|
match class(ruby, "RenderError") {
|
|
48
48
|
Ok(c) => Error::new(c, msg),
|
|
49
|
-
Err(_) => Error::new(
|
|
49
|
+
Err(_) => Error::new(ruby.exception_runtime_error(), msg),
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
fn asset_error(ruby: &Ruby, msg: String) -> Error {
|
|
54
54
|
match class(ruby, "AssetError") {
|
|
55
55
|
Ok(c) => Error::new(c, msg),
|
|
56
|
-
Err(_) => Error::new(
|
|
56
|
+
Err(_) => Error::new(ruby.exception_runtime_error(), msg),
|
|
57
57
|
}
|
|
58
58
|
}
|
data/src/lib.rs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
#![cfg(feature = "ruby-api")]
|
|
8
8
|
|
|
9
|
-
use magnus::
|
|
9
|
+
use magnus::Error;
|
|
10
10
|
|
|
11
11
|
mod asset_bundle;
|
|
12
12
|
mod engine;
|
|
@@ -30,7 +30,7 @@ mod assertions {
|
|
|
30
30
|
|
|
31
31
|
#[magnus::init]
|
|
32
32
|
fn init(ruby: &magnus::Ruby) -> Result<(), Error> {
|
|
33
|
-
let fulgur = define_module("Fulgur")?;
|
|
33
|
+
let fulgur = ruby.define_module("Fulgur")?;
|
|
34
34
|
page_size::define(ruby, &fulgur)?;
|
|
35
35
|
margin::define(ruby, &fulgur)?;
|
|
36
36
|
asset_bundle::define(ruby, &fulgur)?;
|
data/src/margin.rs
CHANGED
|
@@ -61,8 +61,8 @@ impl RbMargin {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
pub fn define(
|
|
65
|
-
let class = fulgur.define_class("Margin",
|
|
64
|
+
pub fn define(ruby: &Ruby, fulgur: &RModule) -> Result<(), Error> {
|
|
65
|
+
let class = fulgur.define_class("Margin", ruby.class_object())?;
|
|
66
66
|
class.define_singleton_method("__build__", function!(RbMargin::from_trbl, 4))?;
|
|
67
67
|
class.define_singleton_method("uniform", function!(RbMargin::uniform, 1))?;
|
|
68
68
|
class.define_singleton_method("symmetric", function!(RbMargin::symmetric, 2))?;
|
data/src/page_size.rs
CHANGED
|
@@ -59,8 +59,9 @@ pub fn extract(value: Value) -> Result<PageSize, Error> {
|
|
|
59
59
|
if let Ok(s) = <String>::try_convert(value) {
|
|
60
60
|
return parse_name(&s);
|
|
61
61
|
}
|
|
62
|
+
let ruby = Ruby::get().expect("ruby vm");
|
|
62
63
|
Err(Error::new(
|
|
63
|
-
|
|
64
|
+
ruby.exception_arg_error(),
|
|
64
65
|
"page_size must be Symbol, String, or Fulgur::PageSize",
|
|
65
66
|
))
|
|
66
67
|
}
|
|
@@ -70,15 +71,18 @@ fn parse_name(name: &str) -> Result<PageSize, Error> {
|
|
|
70
71
|
"A4" => Ok(PageSize::A4),
|
|
71
72
|
"LETTER" => Ok(PageSize::LETTER),
|
|
72
73
|
"A3" => Ok(PageSize::A3),
|
|
73
|
-
other =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
other => {
|
|
75
|
+
let ruby = Ruby::get().expect("ruby vm");
|
|
76
|
+
Err(Error::new(
|
|
77
|
+
ruby.exception_arg_error(),
|
|
78
|
+
format!("unknown page size: {other}"),
|
|
79
|
+
))
|
|
80
|
+
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
pub fn define(
|
|
81
|
-
let class = fulgur.define_class("PageSize",
|
|
84
|
+
pub fn define(ruby: &Ruby, fulgur: &RModule) -> Result<(), Error> {
|
|
85
|
+
let class = fulgur.define_class("PageSize", ruby.class_object())?;
|
|
82
86
|
class.define_singleton_method("custom", function!(RbPageSize::custom, 2))?;
|
|
83
87
|
class.define_method("width", method!(RbPageSize::width, 0))?;
|
|
84
88
|
class.define_method("height", method!(RbPageSize::height, 0))?;
|
data/src/pdf.rs
CHANGED
|
@@ -24,8 +24,9 @@ impl RbPdf {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
fn to_s(&self) -> RString {
|
|
27
|
-
// `
|
|
28
|
-
|
|
27
|
+
// `Ruby::str_from_slice` は ASCII-8BIT (binary) encoding の Ruby String を返す。
|
|
28
|
+
let ruby = Ruby::get().expect("ruby vm");
|
|
29
|
+
ruby.str_from_slice(&self.bytes)
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
fn to_base64(&self) -> String {
|
|
@@ -62,18 +63,19 @@ impl RbPdf {
|
|
|
62
63
|
/// - `IO#write` が要求より少ないバイト数を返した場合 (socket / pipe / 独自 IO の短書き込み)
|
|
63
64
|
/// は残りを再送する。戻り値が 0 の場合は無限ループを防ぐため `RuntimeError` を返す。
|
|
64
65
|
fn write_to_io(&self, io: Value) -> Result<(), Error> {
|
|
65
|
-
let
|
|
66
|
+
let ruby = Ruby::get().expect("ruby vm");
|
|
67
|
+
let responds: bool = io.funcall("respond_to?", (ruby.to_symbol("binmode"),))?;
|
|
66
68
|
if responds {
|
|
67
69
|
let _: Value = io.funcall("binmode", ())?;
|
|
68
70
|
}
|
|
69
71
|
for chunk in self.bytes.chunks(CHUNK_SIZE) {
|
|
70
72
|
let mut offset = 0;
|
|
71
73
|
while offset < chunk.len() {
|
|
72
|
-
let rb_bytes =
|
|
74
|
+
let rb_bytes = ruby.str_from_slice(&chunk[offset..]);
|
|
73
75
|
let written: usize = io.funcall("write", (rb_bytes,))?;
|
|
74
76
|
if written == 0 {
|
|
75
77
|
return Err(Error::new(
|
|
76
|
-
|
|
78
|
+
ruby.exception_runtime_error(),
|
|
77
79
|
"IO#write returned 0 bytes; cannot make progress",
|
|
78
80
|
));
|
|
79
81
|
}
|
|
@@ -87,7 +89,8 @@ impl RbPdf {
|
|
|
87
89
|
/// Ruby 値をファイルパス文字列に変換する。`Pathname` 等 `to_path` に応答する
|
|
88
90
|
/// オブジェクトを受け入れ、そうでなければ `to_str` で暗黙変換する。
|
|
89
91
|
pub(crate) fn coerce_to_path(value: Value) -> Result<String, Error> {
|
|
90
|
-
let
|
|
92
|
+
let ruby = Ruby::get().expect("ruby vm");
|
|
93
|
+
let responds: bool = value.funcall("respond_to?", (ruby.to_symbol("to_path"),))?;
|
|
91
94
|
let converted: Value = if responds {
|
|
92
95
|
value.funcall("to_path", ())?
|
|
93
96
|
} else {
|
|
@@ -95,14 +98,14 @@ pub(crate) fn coerce_to_path(value: Value) -> Result<String, Error> {
|
|
|
95
98
|
};
|
|
96
99
|
<String>::try_convert(converted).map_err(|_| {
|
|
97
100
|
Error::new(
|
|
98
|
-
|
|
101
|
+
ruby.exception_type_error(),
|
|
99
102
|
"path must be a String or respond to to_path",
|
|
100
103
|
)
|
|
101
104
|
})
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
pub fn define(
|
|
105
|
-
let class = fulgur.define_class("Pdf",
|
|
107
|
+
pub fn define(ruby: &Ruby, fulgur: &RModule) -> Result<(), Error> {
|
|
108
|
+
let class = fulgur.define_class("Pdf", ruby.class_object())?;
|
|
106
109
|
class.define_method("bytesize", method!(RbPdf::bytesize, 0))?;
|
|
107
110
|
class.define_method("to_s", method!(RbPdf::to_s, 0))?;
|
|
108
111
|
class.define_method("to_base64", method!(RbPdf::to_base64, 0))?;
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fulgur
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mitsuru Hayasaka
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rb_sys
|