🐛 Fixes double generation of content for the pdf_generatorx

main
Ervan Silvert 4 years ago
parent d356da89aa
commit b0a97adc96
  1. 4
      Gemfile.lock
  2. 3
      agenda_pdf.gemspec
  3. 2
      lib/agenda_pdf/options_parser.rb
  4. 10
      lib/agenda_pdf/pdf_generator.rb
  5. 2
      lib/agenda_pdf/version.rb

@ -7,6 +7,7 @@ PATH
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
byebug (11.1.3)
diff-lcs (1.5.0) diff-lcs (1.5.0)
pdf-core (0.9.0) pdf-core (0.9.0)
prawn (2.4.0) prawn (2.4.0)
@ -26,7 +27,6 @@ GEM
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0) rspec-support (~> 3.10.0)
rspec-support (3.10.3) rspec-support (3.10.3)
thor (1.2.1)
ttfunk (1.7.0) ttfunk (1.7.0)
PLATFORMS PLATFORMS
@ -35,10 +35,10 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
agenda_pdf! agenda_pdf!
bundler (~> 2.2.22) bundler (~> 2.2.22)
byebug (~> 11.1)
prawn (~> 2.4) prawn (~> 2.4)
rake (~> 10.0) rake (~> 10.0)
rspec (~> 3.0) rspec (~> 3.0)
thor (~> 1.2)
RUBY VERSION RUBY VERSION
ruby 3.0.2p107 ruby 3.0.2p107

@ -33,12 +33,13 @@ Gem::Specification.new do |spec|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end end
spec.bindir = "bin" spec.bindir = "bin"
spec.executables = ['agenda_pdf'] spec.executables = ['agenda_pdf']
spec.require_paths = ["lib"] spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 2.2.22" spec.add_development_dependency "bundler", "~> 2.2.22"
spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "byebug", "~> 11.1"
spec.add_dependency "prawn", "~> 2.4" spec.add_dependency "prawn", "~> 2.4"
end end

@ -34,7 +34,7 @@ class OptionsParser
@options[:month] = DateTime.parse(v) rescue DateTime.now @options[:month] = DateTime.parse(v) rescue DateTime.now
end end
opts.on("-o", "--path", "The output file path") do |v| opts.on("-oPATH", "--path=PATH", "The output file path") do |v|
@options[:path] = Pathname.new(v) @options[:path] = Pathname.new(v)
end end

@ -1,11 +1,11 @@
require 'prawn' require 'prawn'
require 'byebug'
class PdfGenerator < Prawn::Document class PdfGenerator < Prawn::Document
def initialize(path, &block) def initialize(path, &block)
super()
initialize_document initialize_document
instance_eval(&block) super()
finalize_document(path) finalize_document(path)
end end
@ -17,13 +17,13 @@ class PdfGenerator < Prawn::Document
start_date = DateTime.new(year, month) start_date = DateTime.new(year, month)
end_date = start_date.next_month end_date = start_date.next_month
new(path) do new(path) do
(start_date..end_date).each do |day| (start_date...end_date).to_a.each do |day|
text day.year.to_s text day.year.to_s
text day.strftime('%b') text day.strftime('%b')
text day.strftime('%a %d') text day.strftime('%a %d')
start_new_page unless day == end_date start_new_page
end end
end end
end end

@ -1,3 +1,3 @@
module AgendaPdf module AgendaPdf
VERSION = "0.1.0" VERSION = "0.1.1"
end end

Loading…
Cancel
Save