aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-01-04 15:44:28 +0100
committerHarald Eilertsen <haraldei@anduin.net>2020-01-04 15:44:28 +0100
commitf8d95bbcbb8b5546046e3450eb3a75d3d3681341 (patch)
tree090fd8fc5b9fb975463584ddc65de99228e210d3
parent759d49d1a8ab6d444f443cc4afa80257f18d09d3 (diff)
downloadpdf-calendars-f8d95bbcbb8b5546046e3450eb3a75d3d3681341.tar.gz
pdf-calendars-f8d95bbcbb8b5546046e3450eb3a75d3d3681341.tar.bz2
pdf-calendars-f8d95bbcbb8b5546046e3450eb3a75d3d3681341.zip
Add column layout.
-rw-r--r--lib/carlosgoce/layout/layouts.rb42
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/carlosgoce/layout/layouts.rb b/lib/carlosgoce/layout/layouts.rb
index 9bc6ec1..ae934f1 100644
--- a/lib/carlosgoce/layout/layouts.rb
+++ b/lib/carlosgoce/layout/layouts.rb
@@ -27,5 +27,45 @@ module CarlosGoce
end
end
end
+
+ class Columns
+ attr_reader :columns, :num_cols
+
+ def initialize(cols)
+ @columns = cols
+ @num_cols = cols.length
+ end
+
+ def header
+ [[""] + @columns]
+ end
+
+ def create(file, data, year)
+ Prawn::Document.generate(file, :page_layout => :landscape, :page_size => "A4") do |pdf|
+ data[:months].each do |k, month|
+ pdf.font_size = 16
+ pdf.text "#{month[:name].capitalize} #{year}"
+
+ rows = []
+ offset = 6 - month[:formatted_days].select { |d| d == "" }.length
+
+ month[:days].each_index do |i|
+ row = []
+ bg = (i - offset) % 7 == 0 ? "ffcccc" : "ffffff"
+ row << pdf.make_cell(:content => "#{month[:days][i]} #{month[:days_names][i]}", :background_color => bg)
+ @num_cols.times { row << pdf.make_cell(:content => "", :background_color => bg) }
+ rows << row
+ end
+
+ pdf.font_size = 10
+ style = {align: :left, padding: 2, border_width: 1, valign: :center, margin: [0, 0, 15, 0]}
+ t = pdf.make_table(header + rows, cell_style: style, :width => 760, :column_widths => { 0 => 100 }, :header => true)
+ t.row(0).style(:background_color => "cccccc", :font_style => :bold)
+ t.draw()
+ pdf.start_new_page if k < 12
+ end
+ end
+ end
+ end
end
-end \ No newline at end of file
+end