wkhtmltopdf_for_rails 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjgyOGQyNWQxZWE5YmQ3NDJhYjM0YzEwZGQ0OTM3MTBjMDIxZjJjYQ==
4
+ MjcwYzdiMjE0MDI1ZDQ2N2QxYTQ1YjVhNTJmY2Q0MjU5YzNkMTg2Zg==
5
5
  data.tar.gz: !binary |-
6
- NDc3N2E4MGE4ODc0NDU0MTMyMzRmM2MxOGJlZTEzMmI1YzhlNWExNw==
6
+ NzcwMGNkMDJjNjUyY2IyMWE1OTk4YmUyMGE2MGEyMDZkYmVhMzZiZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDA2MWUzZTVkYWRjYTgwOTgxODdhMGZlZWQzZDI3ODQ4MTRhODRhYjJhNWVk
10
- NTIwNmFiZjdhYjY1MTg1NGVhNmQ4MjA5NTU0YjA4ZWUxZjNjNjJhNjZjYzE5
11
- ZThmZTk0NzY3NWFkNzZjYjUzOWVmYjUzMTVjY2M5ZjVmMTUyOWU=
9
+ MWMwNWU0NjJiZjI5ZGI3OGM1YjFiZTlhYzc5MjAzYjUyOTcxY2M2YjYyYjRj
10
+ NThiZjFiZTk4NTBiNTQxZDJkZTU1N2NkM2U0MjZiNTJjZDE1ZjJhNTdmZmU1
11
+ ODA2YjQ0ZGQ1NjhmNmIwYzE0NTQ1ZGRhZDgwOGQzM2EwNGQzNDU=
12
12
  data.tar.gz: !binary |-
13
- MDgxNzQ0ODA4N2NhZTQ0M2IxNDVmMDkyN2VhZjNjN2FkMWU2YTRiNDdkOThl
14
- ZTM2NDBhYjFiZjRkOGJlMDdiM2Q0Mzg4NzJjZTRkZDc5YzRmMTUxNTQxNjNk
15
- Mjc2YmE3ZGZjYmE4YjhjOTYwY2FiNDE1OWE5NWU5OWU0OTcwMjg=
13
+ N2ZkNGZjMTM4Yjk0YjVjNzYxYjM1NmE0NWQ4OTZkZDM5ZmEzZWRiYjI0MzIx
14
+ MzM2ZGQ1YzFkNTEwMDA3NzAxODc4ZWVjM2EwYmJiMTBiMWVjNGRjZWFiNDBm
15
+ ZWY5OWU4NTg2MmQxZjZmNzIwOWFjNTliOWZhZjJkOGI5ZDQwMTM=
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  pkg
2
+ bin
2
3
  Icon?
3
4
  .DS_Store
