From 25b052e864244170058f59578964012e9dfe725a Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 7 Feb 2014 21:04:08 +0100 Subject: [PATCH] Support alternative invoice template configuration --- config.yaml.example | 3 +++ stoptime.rb | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config.yaml.example b/config.yaml.example index 687778f..e2311be 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -8,3 +8,6 @@ # The invoice ID format (see strftime(3) and %N for the sequence number) #invoice_id: %Y%N + +# The invoice template used (without the .tex.erb suffix) +#invoice_template: invoice diff --git a/stoptime.rb b/stoptime.rb index 64ec42c..278dd3d 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -137,9 +137,10 @@ module StopTime::Models # The default configuration. Note that the configuration of the root # will be merged with this configuration. - DefaultConfig = { "invoice_id" => "%Y%N", - "hourly_rate" => 20.0, - "vat_rate" => 21.0 } + DefaultConfig = { "invoice_id" => "%Y%N", + "invoice_template" => "invoice", + "hourly_rate" => 20.0, + "vat_rate" => 21.0 } # Creates a new configuration object and loads the configuation. # by reading the file @config.yaml@ on disk, parsing it, and @@ -1165,7 +1166,7 @@ module StopTime::Controllers # Generates a LaTex document for the invoice with the given _number_. def _generate_invoice_tex(number) - template = TEMPLATE_DIR + "invoice.tex.erb" + template = TEMPLATE_DIR + "#{@config["invoice_template"]}.tex.erb" tex_file = PUBLIC_DIR + "invoices/#{number}.tex" I18n.with_locale :nl do @@ -1173,7 +1174,7 @@ module StopTime::Controllers File.open(tex_file, "w") { |f| f.write(erb.result(binding)) } end rescue Exception => err - tex_file.delete + tex_file.delete if File.exist? tex_file raise err end