page_print 0.1.4 → 0.1.6
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/README.md +16 -2
- data/ext/page_print/page_print.c +70 -28
- data/lib/page_print/version.rb +1 -1
- 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: 169eff31f74498423a1a2e143966ade6f58e912a548922f906fba8b64264e905
|
|
4
|
+
data.tar.gz: 61a523b3f98cd4b36cdcd4b9fce35fa011995ef37a431a0b6379fa15e05a24c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 703a44815c6a315aabf6bafd7e8f2f355794f619689ed5b37b31b58ba83388176da9ddde484484c818fb9ebc13132e5b62cbe32613f72776c778cb500406be88
|
|
7
|
+
data.tar.gz: 80a783772bd1ff36397aa6c830dd80373697664cd4a9d0e36a7d4798a87c906bf28683cca854b07f6edfd080b91fd5956d49cae22e35e9d2e04860f62c244b9a
|
data/README.md
CHANGED
|
@@ -130,6 +130,8 @@ Supported keyword options:
|
|
|
130
130
|
- `resource_fetcher:` callable that receives a URL and returns `nil` or `{ content:, mime_type:, text_encoding: nil }`
|
|
131
131
|
- `metadata:` hash with `:title`, `:author`, `:subject`, `:keywords`, `:creation_date`, or `:modification_date`
|
|
132
132
|
|
|
133
|
+
Unresolved URLs are not fetched over the network. Provide assets through `resource_fetcher`, or return `nil` to skip a URL.
|
|
134
|
+
|
|
133
135
|
`metadata[:creation_date]` and `metadata[:modification_date]` should be ISO-8601 strings, for example `2026-05-10T12:00:00Z`.
|
|
134
136
|
|
|
135
137
|
Custom dimensions and margins require `unit:`. Supported units are `:pt`, `:pc`, `:in`, `:cm`, `:mm`, and `:px`.
|
|
@@ -151,7 +153,7 @@ For options and CSV output, see `benchmark/README.md`.
|
|
|
151
153
|
|
|
152
154
|
## Requirements
|
|
153
155
|
|
|
154
|
-
- Ruby 3.
|
|
156
|
+
- Ruby 3.2+
|
|
155
157
|
- Native gems are published for `x86_64-linux` and `arm64-darwin`.
|
|
156
158
|
- Native gems vendor PlutoBook but compile the small Ruby extension during install so it links against your local Ruby.
|
|
157
159
|
- Source builds on unsupported platforms require PlutoBook development headers and library files.
|
|
@@ -250,6 +252,18 @@ gem build page_print.gemspec
|
|
|
250
252
|
gem install ./page_print-*.gem
|
|
251
253
|
```
|
|
252
254
|
|
|
255
|
+
## Releasing
|
|
256
|
+
|
|
257
|
+
Publish a new version with:
|
|
258
|
+
|
|
259
|
+
```sh
|
|
260
|
+
bin/bump 0.1.6
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
That updates `lib/page_print/version.rb` and `Gemfile.lock`, commits `Release 0.1.6`, creates annotated tag `v0.1.6`, and pushes `main` plus the tag. Requires a clean worktree on `main`.
|
|
264
|
+
|
|
265
|
+
The Package workflow then builds the source and platform gems, pushes them to RubyGems (trusted publishing / OIDC, GitHub environment `release`), and creates a GitHub Release with the gem artifacts and commit notes since the previous `v*` tag.
|
|
266
|
+
|
|
253
267
|
## Building Native Gems
|
|
254
268
|
|
|
255
269
|
Build an `x86_64-linux` platform gem with a vendored PlutoBook library:
|
|
@@ -264,7 +278,7 @@ Build an Apple Silicon macOS platform gem with a vendored PlutoBook library:
|
|
|
264
278
|
bundle exec rake package:darwin_arm64
|
|
265
279
|
```
|
|
266
280
|
|
|
267
|
-
These tasks check out PlutoBook `v0.
|
|
281
|
+
These tasks check out PlutoBook `v0.18.0`, build it into `lib/page_print/vendor/<platform>`, and write a platform gem to `pkg/`. Platform gems compile the Ruby extension during gem install to avoid tying the gem to the build machine's Ruby version.
|
|
268
282
|
|
|
269
283
|
Native gems bundle PlutoBook and its non-system shared library dependencies. Optional PlutoBook features for curl, TurboJPEG, and WebP are disabled to keep the bundled dependency set smaller.
|
|
270
284
|
|
data/ext/page_print/page_print.c
CHANGED
|
@@ -48,7 +48,7 @@ typedef struct {
|
|
|
48
48
|
plutobook_page_size_t page_size;
|
|
49
49
|
plutobook_page_margins_t margins;
|
|
50
50
|
plutobook_media_type_t media;
|
|
51
|
-
|
|
51
|
+
VALUE base_url;
|
|
52
52
|
VALUE resource_fetcher;
|
|
53
53
|
VALUE metadata;
|
|
54
54
|
} pageprint_options_t;
|
|
@@ -97,6 +97,11 @@ typedef struct {
|
|
|
97
97
|
int ok;
|
|
98
98
|
} pageprint_write_pdf_stream_args_t;
|
|
99
99
|
|
|
100
|
+
typedef struct {
|
|
101
|
+
plutobook_t *book;
|
|
102
|
+
VALUE metadata;
|
|
103
|
+
} pageprint_apply_metadata_args_t;
|
|
104
|
+
|
|
100
105
|
static VALUE pageprint_append_pdf_string(VALUE value);
|
|
101
106
|
static plutobook_stream_status_t pageprint_write_pdf_string(void *closure, const char *data, unsigned int length);
|
|
102
107
|
static plutobook_resource_data_t *pageprint_fetch_resource(void *closure, const char *url);
|
|
@@ -368,6 +373,15 @@ static void pageprint_apply_metadata(plutobook_t *book, VALUE metadata)
|
|
|
368
373
|
pageprint_set_metadata_value(book, metadata, id_modification_date, PLUTOBOOK_PDF_METADATA_MODIFICATION_DATE);
|
|
369
374
|
}
|
|
370
375
|
|
|
376
|
+
static VALUE pageprint_apply_metadata_with_gvl(VALUE ptr)
|
|
377
|
+
{
|
|
378
|
+
pageprint_apply_metadata_args_t *args = (pageprint_apply_metadata_args_t *)ptr;
|
|
379
|
+
|
|
380
|
+
pageprint_apply_metadata(args->book, args->metadata);
|
|
381
|
+
|
|
382
|
+
return Qnil;
|
|
383
|
+
}
|
|
384
|
+
|
|
371
385
|
static void *pageprint_load_html_without_gvl(void *ptr)
|
|
372
386
|
{
|
|
373
387
|
pageprint_load_html_args_t *args = ptr;
|
|
@@ -487,23 +501,26 @@ static plutobook_resource_data_t *pageprint_fetch_resource(void *closure, const
|
|
|
487
501
|
pageprint_resource_fetch_args_t args;
|
|
488
502
|
int state;
|
|
489
503
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
504
|
+
if (!NIL_P(fetcher->object)) {
|
|
505
|
+
args.fetcher = fetcher;
|
|
506
|
+
args.url = url;
|
|
507
|
+
args.resource = NULL;
|
|
493
508
|
|
|
494
|
-
|
|
509
|
+
state = (int)(intptr_t)rb_thread_call_with_gvl(pageprint_call_resource_fetcher_with_gvl, &args);
|
|
495
510
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
511
|
+
if (state) {
|
|
512
|
+
fetcher->state = state;
|
|
513
|
+
plutobook_set_error_message("failed to fetch URL '%s'", url);
|
|
514
|
+
return NULL;
|
|
515
|
+
}
|
|
501
516
|
|
|
502
|
-
|
|
503
|
-
|
|
517
|
+
if (args.resource) {
|
|
518
|
+
return args.resource;
|
|
519
|
+
}
|
|
504
520
|
}
|
|
505
521
|
|
|
506
|
-
|
|
522
|
+
plutobook_set_error_message("network fetch disabled for URL '%s'", url);
|
|
523
|
+
return NULL;
|
|
507
524
|
}
|
|
508
525
|
|
|
509
526
|
static pageprint_options_t pageprint_options_from_value(VALUE options)
|
|
@@ -521,7 +538,7 @@ static pageprint_options_t pageprint_options_from_value(VALUE options)
|
|
|
521
538
|
result.page_size = PLUTOBOOK_PAGE_SIZE_A4;
|
|
522
539
|
result.margins = PLUTOBOOK_PAGE_MARGINS_NORMAL;
|
|
523
540
|
result.media = PLUTOBOOK_MEDIA_TYPE_PRINT;
|
|
524
|
-
result.base_url =
|
|
541
|
+
result.base_url = Qnil;
|
|
525
542
|
result.resource_fetcher = Qnil;
|
|
526
543
|
result.metadata = Qnil;
|
|
527
544
|
|
|
@@ -556,7 +573,7 @@ static pageprint_options_t pageprint_options_from_value(VALUE options)
|
|
|
556
573
|
rb_raise(rb_eTypeError, "base_url must be a String or nil");
|
|
557
574
|
}
|
|
558
575
|
|
|
559
|
-
result.base_url =
|
|
576
|
+
result.base_url = base_url_value;
|
|
560
577
|
}
|
|
561
578
|
|
|
562
579
|
if (page_size_value != Qundef) {
|
|
@@ -596,6 +613,7 @@ static plutobook_t *pageprint_create_book_from_html(VALUE html, VALUE options, p
|
|
|
596
613
|
pageprint_options_t pageprint_options;
|
|
597
614
|
|
|
598
615
|
const char *html_str;
|
|
616
|
+
const char *base_url_str;
|
|
599
617
|
long html_len;
|
|
600
618
|
|
|
601
619
|
plutobook_t *book;
|
|
@@ -628,21 +646,30 @@ static plutobook_t *pageprint_create_book_from_html(VALUE html, VALUE options, p
|
|
|
628
646
|
resource_fetcher->object = pageprint_options.resource_fetcher;
|
|
629
647
|
resource_fetcher->state = 0;
|
|
630
648
|
|
|
631
|
-
|
|
632
|
-
plutobook_set_custom_resource_fetcher(book, pageprint_fetch_resource, resource_fetcher);
|
|
633
|
-
}
|
|
649
|
+
plutobook_set_custom_resource_fetcher(book, pageprint_fetch_resource, resource_fetcher);
|
|
634
650
|
|
|
635
651
|
/* 2. Load HTML */
|
|
636
652
|
plutobook_clear_error_message();
|
|
637
653
|
|
|
654
|
+
base_url_str = "";
|
|
655
|
+
if (!NIL_P(pageprint_options.base_url)) {
|
|
656
|
+
base_url_str = StringValueCStr(pageprint_options.base_url);
|
|
657
|
+
}
|
|
658
|
+
|
|
638
659
|
load_args.book = book;
|
|
639
660
|
load_args.html = html_str;
|
|
640
661
|
load_args.length = (int)html_len;
|
|
641
662
|
load_args.user_style = "";
|
|
642
663
|
load_args.user_script = "";
|
|
643
|
-
load_args.base_url =
|
|
664
|
+
load_args.base_url = base_url_str;
|
|
644
665
|
load_args.ok = 0;
|
|
645
666
|
|
|
667
|
+
RB_GC_GUARD(html);
|
|
668
|
+
RB_GC_GUARD(options);
|
|
669
|
+
RB_GC_GUARD(pageprint_options.base_url);
|
|
670
|
+
RB_GC_GUARD(pageprint_options.resource_fetcher);
|
|
671
|
+
RB_GC_GUARD(pageprint_options.metadata);
|
|
672
|
+
|
|
646
673
|
rb_thread_call_without_gvl(
|
|
647
674
|
pageprint_load_html_without_gvl,
|
|
648
675
|
&load_args,
|
|
@@ -665,7 +692,20 @@ static plutobook_t *pageprint_create_book_from_html(VALUE html, VALUE options, p
|
|
|
665
692
|
rb_jump_tag(resource_fetcher->state);
|
|
666
693
|
}
|
|
667
694
|
|
|
668
|
-
|
|
695
|
+
{
|
|
696
|
+
pageprint_apply_metadata_args_t metadata_args;
|
|
697
|
+
int metadata_state = 0;
|
|
698
|
+
|
|
699
|
+
metadata_args.book = book;
|
|
700
|
+
metadata_args.metadata = pageprint_options.metadata;
|
|
701
|
+
|
|
702
|
+
rb_protect(pageprint_apply_metadata_with_gvl, (VALUE)&metadata_args, &metadata_state);
|
|
703
|
+
|
|
704
|
+
if (metadata_state) {
|
|
705
|
+
plutobook_destroy(book);
|
|
706
|
+
rb_jump_tag(metadata_state);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
669
709
|
|
|
670
710
|
return book;
|
|
671
711
|
}
|
|
@@ -734,6 +774,11 @@ static VALUE pageprint_html_to_pdf(int argc, VALUE *argv, VALUE self) {
|
|
|
734
774
|
write_args.path = path_str;
|
|
735
775
|
write_args.ok = 0;
|
|
736
776
|
|
|
777
|
+
RB_GC_GUARD(html);
|
|
778
|
+
RB_GC_GUARD(options);
|
|
779
|
+
RB_GC_GUARD(resource_fetcher.object);
|
|
780
|
+
RB_GC_GUARD(path);
|
|
781
|
+
|
|
737
782
|
rb_thread_call_without_gvl(
|
|
738
783
|
pageprint_write_pdf_without_gvl,
|
|
739
784
|
&write_args,
|
|
@@ -751,10 +796,6 @@ static VALUE pageprint_html_to_pdf(int argc, VALUE *argv, VALUE self) {
|
|
|
751
796
|
pageprint_raise_plutobook_error_with_path(rb_eRuntimeError, "failed to write PDF to", path_str);
|
|
752
797
|
}
|
|
753
798
|
|
|
754
|
-
RB_GC_GUARD(resource_fetcher.object);
|
|
755
|
-
RB_GC_GUARD(options);
|
|
756
|
-
RB_GC_GUARD(path);
|
|
757
|
-
|
|
758
799
|
return Qtrue;
|
|
759
800
|
}
|
|
760
801
|
|
|
@@ -783,6 +824,11 @@ static VALUE pageprint_html_to_pdf_string(int argc, VALUE *argv, VALUE self) {
|
|
|
783
824
|
write_args.output = &output;
|
|
784
825
|
write_args.ok = 0;
|
|
785
826
|
|
|
827
|
+
RB_GC_GUARD(html);
|
|
828
|
+
RB_GC_GUARD(options);
|
|
829
|
+
RB_GC_GUARD(resource_fetcher.object);
|
|
830
|
+
RB_GC_GUARD(output.output);
|
|
831
|
+
|
|
786
832
|
rb_thread_call_without_gvl(
|
|
787
833
|
pageprint_write_pdf_stream_without_gvl,
|
|
788
834
|
&write_args,
|
|
@@ -804,10 +850,6 @@ static VALUE pageprint_html_to_pdf_string(int argc, VALUE *argv, VALUE self) {
|
|
|
804
850
|
pageprint_raise_plutobook_error(rb_eRuntimeError, "failed to write PDF to string");
|
|
805
851
|
}
|
|
806
852
|
|
|
807
|
-
RB_GC_GUARD(resource_fetcher.object);
|
|
808
|
-
RB_GC_GUARD(options);
|
|
809
|
-
RB_GC_GUARD(output.output);
|
|
810
|
-
|
|
811
853
|
return output.output;
|
|
812
854
|
}
|
|
813
855
|
|
data/lib/page_print/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: page_print
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dino Maric
|
|
@@ -40,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
40
40
|
requirements:
|
|
41
41
|
- - ">="
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: '3.
|
|
43
|
+
version: '3.2'
|
|
44
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|