4
5
  TAGS
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wkhtmltopdf_for_rails (0.0.7)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.0.4)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ rake
16
+ wkhtmltopdf_for_rails!
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ task :clean do
7
+ sh "rm -rf pkg"
8
+ sh "rm -rf bin"
9
+ end
10
+
11
+ def get_binary_gemspec(platform = RUBY_PLATFORM)
12
+ gemspec = eval(File.read('wkhtmltopdf_for_rails.gemspec'))
13
+ gemspec.platform = Gem::Platform.new(platform)
14
+ gemspec
15
+ end
16
+
17
+ begin
18
+ binary_gem_name = File.basename get_binary_gemspec.cache_file
19
+ rescue
20
+ binary_gem_name = ''
21
+ end
22
+
23
+ desc "build a binary gem #{binary_gem_name}"
24
+ task :binary do
25
+ gemspec = get_binary_gemspec
26
+ gemspec.files += ['bin/wkhtmltopdf']
27
+
28
+ FileUtils.mkdir_p 'pkg'
29
+ FileUtils.mkdir_p 'bin'
30
+
31
+ FileUtils.cp "ext/wkhtmltopdf/wkhtmltopdf_#{gemspec.platform.os}", "bin/wkhtmltopdf"
32
+
33
+ package = if Gem::VERSION < '2.0.0'
34
+ Gem::Builder.new(gemspec).build
35
+ else
36
+ require 'rubygems/package'
37
+ Gem::Package.build(gemspec)
38
+ end
39
+
40
+ FileUtils.mv(package, 'pkg')
41
+ FileUtils.remove_dir('bin')
42
+ end
43
+
44
+ Rake::TestTask.new do |t|
45
+ t.libs << 'test'
46
+ t.test_files = FileList['test/**/*.rb']
47
+ t.verbose = true
48
+ end
49
+
50
+ desc "Run tests"
51
+ task :default => :test
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'rubygems/command.rb'
3
+ require 'fileutils'
4
+ require 'rbconfig'
5
+
6
+ begin
7
+ Gem::Command.build_args = ARGV
8
+ rescue NoMethodError
9
+ end
10
+
11
+ platform = RbConfig::CONFIG['host_os']
12
+ cpu = RbConfig::CONFIG['host_cpu']
13
+
14
+ if platform =~ /linux/ && cpu =~ /[3|4]86/
15
+ executable = 'wkhtmltopdf_linux'
16
+ elsif platform =~ /linux/ && cpu =~ /64/
17
+ executable = 'wkhtmltopdf_amd64'
18
+ elsif platform =~ /darwin/
19
+ executable = 'wkhtmltopdf_darwin'
20
+ else
21
+ raise "Invalid platform. Must be running linux or intel-based Mac OS."
22
+ end
23
+
24
+ FileUtils.mkdir_p '../bin'
25
+ FileUtils.cp "wkhtmltopdf/#{executable}", "../bin/wkhtmltopdf"
26
+
27
+ f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
28
+ f.write("task :default\n")
29
+ f.close
@@ -1,6 +1,6 @@
1
- require 'render_pdf'
2
- require 'wkhtmltopdf'
1
+ require 'wkhtmltopdf_for_rails/render_pdf'
2
+ require 'wkhtmltopdf_for_rails/wkhtmltopdf'
3
3
 
4
4
  Mime::Type.register 'application/pdf', :pdf unless Mime[:pdf]
5
5
 
