Module: PagePrint
- Defined in:
- lib/page_print.rb,
lib/page_print/railtie.rb,
lib/page_print/version.rb,
lib/page_print/rails_resource_fetcher.rb,
ext/page_print/page_print.c
Defined Under Namespace
Classes: RailsResourceFetcher, Railtie
Constant Summary collapse
- VERSION =
'0.1.7'
Class Attribute Summary collapse
- .base_url ⇒ Object
-
.resource_fetcher ⇒ Object
Returns the value of attribute resource_fetcher.
Class Method Summary collapse
- .configure {|_self| ... } ⇒ Object
- .html_to_pdf(*args) ⇒ Object
- .html_to_pdf_string(*args) ⇒ Object
- .with_base_url(base_url) ⇒ Object
Class Attribute Details
.base_url ⇒ Object
10 11 12 |
# File 'lib/page_print.rb', line 10 def base_url Thread.current[:page_print_base_url] || @base_url end |
.resource_fetcher ⇒ Object
Returns the value of attribute resource_fetcher.
7 8 9 |
# File 'lib/page_print.rb', line 7 def resource_fetcher @resource_fetcher end |
Class Method Details
.configure {|_self| ... } ⇒ Object
14 15 16 |
# File 'lib/page_print.rb', line 14 def configure yield self end |
.html_to_pdf(*args) ⇒ Object
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
# File 'ext/page_print/page_print.c', line 742
static VALUE pageprint_html_to_pdf(int argc, VALUE *argv, VALUE self) {
VALUE html;
VALUE path;
VALUE options;
const char *path_str;
plutobook_t *book;
pageprint_resource_fetcher_t resource_fetcher;
pageprint_write_pdf_args_t write_args;
rb_check_arity(argc, 2, 3);
html = argv[0];
path = argv[1];
options = argc == 3 ? argv[2] : Qnil;
if (!RB_TYPE_P(path, T_STRING)) {
rb_raise(rb_eTypeError, "path must be a String");
}
if (RSTRING_LEN(path) == 0) {
rb_raise(rb_eArgError, "path must not be empty");
}
path_str = StringValueCStr(path);
book = pageprint_create_book_from_html(html, options, &resource_fetcher);
plutobook_clear_error_message();
write_args.book = book;
write_args.path = path_str;
write_args.ok = 0;
RB_GC_GUARD(html);
RB_GC_GUARD(options);
RB_GC_GUARD(resource_fetcher.object);
RB_GC_GUARD(path);
rb_thread_call_without_gvl(
pageprint_write_pdf_without_gvl,
&write_args,
RUBY_UBF_IO,
NULL
);
plutobook_destroy(book);
if (resource_fetcher.state) {
rb_jump_tag(resource_fetcher.state);
}
if (!write_args.ok) {
pageprint_raise_plutobook_error_with_path(rb_eRuntimeError, "failed to write PDF to", path_str);
}
return Qtrue;
}
|
.html_to_pdf_string(*args) ⇒ Object
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
# File 'ext/page_print/page_print.c', line 802
static VALUE pageprint_html_to_pdf_string(int argc, VALUE *argv, VALUE self) {
VALUE html;
VALUE options;
pageprint_pdf_string_output_t output;
plutobook_t *book;
pageprint_resource_fetcher_t resource_fetcher;
pageprint_write_pdf_stream_args_t write_args;
rb_check_arity(argc, 1, 2);
html = argv[0];
options = argc == 2 ? argv[1] : Qnil;
output.output = rb_str_new(NULL, 0);
output.state = 0;
rb_enc_associate_index(output.output, rb_ascii8bit_encindex());
book = pageprint_create_book_from_html(html, options, &resource_fetcher);
plutobook_clear_error_message();
write_args.book = book;
write_args.output = &output;
write_args.ok = 0;
RB_GC_GUARD(html);
RB_GC_GUARD(options);
RB_GC_GUARD(resource_fetcher.object);
RB_GC_GUARD(output.output);
rb_thread_call_without_gvl(
pageprint_write_pdf_stream_without_gvl,
&write_args,
RUBY_UBF_IO,
NULL
);
plutobook_destroy(book);
if (resource_fetcher.state) {
rb_jump_tag(resource_fetcher.state);
}
if (output.state) {
rb_jump_tag(output.state);
}
if (!write_args.ok) {
pageprint_raise_plutobook_error(rb_eRuntimeError, "failed to write PDF to string");
}
return output.output;
}
|
.with_base_url(base_url) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/page_print.rb', line 18 def with_base_url(base_url) previous_base_url = Thread.current[:page_print_base_url] Thread.current[:page_print_base_url] = base_url yield ensure Thread.current[:page_print_base_url] = previous_base_url end |