Class: GTK::Webkit
- Inherits:
-
Object
- Object
- GTK::Webkit
- Defined in:
- lib/gtk_webkit_pdf.rb,
ext/gtk_webkit_pdf/webkit.c
Constant Summary collapse
- VERSION =
"0.0.2.2"
- CONTENT =
0
- FILEPATH =
1
- HTTP_URI =
2
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#options ⇒ Object
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #generate_pdf ⇒ Object
- #gtk_printer ⇒ Object
-
#initialize(source, format, options = {}) ⇒ Webkit
constructor
A new instance of Webkit.
Constructor Details
#initialize(source, format, options = {}) ⇒ Webkit
Returns a new instance of Webkit.
17 18 19 20 21 22 |
# File 'lib/gtk_webkit_pdf.rb', line 17 def initialize(source, format, = {}) @source = source @format = format @options = { :mime_type => 'text/html', :encoding => 'UTF-8' }.merge() raise WebkitError, 'format should be 0 or 1 or 2' unless [CONTENT, FILEPATH, HTTP_URI].member?(@format) end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
15 16 17 |
# File 'lib/gtk_webkit_pdf.rb', line 15 def format @format end |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/gtk_webkit_pdf.rb', line 15 def @options end |
#source ⇒ Object
Returns the value of attribute source.
15 16 17 |
# File 'lib/gtk_webkit_pdf.rb', line 15 def source @source end |
Instance Method Details
#generate_pdf ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'ext/gtk_webkit_pdf/webkit.c', line 15
static VALUE c_generate_pdf(VALUE self) {
VALUE source, content;
WEBKIT_PTR(self);
webkit -> webkit_webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
source = rb_iv_get(self, "@source");
switch(NUM2INT(rb_iv_get(self, "@format"))) {
case 0:
webkit_web_view_load_string(webkit -> webkit_webview, StringValuePtr(source), NULL, NULL, "file://");
break;
case 1:
content = rb_funcall(self, rb_intern("source_content"), 0, 0);
webkit_web_view_load_html_string(webkit -> webkit_webview, StringValuePtr(content), "file://");
break;
case 2:
webkit_web_view_load_uri(webkit -> webkit_webview, StringValuePtr(source));
break;
}
g_signal_connect(webkit -> webkit_webview, "load-finished", G_CALLBACK(webkit_load_finished), (void *)self);
gtk_main();
return webkit -> printer;
}
|
#gtk_printer ⇒ Object
24 25 26 |
# File 'lib/gtk_webkit_pdf.rb', line 24 def gtk_printer @gtk_printer ||= generate_pdf end |