middleman-pdfkit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 040fb551d9cfcd8c0a781f9b5798a012561e3624
4
+ data.tar.gz: b88fb76c0fec4c04837ed8787fb566ca3f5922ac
5
+ SHA512:
6
+ metadata.gz: a0dcc52e3ecb9c56ad471de2c3e483d85aeb8b19e436964680af2d6a55c86cc05fff5891f97aef22222d6d274f3f193a2451ff688b54f07e709da1e8c479082e
7
+ data.tar.gz: 3aa828a6815e089ff201199013c1707c1a366f5e7ffe5a5bb1b5305724989d4f58a1b279877911eb590d15ba91427252baeae01cdd2c687313b8dcb52cf5afb3
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .ruby-gemset
24
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middleman-pdfkit.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthias Döring
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ Middleman-PDFKit
2
+ ================
3
+
4
+ PDFKit extension for middleman
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'middleman-pdfkit'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install middleman-pdfkit
19
+
20
+ ## Usage
21
+
22
+ TODO: Add link to example app
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( https://github.com/matt-hh/middleman-pdfkit/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ require 'pdfkit'
2
+ require "middleman-pdfkit/version"
3
+
4
+ ::Middleman::Extensions.register(:pdfkit) do
5
+ require 'middleman-pdfkit/extension'
6
+ ::Middleman::PDFKit::Extension
7
+ end
@@ -0,0 +1,62 @@
1
+ module Middleman
2
+ module PDFKit
3
+ class Extension < ::Middleman::Extension
4
+ option :filenames, [], 'array of html files without .ext or leave it empty for all html files in build directory'
5
+
6
+ # https://github.com/pdfkit/pdfkit/blob/v0.6.2/lib/pdfkit/configuration.rb#L10-L17
7
+ option :disable_smart_shrinking, false, 'Disable smart shrinking'
8
+ option :quiet, true, 'Be quiet'
9
+ option :page_size, 'A4', 'Page size: A4'
10
+ option :margin_top, '0', 'Margin top: 0'
11
+ option :margin_right, '0', 'Margin right: 0'
12
+ option :margin_bottom, '0', 'Margin bottom: 0'
13
+ option :margin_left, '0', 'Margin left: 0'
14
+ option :encoding, 'UTF-8', 'Encoding'
15
+
16
+ def initialize(klass, options_hash={}, &block)
17
+ super
18
+ setup_filenames
19
+ end
20
+
21
+ def after_build(builder)
22
+ @filenames.each do |pdfkit_filename|
23
+ html_filename = "build/#{pdfkit_filename}.html"
24
+ pdf_filename = "build/#{pdfkit_filename}.pdf"
25
+ if File.exist?(html_filename)
26
+ generate_pdf(html_filename, pdf_filename)
27
+ builder.say_status "create", pdf_filename
28
+ else
29
+ builder.say_status "error", "#{pdf_filename} (HTML-File not found )", :red
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def setup_filenames
37
+ @filenames = options.filenames.empty? ? all_html_files : options.filenames
38
+ end
39
+
40
+ def all_html_files
41
+ # TODO: find a better way?!
42
+ Dir.glob(File.join('build', '**', '*.html')).map do |d|
43
+ File.join(File.dirname(d).sub('build', ''), File.basename(d, '.html'))[1..-1]
44
+ end
45
+ end
46
+
47
+ def generate_pdf(html_filename, pdf_filename)
48
+ kit = ::PDFKit.new(File.new(html_filename),
49
+ disable_smart_shrinking: options.disable_smart_shrinking,
50
+ quiet: options.quiet,
51
+ page_size: options.page_size,
52
+ margin_top: options.margin_top,
53
+ margin_right: options.margin_right,
54
+ margin_bottom: options.margin_bottom,
55
+ margin_left: options.margin_left,
56
+ encoding: options.encoding)
57
+ file = kit.to_file(pdf_filename)
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module PDFKit
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require "middleman-pdfkit"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman-pdfkit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "middleman-pdfkit"
8
+ spec.version = Middleman::PDFKit::VERSION
9
+ spec.authors = ["Matthias Döring"]
10
+ spec.email = ["matt@foryourcontent.de"]
11
+ spec.summary = %q{PDFKit extension for middleman}
12
+ spec.description = %q{Generate PDFs from HTML/CSS with middleman}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "middleman-core", ">= 3.0.0"
22
+ spec.add_dependency "pdfkit", "~> 0.6.2"
23
+ spec.add_dependency "wkhtmltopdf_binary_provider"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-pdfkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthias Döring
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pdfkit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: wkhtmltopdf_binary_provider
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Generate PDFs from HTML/CSS with middleman
84
+ email:
85
+ - matt@foryourcontent.de
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/middleman-pdfkit.rb
96
+ - lib/middleman-pdfkit/extension.rb
97
+ - lib/middleman-pdfkit/version.rb
98
+ - lib/middleman_extension.rb
99
+ - middleman-pdfkit.gemspec
100
+ homepage: ''
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: PDFKit extension for middleman
124
+ test_files: []