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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd99093a10d095f017dc6409f2ec3b8656cddebb
4
- data.tar.gz: 82968d21422179ea4f9fb701ba588fed5bb00850
3
+ metadata.gz: b9b5c0a79bb3bc2633bb3537b1bf6089fef67973
4
+ data.tar.gz: 66814de6e4f81650b30a169e090732d9b3c8dc0e
5
5
  SHA512:
6
- metadata.gz: 5d6d3d945c70e11bf080a1293072349c7f4c61c02caac427825fe04218fb1e8bd8d794cf201c28d05f883926323e7c6ec5d982ba57b2e49bd91d46f477b76e3d
7
- data.tar.gz: 4f23a2f9048f436966f385dcd619a99961809df9a5ca50bb8a9848ebc8a1bafaff46c58608b579148b5d3b12085c64eca6d4073e218904cb35d27d37fe0d34c8
6
+ metadata.gz: 8d876a23cf2ad33df19f14503d99e8cb2389d3f8965aac790049aa9529f80dd83f79a4f2348270c6c776b2a2adf8837f57e13f979426d8a3c82c05aed339803c
7
+ data.tar.gz: 29e69f866f2cc90c97ea2cfbb1daabbc130ff0bb2b3303dc4a8d737c3fe23fac513a928645a2cb54f799422f36bfa1c65023477d18dec9469ce1f5dd88114298
data/bin/gimli CHANGED
@@ -19,6 +19,7 @@ config = Gimli.configure do |config|
19
19
  config.output_filename = ARGV.flags.outputfilename
20
20
  config.output_dir = ARGV.flags.outputdir
21
21
  config.stylesheet = ARGV.flags.stylesheet
22
+ config.cover = ARGV.flags.cover
22
23
  end
23
24
 
24
25
  Gimli.process! config
@@ -171,4 +171,9 @@ table tr {
171
171
 
172
172
  table tr:nth-child(2n) {
173
173
  background-color: #f8f8f8;
174
- }
174
+ }
175
+
176
+ .cover {
177
+ text-align: center;
178
+ margin-top: 100px;
179
+ }
@@ -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
@@ -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
- @wkhtmltopdf = Wkhtmltopdf.new @config.wkhtmltopdf_parameters
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
- html.insert(0, "\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n</head>\n")
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.insert(0, style_tag_for(stylesheet))
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
 
@@ -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!
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Gimli
4
- VERSION = "0.5.4"
4
+ VERSION = "0.5.5"
5
5
  end
6
6
 
@@ -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
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-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-markup