6
- ActionController::Base.send(:include, RenderPdf)
6
+ ActionController::Base.send(:include, WkhtmltopdfForRails::RenderPdf)
@@ -0,0 +1,47 @@
1
+ module WkhtmltopdfForRails
2
+ module RenderPdf
3
+ def render_to_pdf(options = {})
4
+ send_data(
5
+ make_pdf(options),
6
+ :filename => "#{options[:pdf]}.pdf",
7
+ :type => 'application/pdf'
8
+ )
9
+ end
10
+
11
+ private
12
+
13
+ def make_pdf(options)
14
+ if options.has_key?(:template)
15
+ html_string = generate_html(options)
16
+ file = Tempfile.new([options[:pdf], '.html'])
17
+ file.write(html_string)
18
+ file.close
19
+ options[:html_file] = file.path
20
+ end
21
+
22
+ pdf = Wkhtmltopdf.new(options)
23
+ pdf.generate
24
+ ensure
25
+ file.unlink if file
26
+ end
27
+
28
+ def generate_html(options)
29
+ render_options = {}
30
+ render_options[:template] = options.delete(:template)
31
+ render_options[:formats] = options.delete(:formats)
32
+ render_options[:layout] = options.delete(:layout) if options.has_key?(:layout)
33
+
34
+ html_string = render_to_string(render_options).to_str
35
+
36
+ # re-route absolute paths for images, scripts and stylesheets
37
+ html_string.gsub!( /src=["']+([^:]+?)["']/i ) { |m| "src=\"#{::Rails.root}/public" + $1 + '"' }
38
+ html_string.gsub!( /<link href=["']+([^:]+?)["']/i ) { |m| "<link href=\"#{::Rails.root}/public" + $1 + '"' }
39
+
40
+ # Remove asset ids on images, scripts, and stylesheets with a regex
41
+ html_string.gsub!( /src=["'](\S+\?\d*)["']/i ) { |m| 'src="' + $1.split('?').first + '"' }
42
+ html_string.gsub!( /<link href=["'](\S+\?\d*)["']/i ) { |m| '<link href="' + $1.split('?').first + '"' }
43
+
44
+ return html_string.html_safe
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module WkhtmltopdfForRails
2
+ VERSION = "0.0.7"
3
+ end
@@ -0,0 +1,40 @@
1
+ module WkhtmltopdfForRails
2
+ class Wkhtmltopdf
3
+ attr_accessor :pdf_file, :html_file, :source, :optional_params, :params_string
4
+
5
+ def initialize(options)
6
+ @html_file = options[:html_file] if options.has_key?(:html_file)
7
+ @source = options[:source] if options.has_key?(:source)
8
+ @optional_params = options[:wkhtmltopdf_options] if options.has_key?(:wkhtmltopdf_options)
9
+ create_params_string
10
+ end
11
+
12
+ def generate
13
+ wkhtml_call = File.join(File.dirname(__FILE__), "..", "..", "bin", "wkhtmltopdf ")
14
+
15
+ if !@source.nil?
16
+ wkhtml_call << "#{@source}"
17
+ else
18
+ wkhtml_call << "#{@html_file}"
19
+ end
20
+ wkhtml_call << " #{@params_string} - -q"
21
+ IO.popen(wkhtml_call, "rb").read
22
+ end
23
+
24
+ private
25
+
26
+ def create_params_string
27
+ params_arr = []
28
+ unless @optional_params.nil?
29
+ @optional_params.each do |key, val|
30
+ if val && val.is_a?(String)
31
+ params_arr << "--#{key.to_s} '#{val}'"
32
+ elsif val
33
+ params_arr << "--#{key.to_s}"
34
+ end
35
+ end
36
+ end
37
+ @params_string = params_arr.join(' ')
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wkhtmltopdf_for_rails/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{wkhtmltopdf_for_rails}
8
+ s.version = WkhtmltopdfForRails::VERSION
9
+ s.authors = ["Alexey Osipenko"]
10
+ s.date = %q{2010-04-29}
11
+ s.description = %q{Provides WKHTMLTOPDF for ruby on rails.}
12
+ s.email = %q{alexey@osipenko.in.ua}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = [
15
+ "test/test_helper.rb",
16
+ "test/wkhtmltopdf_test.rb",
17
+ "test/wkhtmltopdf_test_controller_test.rb"
18
+ ]
19
+ s.homepage = %q{http://github.com/aratak/wkhtmltopdf_for_rails}
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.require_paths = ["lib"]
22
+ s.summary = %q{Provides WKHTMLTOPDF for ruby on rails.}
23
+ s.extensions = 'ext/mkrf_conf.rb'
24
+ end
25
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wkhtmltopdf_for_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Osipenko
@@ -12,36 +12,31 @@ date: 2010-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides WKHTMLTOPDF for ruby on rails.
14
14
  email: alexey@osipenko.in.ua
15
- executables:
16
- - wkhtmltopdf
17
- - wkhtmltopdf-amd64
18
- - wkhtmltopdf-binary.rb
19
- - wkhtmltopdf_darwin_386
20
- - wkhtmltopdf_linux_386
21
- extensions: []
22
- extra_rdoc_files:
23
- - README.md
15
+ executables: []
16
+ extensions:
17
+ - ext/mkrf_conf.rb
18
+ extra_rdoc_files: []
24
19
  files:
25
20
  - .gitignore
26
- - Manifest
21
+ - Gemfile
22
+ - Gemfile.lock
27
23
  - README.md
28
- - VERSION
29
- - bin/wkhtmltopdf
30
- - bin/wkhtmltopdf-amd64
31
- - bin/wkhtmltopdf-binary.rb
32
- - bin/wkhtmltopdf_darwin_386
33
- - bin/wkhtmltopdf_linux_386
34
- - init.rb
35
- - lib/render_pdf.rb
36
- - lib/wkhtmltopdf.rb
24
+ - Rakefile
25
+ - ext/mkrf_conf.rb
26
+ - ext/wkhtmltopdf/wkhtmltopdf_amd64
27
+ - ext/wkhtmltopdf/wkhtmltopdf_darwin
28
+ - ext/wkhtmltopdf/wkhtmltopdf_linux
37
29
  - lib/wkhtmltopdf_for_rails.rb
38
- - rakefile
30
+ - lib/wkhtmltopdf_for_rails/render_pdf.rb
31
+ - lib/wkhtmltopdf_for_rails/version.rb
32
+ - lib/wkhtmltopdf_for_rails/wkhtmltopdf.rb
39
33
  - test/fixtures/wkhtmltopdf.html
40
34
  - test/pdfs/.gitignore
41
35
  - test/test_helper.rb
42
36
  - test/tmp/.gitkeep
43
37
  - test/wkhtmltopdf_test.rb
44
38
  - test/wkhtmltopdf_test_controller_test.rb
39
+ - wkhtmltopdf_for_rails.gemspec
45
40
  homepage: http://github.com/aratak/wkhtmltopdf_for_rails
46
41
  licenses: []
47
42
  metadata: {}
@@ -64,7 +59,7 @@ requirements: []
64
59
  rubyforge_project:
65
60
  rubygems_version: 2.0.3
66
61
  signing_key:
67
- specification_version: 3
62
+ specification_version: 4
68
63
  summary: Provides WKHTMLTOPDF for ruby on rails.
69
64
  test_files:
70
65
  - test/test_helper.rb
data/Manifest DELETED
@@ -1,16 +0,0 @@
1
- Manifest
2
- bin/wkhtmltopdf
3
- bin/wkhtmltopdf-amd64
4
- bin/wkhtmltopdf-binary.rb
5
- bin/wkhtmltopdf_darwin_386
6
- bin/wkhtmltopdf_linux_386
7
- init.rb
8
- lib/render_pdf.rb
9
- lib/wkhtmltopdf.rb
10
- lib/wkhtmltopdf_for_rails.rb
11
- rakefile
12
- test/fixtures/wkhtmltopdf.html
13
- test/test_helper.rb
14
- test/wkhtmltopdf_test.rb
15
- test/wkhtmltopdf_test_controller_test.rb
16
- Rakefile
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.5
@@ -1,15 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- if RUBY_PLATFORM =~ /linux/ && 1.size == 4
4
- executable = 'wkhtmltopdf_linux_386'
5
- elsif RUBY_PLATFORM =~ /linux/ && 1.size == 8
6
- executable = 'wkhtmltopdf-amd64'
7
- elsif RUBY_PLATFORM =~ /darwin/
8
- executable = 'wkhtmltopdf_darwin_386'
9
- else
10
- raise "Invalid platform. Must be running linux or intel-based Mac OS."
11
- end
12
-
13
- executable = File.join(File.dirname(__FILE__), executable)
14
- system(executable + " " + $*.join(" "))
15
-
File without changes
data/init.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'render_pdf'
2
- require 'wkhtmltopdf'
3
-
4
- Mime::Type.register 'application/pdf', :pdf
5
-
6
- ActionController::Base.send(:include, RenderPdf)
7
-
@@ -1,62 +0,0 @@
1
- module RenderPdf
2
-
3
- def render_to_pdf(options = {})
4
- make_pdf(options)
5
- # pdf_file_name = "#{options[:file_path]}/#{options[:pdf]}.pdf"
6
- send_pdf_options = {
7
- :filename => "#{options[:pdf]}.pdf",
8
- :type => 'application/pdf'
9
- }
10
- # if options[:delete_generated_pdf]
11
- # send_pdf_options[:stream] = false
12
- # end
13
-
14
- send_data(make_pdf(options), send_pdf_options)
15
-
16
- # if options[:delete_generated_pdf] && File.exists?(pdf_file_name)
17
- # File.delete(pdf_file_name)
18
- # end
19
- end
20
-
21
- private
22
-
23
- def make_pdf(options)
24
- if options.has_key?(:template)
25
- html_string = generate_html(options)
26
- timestamp = Time.now.strftime("%y%m%d%H%M%S")
27
- html_file_name = "#{timestamp}_#{options[:pdf]}.html"
28
- html_file_path = File.join(::Rails.root, 'tmp', html_file_name)
29
- File.open(html_file_path, 'w') do |f|
30
- f.write(html_string)
31
- end
32
- options[:html_file] = html_file_path
33
- end
34
-
35
- pdf = Wkhtmltopdf.new(options)
36
- pdf.generate
37
-
38
- # if html_file_path.present? && File.exists?(html_file_path)
39
- # File.delete(html_file_path)
40
- # end
41
- end
42
-
43
- def generate_html(options)
44
- render_options = {}
45
- render_options[:template] = options.delete(:template)
46
- render_options[:layout] = options.delete(:layout) if options.has_key?(:layout)
47
-
48
- html_string = render_to_string(render_options).to_str
49
-
50
- # re-route absolute paths for images, scripts and stylesheets
51
- html_string.gsub!( /src=["']+([^:]+?)["']/i ) { |m| "src=\"#{::Rails.root}/public" + $1 + '"' }
52
- html_string.gsub!( /<link href=["']+([^:]+?)["']/i ) { |m| "<link href=\"#{::Rails.root}/public" + $1 + '"' }
53
-
54
- # Remove asset ids on images, scripts, and stylesheets with a regex
55
- html_string.gsub!( /src=["'](\S+\?\d*)["']/i ) { |m| 'src="' + $1.split('?').first + '"' }
56
- html_string.gsub!( /<link href=["'](\S+\?\d*)["']/i ) { |m| '<link href="' + $1.split('?').first + '"' }
57
-
58
- return html_string.html_safe
59
- end
60
-
61
- end
62
-
@@ -1,43 +0,0 @@
1
- class Wkhtmltopdf
2
-
3
- attr_accessor :pdf_file, :html_file, :source, :optional_params, :params_string
4
-
5
- def initialize(options)
6
- # @pdf_file = "#{options[:file_path]}/#{options[:pdf]}.pdf"
7
- @html_file = options[:html_file] if options.has_key?(:html_file)
8
- @source = options[:source] if options.has_key?(:source)
9
- @optional_params = options[:wkhtmltopdf_options] if options.has_key?(:wkhtmltopdf_options)
10
- create_params_string
11
- end
12
-
13
- def generate
14
- wkhtml_call = "wkhtmltopdf "
15
- if !@source.nil?
16
- wkhtml_call << "#{@source}"
17
- else
18
- wkhtml_call << "#{@html_file}"
19
- end
20
- wkhtml_call << " #{@params_string} - -q"
21
- `#{wkhtml_call}`.tap do
22
- sleep 1
23
- end
24
- end
25
-
26
- private
27
-
28
- def create_params_string
29
- params_arr = []
30
- unless @optional_params.nil?
31
- @optional_params.each do |key, val|
32
- if val && val.is_a?(String)
33
- params_arr << "--#{key.to_s} '#{val}'"
34
- elsif val
35
- params_arr << "--#{key.to_s}"
36
- end
37
- end
38
- end
39
- @params_string = params_arr.join(' ')
40
- end
41
-
42
- end
43
-
data/rakefile DELETED
@@ -1,34 +0,0 @@
1
- # # Rakefile
2
- # require 'rubygems'
3
- # require 'rake'
4
- # require 'echoe'
5
- #
6
- # Echoe.new('wkhtmltopdf_for_rails', '0.0.1') do |p|
7
- # p.description = "Provides WKHTMLTOPDF for ruby on rails."
8
- # p.url = "http://github.com/aratak/wkhtmltopdf_for_rails"
9
- # p.author = "Alexey Osipenko"
10
- # p.email = "alexey@osipenko.in.ua"
11
- # p.ignore_pattern = ["pkg/*"]
12
- # p.development_dependencies = []
13
- # p.executables << "wkhtmltopdf"
14
- # end
15
- #
16
- #
17
-
18
- require 'rubygems'
19
-
20
- begin
21
- require 'jeweler'
22
- Jeweler::Tasks.new do |gemspec|
23
- gemspec.name = "wkhtmltopdf_for_rails"
24
- gemspec.summary = "Provides WKHTMLTOPDF for ruby on rails."
25
- gemspec.description = "Provides WKHTMLTOPDF for ruby on rails."
26
- gemspec.email = "alexey@osipenko.in.ua"
27
- gemspec.homepage = "http://github.com/aratak/wkhtmltopdf_for_rails"
28
- gemspec.authors = ["Alexey Osipenko"]
29
- gemspec.executables << "wkhtmltopdf"
30
- end
31
- Jeweler::GemcutterTasks.new
32
- rescue LoadError
33
- puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
34
- end