gtk_webkit_pdf 0.0.1 → 0.0.2

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.
data/README CHANGED
@@ -1,15 +1,57 @@
1
1
  Creating The PDF from HTML using GTK WEBKIT Tool.
2
2
 
3
+ MAIN FEATURE OF GTK_WEBKIT_PDF
4
+ ==============================
5
+ 1 . This is pure ruby extension based pdf creator using gtk webkit api.
6
+
7
+ FEATURE ADDED WITH THIS NEW VERSION 0.0.2
8
+ =========================================
9
+ 1 . Supports for RAILS integration.
10
+ 2 . Create pdf based on the format in the controller with various options.
11
+ 3 . Supports for rake level pdf creation.
12
+
3
13
  EXAMPLE:
4
14
 
5
- webkit = GTK::Webkit.new(url) #creates the webkit object
6
- webkit.convert_to_pdf(path, pdf_name) #creates the pdf specified in the initialization parameter(in our case gtk.pdf) in current directory
15
+ webkit = GTK::Webkit.new(string_data, format, options) #creates the webkit object
16
+ where "format" => 1 . 0(zero) - means you are giving the html string to the first parameter(that is string_data).
17
+ 2 . 1(one) - future usage.
18
+ 3 . 2(two) - means you are giving the URI to the first parameter(that is string_data).
19
+
20
+ printer = webkit.gtk_printer #which returns the printer object, using this printer object you get the pdf content like below
21
+ printer.pdf_content #returns pdf contenht as a string, then you can save this pdf content to a file or you can render using
22
+ #"send_data"(in the case of download)
23
+ #You can also export to a file using the following
24
+ printer.export(base_url, filename) #base_url => base directory(like /home/mohanraj/)
25
+ #filename => name of the file, you want to export
26
+
27
+ CONTROLLER BASED PDF CREATION
28
+ ============================
29
+
30
+ In your controller just check the format, and render the pdf like below,
31
+
32
+ class UsersController < ApplicationController
33
+ def index
34
+ @users = User.scoped
35
+ respond_to do |format|
36
+ format.html
37
+ format.pdf{ render :pdf => "pdf_name" }
38
+ end
39
+ end
40
+ end
7
41
 
8
- Parameters Description:
9
- 1 . url => Actual webkit URL. Ex http://www.gtk.org/, http://www.google.com
10
- 2 . path => System path, where the pdf will be saved. Ex: /home/user/Documents/
11
- 3 . pdf_name => Actual name to PDF file. Ex: gtk.pdf, google.pdf
42
+ available options while rendering pdf,
43
+ :layout => specify the layout, otherwise layout is false
44
+ :template => template name to render
45
+ :file => file to use
46
+ :disposition => default to "inline"
47
+ :format =>
48
+ :handler =>
12
49
 
50
+ NOTE: you have to create the view file for pdf like "index.pdf.erb" in the case of pdf render
13
51
 
52
+ MIDDLEWARE SUPPORT
53
+ ==================
54
+ You can enable middleware by adding following line to config/application.rb
55
+ config.middleware.use GTK::Middleware
14
56
 
15
- This is the first version of the gem, we will update the readme as well the gem features ASAP.
57
+ Thanks to GTK WEBKIT community.
@@ -1,6 +1,6 @@
1
1
  require 'mkmf'
2
2
 
3
- $CFLAGS << " -I /usr/include/gtk-2.0/ -I /usr/include/glib-2.0/ -Wall -Werror -fpic -I /usr/lib/i386-linux-gnu/glib-2.0/include/ -I /usr/include/cairo/ -I /usr/include/pango-1.0/ -I /usr/lib/i386-linux-gnu/gtk-2.0/include -I /usr/include/gdk-pixbuf-2.0/ -I /usr/include/atk-1.0/ -I /usr/include/webkitgtk-1.0/ -I /usr/include/libsoup-2.4/"
3
+ $CFLAGS << " -I /usr/include/gtk-3.0/ -I /usr/include/glib-2.0/ -Wall -Werror -fpic -I /usr/lib/i386-linux-gnu/glib-2.0/include/ -I /usr/include/cairo/ -I /usr/include/pango-1.0/ -I /usr/lib/i386-linux-gnu/gtk-3.0/include -I /usr/include/gdk-pixbuf-2.0/ -I /usr/include/atk-1.0/ -I /usr/include/webkitgtk-3.0/ -I /usr/include/libsoup-2.4/"
4
4
 
