h2p 0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +19 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/h2p.gemspec +20 -0
- data/lib/h2p.rb +27 -0
- data/lib/h2p/version.rb +3 -0
- metadata +71 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3fce445c7c68092538348c0768d2041ad737ae6568f52dd2da5a5d7dea796d18
|
|
4
|
+
data.tar.gz: 605ff64067fddde56ab499946b1bc7ab26e9ab3ba19d671d80a70df4f7cff285
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: df1190a85dce0f00952693cb22edcb4354fdefb3b60e491a6c1280b5413aee149ead5de26ecc19e08033ce4f2233ee7fe6a53ded4b4cd4bcc4a4702055940685
|
|
7
|
+
data.tar.gz: 6a5569cb95e91657b38b73ab144318eb9d362d82b0ade2b97c39b0547a4dc072fd6eba99201db240478d66c80fa9b3055c34ded06572a125eedb68ce0ec2c8a0
|
data/.gitignore
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/test/tmp/
|
|
10
|
+
/test/version_tmp/
|
|
11
|
+
/tmp/
|
|
12
|
+
|
|
13
|
+
# Used by dotenv library to load environment variables.
|
|
14
|
+
# .env
|
|
15
|
+
|
|
16
|
+
## Specific to RubyMotion:
|
|
17
|
+
.dat*
|
|
18
|
+
.repl_history
|
|
19
|
+
build/
|
|
20
|
+
*.bridgesupport
|
|
21
|
+
build-iPhoneOS/
|
|
22
|
+
build-iPhoneSimulator/
|
|
23
|
+
|
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
25
|
+
#
|
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
29
|
+
#
|
|
30
|
+
# vendor/Pods/
|
|
31
|
+
|
|
32
|
+
## Documentation cache and generated files:
|
|
33
|
+
/.yardoc/
|
|
34
|
+
/_yardoc/
|
|
35
|
+
/doc/
|
|
36
|
+
/rdoc/
|
|
37
|
+
|
|
38
|
+
## Environment normalization:
|
|
39
|
+
/.bundle/
|
|
40
|
+
/vendor/bundle
|
|
41
|
+
/lib/bundler/man/
|
|
42
|
+
|
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
45
|
+
# Gemfile.lock
|
|
46
|
+
# .ruby-version
|
|
47
|
+
# .ruby-gemset
|
|
48
|
+
|
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
50
|
+
.rvmrc
|
data/CHANGELOG.md
ADDED
|
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 digital-fabric
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# H2P: HTML in, PDF out
|
|
2
|
+
|
|
3
|
+
H2P takes an HTML blob, uses wkhtmltopdf to convert it to PDF, and returns a PDF
|
|
4
|
+
blob.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
gem install 'h2p'
|
|
10
|
+
|
|
11
|
+
# you'll also need to have wkhtmltopdf installed:
|
|
12
|
+
gem install 'wkhtmltopdf-binary'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or just [use the source(TM)](#use-the-source).
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
...
|
|
21
|
+
my_html = '<html><body><h1>Hello, world!</h1></body></html>'
|
|
22
|
+
my_pdf = H2P.convert(my_html)
|
|
23
|
+
...
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Use the source
|
|
27
|
+
|
|
28
|
+
Adding a dependency to your `Gemfile` is just another thing to keep track off,
|
|
29
|
+
on top of everything else. Luckily, H2P is so small you can just copy the
|
|
30
|
+
source into your project:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
require 'tmpdir'
|
|
34
|
+
require 'fileutils'
|
|
35
|
+
|
|
36
|
+
module H2P
|
|
37
|
+
def self.tmp_path(ext)
|
|
38
|
+
stamp = Time.now.to_f
|
|
39
|
+
@counter ||= 0
|
|
40
|
+
File.join(Dir.tmpdir, "h2p-#{stamp}-#{@counter += 1}.#{ext}")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.convert(html)
|
|
44
|
+
html_path = tmp_path(:html)
|
|
45
|
+
pdf_path = tmp_path(:pdf)
|
|
46
|
+
p [html_path, pdf_path]
|
|
47
|
+
File.open(html_path, 'w+') { |f| f << html }
|
|
48
|
+
system('wkhtmltopdf', '-q', html_path, pdf_path)
|
|
49
|
+
IO.read(pdf_path)
|
|
50
|
+
ensure
|
|
51
|
+
FileUtils.rm(html_path) rescue nil
|
|
52
|
+
FileUtils.rm(pdf_path) rescue nil
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
```
|
data/h2p.gemspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_relative './lib/h2p/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = 'h2p'
|
|
5
|
+
s.version = H2P::VERSION
|
|
6
|
+
s.licenses = ['MIT']
|
|
7
|
+
s.summary = 'H2P: HTML in, PDF out'
|
|
8
|
+
s.author = 'Sharon Rosner'
|
|
9
|
+
s.email = 'ciconia@gmail.com'
|
|
10
|
+
s.files = `git ls-files`.split
|
|
11
|
+
s.homepage = 'http://github.com/digital-fabric/h2p'
|
|
12
|
+
s.metadata = {
|
|
13
|
+
"source_code_uri" => "https://github.com/digital-fabric/h2p"
|
|
14
|
+
}
|
|
15
|
+
s.rdoc_options = ["--title", "h2p", "--main", "README.md"]
|
|
16
|
+
s.extra_rdoc_files = ["README.md"]
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
|
|
19
|
+
s.add_runtime_dependency 'modulation', '~> 0.21'
|
|
20
|
+
end
|
data/lib/h2p.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'modulation/gem'
|
|
4
|
+
require 'tmpdir'
|
|
5
|
+
require 'fileutils'
|
|
6
|
+
|
|
7
|
+
export_default :H2P
|
|
8
|
+
|
|
9
|
+
module H2P
|
|
10
|
+
def self.tmp_path(ext)
|
|
11
|
+
stamp = Time.now.to_f
|
|
12
|
+
@counter ||= 0
|
|
13
|
+
File.join(Dir.tmpdir, "h2p-#{stamp}-#{@counter += 1}.#{ext}")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.convert(html)
|
|
17
|
+
html_path = tmp_path(:html)
|
|
18
|
+
pdf_path = tmp_path(:pdf)
|
|
19
|
+
p [html_path, pdf_path]
|
|
20
|
+
File.open(html_path, 'w+') { |f| f << html }
|
|
21
|
+
system('wkhtmltopdf', '-q', html_path, pdf_path)
|
|
22
|
+
IO.read(pdf_path)
|
|
23
|
+
ensure
|
|
24
|
+
FileUtils.rm(html_path) rescue nil
|
|
25
|
+
FileUtils.rm(pdf_path) rescue nil
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/h2p/version.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: h2p
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '0.1'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sharon Rosner
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-03-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: modulation
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.21'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.21'
|
|
27
|
+
description:
|
|
28
|
+
email: ciconia@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files:
|
|
32
|
+
- README.md
|
|
33
|
+
files:
|
|
34
|
+
- ".gitignore"
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- Gemfile
|
|
37
|
+
- Gemfile.lock
|
|
38
|
+
- LICENSE
|
|
39
|
+
- README.md
|
|
40
|
+
- h2p.gemspec
|
|
41
|
+
- lib/h2p.rb
|
|
42
|
+
- lib/h2p/version.rb
|
|
43
|
+
homepage: http://github.com/digital-fabric/h2p
|
|
44
|
+
licenses:
|
|
45
|
+
- MIT
|
|
46
|
+
metadata:
|
|
47
|
+
source_code_uri: https://github.com/digital-fabric/h2p
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options:
|
|
50
|
+
- "--title"
|
|
51
|
+
- h2p
|
|
52
|
+
- "--main"
|
|
53
|
+
- README.md
|
|
54
|
+
require_paths:
|
|
55
|
+
- lib
|
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '0'
|
|
66
|
+
requirements: []
|
|
67
|
+
rubygems_version: 3.0.1
|
|
68
|
+
signing_key:
|
|
69
|
+
specification_version: 4
|
|
70
|
+
summary: 'H2P: HTML in, PDF out'
|
|
71
|
+
test_files: []
|