gimli 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gimli +1 -0
- data/config/style.css +6 -1
- data/lib/gimli/config.rb +1 -1
- data/lib/gimli/converter.rb +22 -4
- data/lib/gimli/setup.rb +4 -0
- data/lib/gimli/version.rb +1 -1
- data/spec/gimli/converter_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9b5c0a79bb3bc2633bb3537b1bf6089fef67973
|
4
|
+
data.tar.gz: 66814de6e4f81650b30a169e090732d9b3c8dc0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d876a23cf2ad33df19f14503d99e8cb2389d3f8965aac790049aa9529f80dd83f79a4f2348270c6c776b2a2adf8837f57e13f979426d8a3c82c05aed339803c
|
7
|
+
data.tar.gz: 29e69f866f2cc90c97ea2cfbb1daabbc130ff0bb2b3303dc4a8d737c3fe23fac513a928645a2cb54f799422f36bfa1c65023477d18dec9469ce1f5dd88114298
|
data/bin/gimli
CHANGED
data/config/style.css
CHANGED
data/lib/gimli/config.rb
CHANGED
@@ -4,7 +4,7 @@ module Gimli
|
|
4
4
|
|
5
5
|
# Class that keeps the config parameters
|
6
6
|
class Config
|
7
|
-
attr_accessor :file, :recursive, :merge, :debug, :wkhtmltopdf_parameters, :remove_front_matter, :output_filename, :output_dir, :stylesheet
|
7
|
+
attr_accessor :file, :recursive, :merge, :debug, :wkhtmltopdf_parameters, :remove_front_matter, :output_filename, :output_dir, :stylesheet, :cover
|
8
8
|
|
9
9
|
# Sets default values
|
10
10
|
def initialize
|
data/lib/gimli/converter.rb
CHANGED
@@ -9,6 +9,8 @@ module Gimli
|
|
9
9
|
# The class that converts the files
|
10
10
|
class Converter
|
11
11
|
|
12
|
+
COVER_FILE_PATH = ::File.expand_path("../../../config/cover.html", __FILE__)
|
13
|
+
|
12
14
|
# Initialize the converter with a File
|
13
15
|
# @param [Array] files The list of Gimli::MarkupFile to convert (passing a single file will still work)
|
14
16
|
# @param [Gimli::Config] config
|
@@ -16,7 +18,9 @@ module Gimli
|
|
16
18
|
@files, @config = files, config
|
17
19
|
|
18
20
|
@stylesheets = []
|
19
|
-
|
21
|
+
parameters = [@config.wkhtmltopdf_parameters]
|
22
|
+
parameters << '--cover' << COVER_FILE_PATH if config.cover
|
23
|
+
@wkhtmltopdf = Wkhtmltopdf.new parameters.join(' ')
|
20
24
|
end
|
21
25
|
|
22
26
|
# Convert the file and save it as a PDF file
|
@@ -56,14 +60,15 @@ module Gimli
|
|
56
60
|
# @param [String] html the html input
|
57
61
|
# @param [String] filename the name of the output file
|
58
62
|
def output_pdf(html, filename)
|
63
|
+
html = add_head html
|
59
64
|
load_stylesheets
|
65
|
+
generate_cover!
|
60
66
|
append_stylesheets html
|
61
|
-
add_head html
|
62
67
|
@wkhtmltopdf.output_pdf html, output_file(filename)
|
63
68
|
end
|
64
69
|
|
65
70
|
def add_head(html)
|
66
|
-
|
71
|
+
html = "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n</head><body>\n#{html}</body></html>"
|
67
72
|
end
|
68
73
|
|
69
74
|
# Load the stylesheets to pdfkit loads the default and the user selected if any
|
@@ -76,7 +81,7 @@ module Gimli
|
|
76
81
|
|
77
82
|
def append_stylesheets(html)
|
78
83
|
@stylesheets.each do |stylesheet|
|
79
|
-
html.
|
84
|
+
html.gsub!(/<\/head>/, style_tag_for(stylesheet) + '</head>')
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
@@ -115,6 +120,19 @@ module Gimli
|
|
115
120
|
|
116
121
|
::File.join(output_dir, "#{output_filename}.pdf")
|
117
122
|
end
|
123
|
+
|
124
|
+
# Generate cover file if optional cover was given
|
125
|
+
def generate_cover!
|
126
|
+
return unless @config.cover
|
127
|
+
cover_file = MarkupFile.new @config.cover
|
128
|
+
markup = Markup::Renderer.new cover_file
|
129
|
+
html = "<div class=\"cover\">\n#{markup.render}\n</div>"
|
130
|
+
append_stylesheets(html)
|
131
|
+
html = add_head(html)
|
132
|
+
File.open(COVER_FILE_PATH, 'w') do |f|
|
133
|
+
f.write html
|
134
|
+
end
|
135
|
+
end
|
118
136
|
end
|
119
137
|
end
|
120
138
|
|
data/lib/gimli/setup.rb
CHANGED
@@ -44,6 +44,10 @@ module Gimli extend OptiFlagSet
|
|
44
44
|
description 'Show version information and quit'
|
45
45
|
alternate_forms 'v'
|
46
46
|
end
|
47
|
+
optional_flag 'cover' do
|
48
|
+
description 'Create cover with the first headline'
|
49
|
+
alternate_forms 'C'
|
50
|
+
end
|
47
51
|
usage_flag 'h', 'help', '?'
|
48
52
|
|
49
53
|
and_process!
|
data/lib/gimli/version.rb
CHANGED
@@ -120,5 +120,21 @@ describe Gimli::Converter do
|
|
120
120
|
|
121
121
|
converter.convert_image_urls(html, filename).should == valid_html
|
122
122
|
end
|
123
|
+
|
124
|
+
it 'should create a cover file if given cover option' do
|
125
|
+
file = Gimli::MarkupFile.new 'fake'
|
126
|
+
config = Gimli.configure do |config|
|
127
|
+
config.cover = 'fake'
|
128
|
+
end
|
129
|
+
converter = Gimli::Converter.new file, config
|
130
|
+
any_instance_of(Gimli::Markup::Renderer) do |renderer|
|
131
|
+
stub(renderer).render { 'fake' }
|
132
|
+
end
|
133
|
+
|
134
|
+
FileUtils.rm_f(Gimli::Converter::COVER_FILE_PATH)
|
135
|
+
converter.generate_cover!
|
136
|
+
File.exists?(Gimli::Converter::COVER_FILE_PATH).should == true
|
137
|
+
FileUtils.rm_f(Gimli::Converter::COVER_FILE_PATH)
|
138
|
+
end
|
123
139
|
end
|
124
140
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gimli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fredrik Wallgren
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github-markup
|