himg 0.0.9 → 0.0.10
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/CHANGELOG.md +6 -0
- data/Cargo.lock +1 -1
- data/Cargo.toml +4 -0
- data/ext/himg/Cargo.toml +1 -1
- data/ext/himg/src/lib.rs +23 -3
- data/lib/himg/version.rb +1 -1
- data/lib/himg.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d65ada02141e4fdd397d4c58def4e7fd658202563a2bbc31b548801b08198d4b
|
4
|
+
data.tar.gz: b7c9cc37243b8f790dfb977a6d6e5c215104e4a6a0f03cbc63308191d7ba7e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d21cb8a714e462c08b36a000275eb9b4c840ab2bb049f8c7bcacb5b978a4404f36d0431b867b019fee864130b1895ef026b81257d6ce0199dec0adef8ecf5578
|
7
|
+
data.tar.gz: a96a262c6dc6e4a42bb8b6bcdacb47f24203d3e5d74673880b6851f76a01421e373c2a3e074f2cbb697e58c69b1e9eb1a3284824853821601c3e694c5bd127a3
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
3
|
|
4
|
+
## [0.0.10] - 2025-08-01
|
5
|
+
|
6
|
+
- Fixed himg require from native extension
|
7
|
+
- Catch rust panics and wrap with ruby Error
|
8
|
+
- GpuNotFound error extending Himg::Error
|
9
|
+
|
4
10
|
## [0.0.9] - 2025-07-31
|
5
11
|
|
6
12
|
- Returned to CPU-only rendering by default
|
data/Cargo.lock
CHANGED
data/Cargo.toml
CHANGED
data/ext/himg/Cargo.toml
CHANGED
data/ext/himg/src/lib.rs
CHANGED
@@ -45,10 +45,30 @@ impl Options {
|
|
45
45
|
pub fn render_blocking_rb(ruby: &Ruby, html: String, options: Option<RHash>) -> Result<RString, Error> {
|
46
46
|
let options = Options::from_ruby(options)?;
|
47
47
|
let exception_class = ExceptionClass::from_value(magnus::eval("Himg::Error").unwrap()).unwrap();
|
48
|
+
let gpu_not_found_class = ExceptionClass::from_value(magnus::eval("Himg::GpuNotFound").unwrap()).unwrap();
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
51
|
+
render_blocking(html, options)
|
52
|
+
}));
|
53
|
+
|
54
|
+
match result {
|
55
|
+
Ok(Ok(data)) => Ok(ruby.str_from_slice(&data)),
|
56
|
+
Ok(Err(e)) => Err(Error::new(exception_class, format!("{}", e))),
|
57
|
+
Err(panic) => {
|
58
|
+
let msg = if let Some(s) = panic.downcast_ref::<String>() {
|
59
|
+
s.clone()
|
60
|
+
} else if let Some(s) = panic.downcast_ref::<&str>() {
|
61
|
+
s.to_string()
|
62
|
+
} else {
|
63
|
+
"Unknown panic".to_string()
|
64
|
+
};
|
65
|
+
|
66
|
+
if msg.contains("No compatible device found") {
|
67
|
+
Err(Error::new(gpu_not_found_class, msg))
|
68
|
+
} else {
|
69
|
+
Err(Error::new(exception_class, format!("Panic: {}", msg)))
|
70
|
+
}
|
71
|
+
}
|
52
72
|
}
|
53
73
|
}
|
54
74
|
|
data/lib/himg/version.rb
CHANGED
data/lib/himg.rb
CHANGED
@@ -8,7 +8,7 @@ require "himg/railtie" if defined?(Rails::Railtie)
|
|
8
8
|
# Fall back to loading the non-versioned extension if version-specific loading fails.
|
9
9
|
begin
|
10
10
|
RUBY_VERSION =~ /(\d+\.\d+)/
|
11
|
-
require "
|
11
|
+
require "himg/#{Regexp.last_match(1)}/himg"
|
12
12
|
rescue LoadError
|
13
13
|
require "himg/himg"
|
14
14
|
end
|
@@ -19,6 +19,7 @@ end
|
|
19
19
|
module Himg
|
20
20
|
RENDER_OPTIONS = %i[width height truncate verbose base_url disable_fetch fetch_timeout gpu].freeze
|
21
21
|
class Error < StandardError; end
|
22
|
+
class GpuNotFound < Error; end
|
22
23
|
|
23
24
|
def self.render(html, width: 720, height: 405, truncate: true, verbose: false, base_url: nil, disable_fetch: false, fetch_timeout: 10, gpu: false)
|
24
25
|
render_to_string(html, "width" => width.to_i, "height" => height.to_i, "truncate" => truncate, "verbose" => verbose, "base_url" => BaseUrl.new(base_url).to_s, "disable_fetch" => disable_fetch, "fetch_timeout" => fetch_timeout.to_f, "gpu" => gpu)
|