pdfkit-middleware-to-file 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -0
- data/lib/pdfkit/configuration.rb +7 -1
- data/lib/pdfkit/middleware.rb +21 -2
- data/pdfkit.gemspec +3 -3
- metadata +5 -3
data/README.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# UPDATES -
|
2
|
+
save pdf serverside and on repository if necessary ( combination of basic knowledge of sftp, cracking open the gem, and some stack overflow knowledge )
|
3
|
+
gem install pdfkit-middleware-to-file
|
4
|
+
|
5
|
+
## Uploads
|
6
|
+
PDFKit.configure do |config|
|
7
|
+
config.upload_options = {
|
8
|
+
:host => <your_host>
|
9
|
+
:user => <your_user>
|
10
|
+
:password => <your_password>
|
11
|
+
:folder => <your_remote_folder>
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
## Downloads
|
16
|
+
In controller, set header['PDF-Full-File-Path'] = <your_local_full_path_to_save_to>
|
17
|
+
|
1
18
|
# PDFKit
|
2
19
|
|
3
20
|
Create PDFs using plain old HTML+CSS. Uses [wkhtmltopdf](http://github.com/antialize/wkhtmltopdf) on the back-end which renders HTML using Webkit.
|
data/lib/pdfkit/configuration.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class PDFKit
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :meta_tag_prefix, :default_options, :root_url
|
3
|
+
attr_accessor :meta_tag_prefix, :default_options, :root_url, :upload_options
|
4
4
|
attr_writer :wkhtmltopdf
|
5
5
|
|
6
6
|
def initialize
|
@@ -14,6 +14,12 @@ class PDFKit
|
|
14
14
|
:margin_left => '0.75in',
|
15
15
|
:encoding => "UTF-8"
|
16
16
|
}
|
17
|
+
@upload_options = {
|
18
|
+
:host => '',
|
19
|
+
:user => '',
|
20
|
+
:password => '',
|
21
|
+
:folder => ''
|
22
|
+
}
|
17
23
|
end
|
18
24
|
|
19
25
|
def wkhtmltopdf
|
data/lib/pdfkit/middleware.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class PDFKit
|
2
|
-
|
2
|
+
|
3
3
|
class Middleware
|
4
4
|
|
5
5
|
def initialize(app, options = {}, conditions = {})
|
@@ -8,6 +8,20 @@ class PDFKit
|
|
8
8
|
@conditions = conditions
|
9
9
|
end
|
10
10
|
|
11
|
+
def upload(file)
|
12
|
+
host = PDFKit.configure.upload_options[:host]
|
13
|
+
user = PDFKit.configure.upload_options[:user]
|
14
|
+
folder = PDFKit.configure.upload_options[:folder]
|
15
|
+
password = PDFKit.configure.upload_options[:password]
|
16
|
+
|
17
|
+
file_name = File.basename( file )
|
18
|
+
full_path = File.absolute_path( file )
|
19
|
+
|
20
|
+
Net::SFTP.start(host, user, :password => password) do |sftp|
|
21
|
+
data = sftp.upload!( full_path, "#{folder}/#{file_name}" )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
11
25
|
def call(env)
|
12
26
|
@request = Rack::Request.new(env)
|
13
27
|
@render_pdf = false
|
@@ -19,7 +33,12 @@ class PDFKit
|
|
19
33
|
body = response.respond_to?(:body) ? response.body : response.join
|
20
34
|
body = body.join if body.is_a?(Array)
|
21
35
|
pdf = PDFKit.new(translate_paths(body, env), @options)
|
22
|
-
|
36
|
+
|
37
|
+
if headers["PDF-Full-File-Path"].present?
|
38
|
+
file = pdf.to_file( headers["PDF-Full-File-Path"] )
|
39
|
+
upload(file) if PDFKit.configure.upload_options[:host].present?
|
40
|
+
end
|
41
|
+
|
23
42
|
body = pdf.to_pdf
|
24
43
|
response = [body]
|
25
44
|
|
data/pdfkit.gemspec
CHANGED
@@ -4,13 +4,13 @@ require "pdfkit/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "pdfkit-middleware-to-file"
|
7
|
-
s.version = "0.5.
|
7
|
+
s.version = "0.5.5" # PDFKit::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Jared Pace", "Relevance", "Ashish"]
|
9
|
+
s.authors = ["Jared Pace", "Relevance", "Ashish", "kikuchiyo"]
|
10
10
|
# s.email = ["jared@codewordstudios.com"]
|
11
11
|
# s.homepage = "http://github.com/jdpace/PDFKit"
|
12
12
|
s.summary = "HTML+CSS -> PDF"
|
13
|
-
s.description = "
|
13
|
+
s.description = "Updates to PDFKit by Jared Pace and Relevance with stack overflow post suggested by Ashish implemented to save server side pdf file, and code to save pdf file on repository."
|
14
14
|
|
15
15
|
s.rubyforge_project = "pdfkit"
|
16
16
|
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfkit-middleware-to-file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jared Pace
|
9
9
|
- Relevance
|
10
10
|
- Ashish
|
11
|
+
- kikuchiyo
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
@@ -61,8 +62,9 @@ dependencies:
|
|
61
62
|
- - ! '>='
|
62
63
|
- !ruby/object:Gem::Version
|
63
64
|
version: 0.5.6
|
64
|
-
description:
|
65
|
-
|
65
|
+
description: Updates to PDFKit by Jared Pace and Relevance with stack overflow post
|
66
|
+
suggested by Ashish implemented to save server side pdf file, and code to save pdf
|
67
|
+
file on repository.
|
66
68
|
email:
|
67
69
|
executables: []
|
68
70
|
extensions: []
|