5
- $LIBS << " -L /usr/lib/i386-linux-gnu/ -lgtk-3 -L /usr/lib/webkitgtk-1.0-0/ -lwebkitgtk-3.0"
5
+ $LIBS << " -L /usr/lib/i386-linux-gnu/ -lgtk-3 -lwebkitgtk-3.0"
6
6
  create_makefile("gtk_webkit_pdf/webkit")
@@ -5,19 +5,23 @@
5
5
 
6
6
  VALUE cPrinter = Qnil;
7
7
 
8
- static VALUE c_printer_new(VALUE self) {
8
+ static VALUE printer_allocate(VALUE klass) {
9
9
  printer_wrapper *printer;
10
- VALUE data_object = Data_Make_Struct(self, printer_wrapper, 0, free_printer, printer);
11
- gtk_init(NULL, NULL);
12
- init_printer_configurations(data_object);
10
+ VALUE data_object = Data_Make_Struct(klass, printer_wrapper, 0, free_printer, printer);
13
11
  return data_object;
14
12
  }
15
13
 
16
- static VALUE c_export_to_pdf(VALUE self, VALUE source, VALUE directory_path, VALUE file_name) {
17
- char *pdf_path;
14
+ static VALUE c_webkit_webframe_to_pdf(VALUE self, VALUE source) {
15
+ VALUE temp_path;
18
16
  WEBKIT_PRINTER_PTR(self, source);
19
- STR_CON_CAT(directory_path, file_name);
20
- gtk_print_operation_set_export_filename(printer -> gtk_print_operation, pdf_path);
17
+ gtk_init(NULL, NULL);
18
+
19
+ //PRINTER CONFIGURATIONS
20
+ set_printer_configurations(self);
21
+
22
+ //EXPORT PDF FROM WEBKIT WEBFRAME
23
+ temp_path = rb_funcall(self, rb_intern("temp_path"), 0, 0);
24
+ gtk_print_operation_set_export_filename(printer -> gtk_print_operation, StringValuePtr(temp_path));
21
25
  printer -> gtk_print_operation_result = webkit_web_frame_print_full(webkit -> webkit_webframe,
22
26
  printer -> gtk_print_operation, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL);
23
27
 
@@ -27,11 +31,12 @@ static VALUE c_export_to_pdf(VALUE self, VALUE source, VALUE directory_path, VAL
27
31
  printer -> print_status = Qtrue;
28
32
  }
29
33
  g_object_unref(printer -> gtk_print_operation);
30
- return printer -> print_status;
34
+ return printer -> print_status == Qtrue ? self : Qnil;
31
35
  }
32
36
 
33
37
  void init_printer() {
34
38
  cPrinter = rb_define_class_under(cGTK, "Printer", rb_cObject);
35
- rb_define_singleton_method(cPrinter, "new", c_printer_new, 0);
36
- rb_define_private_method(cPrinter, "export_to_pdf", c_export_to_pdf, 3);
39
+ rb_define_alloc_func(cPrinter, printer_allocate);
40
+
41
+ rb_define_method(cPrinter, "webkit_webframe_to_pdf", c_webkit_webframe_to_pdf, 1);
37
42
  }
@@ -5,7 +5,7 @@ void free_printer(void *void_printer) {
5
5
  free(printer);
6
6
  }
7
7
 
8
- void init_printer_configurations(VALUE self) {
8
+ void set_printer_configurations(VALUE self) {
9
9
  PRINTER_PTR(self);
10
10
  printer -> gtk_print_settings = NULL;
11
11
  printer -> gtk_print_operation = gtk_print_operation_new();
@@ -15,7 +15,7 @@ typedef struct {
15
15
  } printer_wrapper;
16
16
 
17
17
  extern void free_printer(void *void_printer);
18
- extern void init_printer_configurations(VALUE self);
18
+ extern void set_printer_configurations(VALUE self);
19
19
  extern void begin_print();
20
20
  extern void draw_page();
21
21
 
@@ -8,34 +8,17 @@ void free_webkit(void *void_webkit) {
8
8
  void mark_webkit_printer(void *void_webkit) {
9
9
  webkit_wrapper *webkit = void_webkit;
10
10
  if(webkit) {
11
- rb_gc_mark(webkit -> data_printer);
12
- rb_gc_mark(webkit -> print_status);
11
+ rb_gc_mark(webkit -> printer);
13
12
  }
14
13
  }
15
14
 
16
- void activate_gtk_webkit(VALUE self) {
17
- WEBKIT_PTR(self);
18
- webkit -> data_printer = Qnil;
19
- webkit -> webkit_webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
20
- webkit_web_view_load_uri(webkit -> webkit_webview, webkit -> webkit_url);
21
- g_signal_connect(webkit -> webkit_webview, "load-finished", G_CALLBACK(webkit_load_finished), (void *)self);
22
- }
23
-
24
15
  void webkit_load_finished(WebKitWebView *webView, WebKitWebFrame *webkitwebframe, void *self) {
25
- VALUE argv[3];
26
- WEBKIT_PTR(CAST_TO_VALUE(self));
16
+ VALUE argv[1], printer;
17
+ WEBKIT_PTR((VALUE)self);
27
18
  webkit -> webkit_webframe = webkit_web_view_get_main_frame(webkit -> webkit_webview);
28
19
 
29
- webkit -> data_printer = rb_funcall(cPrinter, rb_intern("new"), 0);
30
- argv[0] = CAST_TO_VALUE(self);
31
- argv[1] = C_TO_RUBY_STR(webkit -> dir_path);
32
- argv[2] = C_TO_RUBY_STR(webkit -> pdf_filename);
33
- webkit -> print_status = rb_funcall2(webkit -> data_printer, rb_intern("export_to_pdf"), 3, argv);
20
+ argv[0] = (VALUE)self;
21
+ printer = rb_funcall(cPrinter, rb_intern("new"), 0, 0);
22
+ webkit -> printer = rb_funcall2(printer, rb_intern("webkit_webframe_to_pdf"), 1, argv);
34
23
  gtk_main_quit();
35
24
  }
36
-
37
- void set_pdf_configurations(VALUE self, VALUE dir_path, VALUE pdf_filename) {
38
- WEBKIT_PTR(self);
39
- webkit -> dir_path = StringValuePtr(dir_path);
40
- webkit -> pdf_filename = StringValuePtr(pdf_filename);
41
- }
@@ -9,19 +9,13 @@
9
9
  WebKitWebView *webkit_webview;
10
10
  WebKitWebFrame *webkit_webframe;
11
11
 
12
- char *webkit_url;
13
- char *dir_path;
14
- char *pdf_filename;
15
- VALUE print_status;
16
- VALUE data_printer;
12
+ VALUE printer;
17
13
  } webkit_wrapper;
18
14
 
19
15
  extern void webkit_load_finished(WebKitWebView *webView, WebKitWebFrame *webkitwebframe, void *self);
20
16
 
21
17
  extern void free_webkit(void *void_webkit);
22
18
  extern void mark_webkit_printer(void *void_webkit);
23
- extern void activate_gtk_webkit(VALUE self);
24
- extern void set_pdf_configurations(VALUE self, VALUE dir_path, VALUE pdf_filename);
25
19
 
26
20
  extern void init_printer();
27
21
  extern VALUE cPrinter;
@@ -32,13 +26,5 @@
32
26
  #define C_TO_RUBY_STR(str) rb_str_new2(str)
33
27
 
34
28
  #define RUBY_TO_C_STR(str) StringValuePtr(str)
35
-
36
- #define CAST_TO_VALUE(value) (VALUE)value
37
-
38
- #define STR_CON_CAT(dir, name) pdf_path = malloc(strlen(RUBY_TO_C_STR(dir)) + strlen(RUBY_TO_C_STR(name)) + 1); \
39
- if(pdf_path != NULL) { \
40
- strcpy(pdf_path, RUBY_TO_C_STR(dir)); \
41
- strcpy(&pdf_path[strlen(RUBY_TO_C_STR(dir))], RUBY_TO_C_STR(name)); \
42
- } \
43
29
 
44
30
  #endif
@@ -6,31 +6,43 @@
6
6
  VALUE cGTK = Qnil;
7
7
  VALUE cWebkit = Qnil;
8
8
 
9
- static VALUE c_new(VALUE self, VALUE webkit_url) {
9
+ static VALUE webkit_allocate(VALUE klass) {
10
10
  webkit_wrapper *webkit;
11
- VALUE argv[1];
12
- VALUE data_object = Data_Make_Struct(self, webkit_wrapper, mark_webkit_printer, free_webkit, webkit);
13
- webkit -> webkit_url = StringValuePtr(webkit_url);
14
-
15
- argv[0] = webkit_url;
16
- rb_obj_call_init(data_object, 1, argv);
11
+ VALUE data_object = Data_Make_Struct(klass, webkit_wrapper, mark_webkit_printer, free_webkit, webkit);
17
12
  return data_object;
18
13
  }
19
14
 
20
- static VALUE c_convert_to_pdf(VALUE self, VALUE dir_path, VALUE pdf_filename) {
21
- WEBKIT_PTR(self);
15
+ static VALUE c_generate_pdf(VALUE self) {
16
+ VALUE source, content;
17
+ WEBKIT_PTR(self);
22
18
  gtk_init(NULL, NULL);
23
- set_pdf_configurations(self, dir_path, pdf_filename);
24
- activate_gtk_webkit(self);
19
+
20
+ webkit -> webkit_webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
21
+ source = rb_iv_get(self, "@source");
22
+
23
+ switch(NUM2INT(rb_iv_get(self, "@format"))) {
24
+ case 0:
25
+ webkit_web_view_load_string(webkit -> webkit_webview, StringValuePtr(source), NULL, NULL, "file://");
26
+ break;
27
+ case 1:
28
+ content = rb_funcall(self, rb_intern("source_content"), 0, 0);
29
+ webkit_web_view_load_html_string(webkit -> webkit_webview, StringValuePtr(content), "file://");
30
+ break;
31
+ case 2:
32
+ webkit_web_view_load_uri(webkit -> webkit_webview, StringValuePtr(source));
33
+ break;
34
+ }
35
+ g_signal_connect(webkit -> webkit_webview, "load-finished", G_CALLBACK(webkit_load_finished), (void *)self);
25
36
  gtk_main();
26
- return webkit -> print_status;
37
+ return webkit -> printer;
27
38
  }
28
39
 
29
40
  void Init_webkit(void) {
30
41
  cGTK = rb_define_module("GTK");
31
42
  cWebkit = rb_define_class_under(cGTK, "Webkit", rb_cObject);
32
- rb_define_singleton_method(cWebkit, "new", c_new, 1);
33
- rb_define_method(cWebkit, "convert_to_pdf", c_convert_to_pdf, 2);
43
+
44
+ rb_define_alloc_func(cWebkit, webkit_allocate);
45
+ rb_define_method(cWebkit, "generate_pdf", c_generate_pdf, 0);
34
46
 
35
47
  init_printer();
36
48
  }
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'gtk_webkit_pdf'
3
- s.version = '0.0.1'
4
- s.date = '2013-01-04'
3
+ s.version = '0.0.2'
4
+ s.date = Time.now.strftime("%Y-%m-%d")
5
5
  s.summary = "GTK WEBKIT"
6
+ s.homepage = "https://github.com/mohanraj-ramanujam/gtk_webkit_pdf"
6
7
  s.description = "Generates the PDF from the HTML using GTK WEBKIT"
7
8
  s.authors = ["Mohanraj Ramanujam"]
8
9
  s.email = 'mohanraj.ramanujam@gmail.com'
9
10
  s.files = Dir.glob("lib/**/*.rb") + Dir.glob("ext/**/*.{c,h}") + ['README', 'gtk_webkit_pdf.gemspec']
10
11
  s.extensions = ["ext/gtk_webkit_pdf/extconf.rb"]
11
12
  s.executables = ["webkit"]
12
- s.homepage =
13
- 'http://rubygems.org/gems/gtk_webkit_pdf'
13
+ s.add_dependency('rails')
14
14
  end
@@ -0,0 +1,32 @@
1
+ module GTK
2
+ module ControllersHelper
3
+ def self.included(base)
4
+ return if base != ActionController::Base
5
+
6
+ base.class_eval do
7
+ alias_method_chain :render, :gtk_webkit_pdf
8
+ end
9
+ end
10
+
11
+ def render_with_gtk_webkit_pdf(options = {}, *args, &block)
12
+ if options.is_a?(Hash) && options.has_key?(:pdf)
13
+ make_and_send_pdf(options.delete(:pdf), render_options(options))
14
+ else
15
+ render_without_gtk_webkit_pdf(options, *args, &block)
16
+ end
17
+ end
18
+
19
+ def make_and_send_pdf(pdf_name = nil, options = {})
20
+ html_string = render_to_string(options)
21
+ gtk_printer = GTK::Webkit.new(html_string, 0).gtk_printer
22
+ send_data(gtk_printer.pdf_content, :file_name => pdf_name+'.pdf', :type => 'application/pdf', :disposition => options[:disposition])
23
+ end
24
+
25
+ private
26
+ def render_options(options = {})
27
+ options[:template] = File.join(controller_path, action_name)
28
+ options[:layout] ||= false
29
+ options[:file] ? options.merge(:file => options[:file]) : options
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,55 @@
1
+ module GTK
2
+ class Middleware
3
+ def initialize(app, options = {}, conditions = {})
4
+ @app = app
5
+ @options = options
6
+ @conditions = conditions
7
+ end
8
+
9
+ def call(env)
10
+ @request = Rack::Request.new(env)
11
+ @render_pdf = false
12
+
13
+ convert_pdf_request_to_html(env) if pdf_request?
14
+ status, headers, response = @app.call(env)
15
+
16
+ if @render_pdf && headers['Content-Type'] =~ /text\/html|application\/xhtml\+xml/
17
+ body = response.respond_to?(:body) ? response.body : response.join
18
+ body = body.join if body.is_a?(Array)
19
+
20
+ printer = GTK::Webkit.new(prepend_absolute_path(body, env), 0).gtk_printer
21
+ body = printer.pdf_content
22
+ response = [body]
23
+
24
+ headers.delete 'ETag'
25
+ headers.delete 'Cache-Control'
26
+
27
+ headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
28
+ headers['Content-Type'] = 'application/pdf'
29
+ end
30
+ [status, headers, response]
31
+ end
32
+
33
+ private
34
+ def prepend_absolute_path(body, env)
35
+ prepend_path = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}/"
36
+ body.gsub(/(href|src)=(['"])\/([^\"']*|[^"']*)['"]/, '\1=\2' + prepend_path + '\3\2')
37
+ end
38
+
39
+ def convert_pdf_request_to_html(env)
40
+ @render_pdf = true
41
+ path = @request.path.sub(%r{\.pdf$}, '')
42
+ %w(PATH_INFO REQUEST_URI).each{ |e| env[e] = path }
43
+ env['HTTP_ACCEPT'] = concat(env['HTTP_ACCEPT'], Rack::Mime.mime_type('.html'))
44
+ env['Rack-Middleware-Gtk-Webkit-Pdf'] = "true"
45
+ end
46
+
47
+ def concat(accepts, type)
48
+ (accepts || '').split(',').unshift(type).compact.join(',')
49
+ end
50
+
51
+ def pdf_request?
52
+ @request.path.match(/\.pdf$/)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,19 @@
1
+ module GTK
2
+ class Printer
3
+ attr_accessor :tempfile
4
+
5
+ def initialize
6
+ @tempfile = Tempfile.new(Time.now.to_s)
7
+ end
8
+
9
+ def pdf_content; File.read(tempfile); end
10
+
11
+ def export(base_url, name)
12
+ File.open(File.join(base_url, name), 'w+'){ |f| f.write pdf_content }
13
+ end
14
+
15
+ def temp_path; tempfile.path; end
16
+
17
+ def delete_pdf; tempfile.delete; end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module GTK
2
+ if defined?(Rails)
3
+ class Railtie < Rails::Railtie
4
+ initializer 'gtk_webkit_pdf.register' do |app|
5
+ ActionController::Base.send :include, GTK::ControllersHelper
6
+
7
+ if Rails::VERSION::MINOR > 0 && Rails.configuration.assets.enabled
8
+ ActionView::Base.send :include, AssetsHelper
9
+ else
10
+ ActionView::Base.send :include, ViewsHelper
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ if Mime::Type.lookup_by_extension(:pdf).nil?
17
+ Mime::Type.register('application/pdf', :pdf)
18
+ end
19
+ end
@@ -0,0 +1,72 @@
1
+ module GTK
2
+ module ViewsHelper
3
+ def self.root_path
4
+ String === Rails.root ? Pathname.new(Rails.root) : Rails.root
5
+ end
6
+
7
+ def gtk_webkit_pdf_stylesheet_link_tag(*sources)
8
+ css_dir = ViewsHelper.root_path.join('app', 'assets', 'stylesheets')
9
+ css_text = sources.collect { |source| "<style type='text/css'>#{File.read(css_dir.join(sources+'.css'))}</style>" }.join('\n')
10
+ css_text.respond_to?(:html_safe) ? css_text.html_safe : css_text
11
+ end
12
+
13
+ def gtk_webkit_pdf_image_tag(img, options = {})
14
+ image_tag("file:///#{ViewsHelper.root_path.join('app', 'assets', 'images', img)}", options)
15
+ end
16
+
17
+ def gtk_webkit_pdf_javascript_src_tag(jsfile, options = {})
18
+ javascript_src_tag("file:///#{ViewsHelper.root_path.join('app', 'assets', 'javascripts', jsfile)}", options)
19
+ end
20
+
21
+ def gtk_webkit_pdf_javascript_include_tag(*sources)
22
+ js_text = sources.collect { |source| gtk_webkit_pdf_javascript_src_tag(source, {}) }.join('\n')
23
+ js_text.respond_to?(:html_safe) ? js_text.html_safe : js_text
24
+ end
25
+ end
26
+
27
+ module AssetsHelper
28
+ def gtk_webkit_pdf_stylesheet_link_tag(*sources)
29
+ sources.collect { |source| "<style type='text/css'>#{read_asset(source+".css")}</style>" }.join('\n').html_safe
30
+ end
31
+
32
+ def gtk_webkit_pdf_image_tag(img, options={})
33
+ image_tag("file://#{asset_pathname(img).to_s}", options)
34
+ end
35
+
36
+ def gtk_webkit_pdf_javascript_src_tag(jsfile, options={})
37
+ javascript_include_tag("file:///#{asset_pathname(jsfile).to_s}", options)
38
+ end
39
+
40
+ def gtk_webkit_pdf_javascript_include_tag(*sources)
41
+ sources.collect { |source| "<script type='text/javascript'>#{read_asset(source+".js")}</script>" }.join('\n').html_safe
42
+ end
43
+
44
+ private
45
+
46
+ def asset_pathname(source)
47
+ if Rails.configuration.assets.compile == false
48
+ if ActionController::Base.asset_host
49
+ # asset_path returns an absolute URL using asset_host if asset_host is set
50
+ asset_path(source)
51
+ else
52
+ File.join(Rails.public_path, asset_path(source).sub(/\A#{Rails.application.config.action_controller.relative_url_root}/, ''))
53
+ end
54
+ else
55
+ Rails.application.assets.find_asset(source).pathname
56
+ end
57
+ end
58
+
59
+ def read_asset(source)
60
+ if Rails.configuration.assets.compile == false
61
+ if ActionController::Base.asset_host
62
+ require 'open-uri'
63
+ open(asset_pathname(source), 'r:UTF-8') {|f| f.read }
64
+ else
65
+ IO.read(asset_pathname(source))
66
+ end
67
+ else
68
+ Rails.application.assets.find_asset(source).to_s
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,36 @@
1
+ require 'gtk_webkit_pdf/gtk_printer_pdf'
2
+ require 'gtk_webkit_pdf/gtk_controllers_helper_pdf'
3
+ require 'gtk_webkit_pdf/gtk_views_helper_pdf'
4
+ require 'gtk_webkit_pdf/gtk_railtie_pdf'
5
+ require 'gtk_webkit_pdf/gtk_middleware_pdf'
6
+ require 'gtk_webkit_pdf/webkit'
7
+
8
+ module GTK
9
+ class Webkit
10
+ VERSION = 0.0.2
11
+ CONTENT = 0
12
+ FILEPATH = 1
13
+ HTTP_URI = 2
14
+
15
+ attr_accessor :source, :format, :options
16
+
17
+ def initialize(source, format, options = {})
18
+ @source = source
19
+ @format = format
20
+ @options = { :mime_type => 'text/html', :encoding => 'UTF-8' }.merge(options)
21
+ raise WebkitError, 'format should be 0 or 1 or 2' unless [CONTENT, FILEPATH, HTTP_URI].member?(@format)
22
+ end
23
+
24
+ def gtk_printer
25
+ @gtk_printer ||= generate_pdf
26
+ end
27
+
28
+ private
29
+ def source_content
30
+ File.read(@source) if @format == FILEPATH
31
+ end
32
+ end
33
+
34
+ class WebkitError < StandardError
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk_webkit_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-04 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-01-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: Generates the PDF from the HTML using GTK WEBKIT
15
31
  email: mohanraj.ramanujam@gmail.com
16
32
  executables: []
@@ -18,7 +34,12 @@ extensions:
18
34
  - ext/gtk_webkit_pdf/extconf.rb
19
35
  extra_rdoc_files: []
20
36
  files:
21
- - lib/gtk_webkit_pdf/gtk_webkit_pdf.rb
37
+ - lib/gtk_webkit_pdf/gtk_railtie_pdf.rb
38
+ - lib/gtk_webkit_pdf/gtk_middleware_pdf.rb
39
+ - lib/gtk_webkit_pdf/gtk_controllers_helper_pdf.rb
40
+ - lib/gtk_webkit_pdf/gtk_printer_pdf.rb
41
+ - lib/gtk_webkit_pdf/gtk_views_helper_pdf.rb
42
+ - lib/gtk_webkit_pdf.rb
22
43
  - ext/gtk_webkit_pdf/utility.c
23
44
  - ext/gtk_webkit_pdf/webkit.c
24
45
  - ext/gtk_webkit_pdf/printer_utility.c
@@ -30,7 +51,7 @@ files:
30
51
  - README
31
52
  - gtk_webkit_pdf.gemspec
32
53
  - ext/gtk_webkit_pdf/extconf.rb
33
- homepage: http://rubygems.org/gems/gtk_webkit_pdf
54
+ homepage: https://github.com/mohanraj-ramanujam/gtk_webkit_pdf
34
55
  licenses: []
35
56
  post_install_message:
36
57
  rdoc_options: []
@@ -1,12 +0,0 @@
1
- module GTK
2
- class Webkit
3
- attr_accessor :webkit_url
4
-
5
- def initialize(webkit_url)
6
- @webkit_url = webkit_url
7
- end
8
- end
9
- end
10
-
11
- #require the SO(shared object) file
12
- require "gtk_webkit_pdf/webkit"