gimli 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/config/style.css +5 -0
- data/lib/gimli.rb +4 -6
- data/lib/gimli/converter.rb +47 -11
- data/lib/gimli/path.rb +2 -0
- data/lib/gimli/setup.rb +8 -0
- data/lib/gimli/version.rb +1 -1
- data/spec/gimli/converter_spec.rb +15 -3
- metadata +30 -30
data/config/style.css
CHANGED
data/lib/gimli.rb
CHANGED
@@ -16,10 +16,8 @@ module Gimli
|
|
16
16
|
puts "Version: #{Gimli::Version}"
|
17
17
|
return
|
18
18
|
end
|
19
|
-
|
20
|
-
Path.list_valid(ARGV.flags.file, ARGV.flags.recursive?).
|
21
|
-
|
22
|
-
converter.convert!
|
23
|
-
end
|
19
|
+
|
20
|
+
@files = Path.list_valid(ARGV.flags.file, ARGV.flags.recursive?).map { |file| MarkupFile.new(file) }
|
21
|
+
Converter.new(@files).convert!(ARGV.flags.merge?)
|
24
22
|
end
|
25
|
-
end
|
23
|
+
end
|
data/lib/gimli/converter.rb
CHANGED
@@ -12,19 +12,35 @@ module Gimli
|
|
12
12
|
class Converter
|
13
13
|
|
14
14
|
# Initialize the converter with a File
|
15
|
-
# @param [Gimli::File
|
16
|
-
def initialize(
|
17
|
-
@
|
15
|
+
# @param [Array] files The list of Gimli::File to convert (passing a single file will still work)
|
16
|
+
def initialize(files)
|
17
|
+
@files = files
|
18
18
|
end
|
19
19
|
|
20
20
|
# Convert the file and save it as a PDF file
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
# @param [Boolean] merge if true a single pdf with all input files are created
|
22
|
+
def convert!(merge = false)
|
23
|
+
merged_contents = []
|
24
|
+
@files.each do |file|
|
25
|
+
markup = Markup.new file
|
26
|
+
html = convert_image_urls markup.render
|
27
|
+
if merge
|
28
|
+
html = "<div class=\"page-break\"></div>#{html}" unless merged_contents.empty?
|
29
|
+
merged_contents << html
|
30
|
+
else
|
31
|
+
output_pdf(html, file)
|
32
|
+
end
|
33
|
+
end
|
26
34
|
|
27
|
-
|
35
|
+
unless merged_contents.empty?
|
36
|
+
if ARGV.flags.file?
|
37
|
+
path = ARGV.flags.file
|
38
|
+
else
|
39
|
+
path = Dir.getwd
|
40
|
+
end
|
41
|
+
html = merged_contents.join
|
42
|
+
output_pdf(html, nil)
|
43
|
+
end
|
28
44
|
end
|
29
45
|
|
30
46
|
# Rewrite relative image urls to absolute
|
@@ -49,6 +65,14 @@ module Gimli
|
|
49
65
|
kit
|
50
66
|
end
|
51
67
|
|
68
|
+
# Create the pdf
|
69
|
+
# @param [String] html the html input
|
70
|
+
# @param [String] filename the name of the output file
|
71
|
+
def output_pdf(html, filename)
|
72
|
+
kit = pdf_kit(html)
|
73
|
+
kit.to_file(output_file(filename))
|
74
|
+
end
|
75
|
+
|
52
76
|
# Load the stylesheets to pdfkit loads the default and the user selected if any
|
53
77
|
# @param [PDFKit] kit
|
54
78
|
def load_stylesheets(kit)
|
@@ -80,8 +104,20 @@ module Gimli
|
|
80
104
|
|
81
105
|
# Generate the name of the output file
|
82
106
|
# @return [String]
|
83
|
-
|
84
|
-
|
107
|
+
# @param [Gimli::MarkupFile] file optionally, specify a file, otherwise use output filename
|
108
|
+
def output_file(file = nil)
|
109
|
+
if file
|
110
|
+
output_filename = file.name
|
111
|
+
if ARGV.flags.outputfilename? && @files.length == 1
|
112
|
+
output_filename = ARGV.flags.outputfilename
|
113
|
+
end
|
114
|
+
else
|
115
|
+
output_filename = Time.now.to_s.split(' ').join('_')
|
116
|
+
output_filename = @files.last.name if @files.length == 1 || ARGV.flags.merge?
|
117
|
+
output_filename = ARGV.flags.outputfilename if ARGV.flags.outputfilename?
|
118
|
+
end
|
119
|
+
|
120
|
+
::File.join(output_dir, "#{output_filename}.pdf")
|
85
121
|
end
|
86
122
|
end
|
87
123
|
end
|
data/lib/gimli/path.rb
CHANGED
@@ -8,6 +8,7 @@ module Gimli
|
|
8
8
|
# Return an array of paths to valid markup file matching the passed pattern
|
9
9
|
# @param [String] target
|
10
10
|
# @param [Bool] recursive
|
11
|
+
# @return [Array] an array of valid files
|
11
12
|
def self.list_valid(target, recursive = false)
|
12
13
|
if recursive
|
13
14
|
target ||= Dir.pwd
|
@@ -20,6 +21,7 @@ module Gimli
|
|
20
21
|
target = File.join(target, '*')
|
21
22
|
end
|
22
23
|
end
|
24
|
+
|
23
25
|
Dir.glob(target).keep_if { |file| MarkupFile.new(file).valid? }
|
24
26
|
end
|
25
27
|
end
|
data/lib/gimli/setup.rb
CHANGED
@@ -16,10 +16,18 @@ module Gimli extend OptiFlagSet
|
|
16
16
|
description 'The stylesheet to use to override the standard'
|
17
17
|
alternate_forms 's'
|
18
18
|
end
|
19
|
+
optional_flag 'outputfilename' do
|
20
|
+
description 'Sets the name of the output file. Only used with single file and in merge mode'
|
21
|
+
alternate_forms 'n'
|
22
|
+
end
|
19
23
|
optional_switch_flag 'recursive' do
|
20
24
|
description 'Recurse current or target directory and convert all valid markup files'
|
21
25
|
alternate_forms 'r'
|
22
26
|
end
|
27
|
+
optional_switch_flag 'merge' do
|
28
|
+
description 'Merge markup files into single pdf file'
|
29
|
+
alternate_forms 'm'
|
30
|
+
end
|
23
31
|
optional_switch_flag 'version' do
|
24
32
|
description 'Show version information and quit'
|
25
33
|
alternate_forms 'v'
|
data/lib/gimli/version.rb
CHANGED
@@ -10,7 +10,7 @@ describe Gimli::Converter do
|
|
10
10
|
name = 'my_file'
|
11
11
|
mock(file).name { name }
|
12
12
|
|
13
|
-
converter = Gimli::Converter.new file
|
13
|
+
converter = Gimli::Converter.new [file]
|
14
14
|
mock(converter).output_dir { Dir.getwd }
|
15
15
|
|
16
16
|
converter.output_file.should == File.join(Dir.getwd, "#{name}.pdf")
|
@@ -21,10 +21,22 @@ describe Gimli::Converter do
|
|
21
21
|
name = 'my_file'
|
22
22
|
mock(file).name { name }
|
23
23
|
|
24
|
-
converter = Gimli::Converter.new file
|
24
|
+
converter = Gimli::Converter.new [file]
|
25
25
|
mock(converter).output_dir { '/tmp/out' }
|
26
26
|
|
27
|
-
converter.output_file.should == "/tmp/out/#{name}.pdf"
|
27
|
+
converter.output_file(file).should == "/tmp/out/#{name}.pdf"
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should give the correct output_file when one is set' do
|
31
|
+
file = Gimli::MarkupFile.new 'fake'
|
32
|
+
output_filename = 'my_file'
|
33
|
+
|
34
|
+
converter = Gimli::Converter.new [file]
|
35
|
+
mock(converter).output_dir { Dir.getwd }
|
36
|
+
mock(ARGV).flags.mock!.outputfilename? { true }
|
37
|
+
mock(ARGV).flags.mock!.outputfilename { output_filename }
|
38
|
+
|
39
|
+
converter.output_file.should == File.join(Dir.getwd, "#{output_filename}.pdf")
|
28
40
|
end
|
29
41
|
|
30
42
|
it 'should give the correct output_dir when none given' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gimli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-05-
|
12
|
+
date: 2011-05-29 00:00:00.000000000 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
17
|
-
requirement: &
|
17
|
+
requirement: &7265960 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *7265960
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: github-markup
|
28
|
-
requirement: &
|
28
|
+
requirement: &7265520 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *7265520
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: redcarpet
|
39
|
-
requirement: &
|
39
|
+
requirement: &7265100 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *7265100
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: RedCloth
|
50
|
-
requirement: &
|
50
|
+
requirement: &7264680 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *7264680
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: org-ruby
|
61
|
-
requirement: &
|
61
|
+
requirement: &7264260 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *7264260
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: creole
|
72
|
-
requirement: &
|
72
|
+
requirement: &7263840 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *7263840
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: wikicloth
|
83
|
-
requirement: &
|
83
|
+
requirement: &7263420 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *7263420
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: albino
|
94
|
-
requirement: &
|
94
|
+
requirement: &7263000 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :runtime
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *7263000
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: nokogiri
|
105
|
-
requirement: &
|
105
|
+
requirement: &7262580 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :runtime
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *7262580
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: wkhtmltopdf-binary
|
116
|
-
requirement: &
|
116
|
+
requirement: &7262160 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ! '>='
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: '0'
|
122
122
|
type: :runtime
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *7262160
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: pdfkit
|
127
|
-
requirement: &
|
127
|
+
requirement: &7261740 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ! '>='
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: '0'
|
133
133
|
type: :runtime
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *7261740
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: optiflag
|
138
|
-
requirement: &
|
138
|
+
requirement: &7256400 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - ! '>='
|
@@ -143,10 +143,10 @@ dependencies:
|
|
143
143
|
version: '0'
|
144
144
|
type: :runtime
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *7256400
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: rspec
|
149
|
-
requirement: &
|
149
|
+
requirement: &7255960 !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
152
152
|
- - ! '>='
|
@@ -154,10 +154,10 @@ dependencies:
|
|
154
154
|
version: '0'
|
155
155
|
type: :development
|
156
156
|
prerelease: false
|
157
|
-
version_requirements: *
|
157
|
+
version_requirements: *7255960
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: rr
|
160
|
-
requirement: &
|
160
|
+
requirement: &7255480 !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
163
163
|
- - ! '>='
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
version: '0'
|
166
166
|
type: :development
|
167
167
|
prerelease: false
|
168
|
-
version_requirements: *
|
168
|
+
version_requirements: *7255480
|
169
169
|
description: Utility for converting markup files to pdf files. Useful for reports
|
170
170
|
etc.
|
171
171
|
email: fredrik.wallgren@gmail.com
|