aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-01-05 00:09:55 +0100
committerHarald Eilertsen <haraldei@anduin.net>2020-01-05 15:40:55 +0100
commita5c61919e7c9ec58e065d04117132aa424b019cc (patch)
tree3b496c2a1c96491b8afe08b35e23fad673da86b1 /lib
parent54f62ce1c31b82560d40de4486bf9beb1a20d9bf (diff)
downloadpdf-calendars-a5c61919e7c9ec58e065d04117132aa424b019cc.tar.gz
pdf-calendars-a5c61919e7c9ec58e065d04117132aa424b019cc.tar.bz2
pdf-calendars-a5c61919e7c9ec58e065d04117132aa424b019cc.zip
Add week numbers to columns layout
Diffstat (limited to 'lib')
-rw-r--r--lib/carlosgoce/layout/layouts.rb31
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/carlosgoce/layout/layouts.rb b/lib/carlosgoce/layout/layouts.rb
index ae934f1..bb03362 100644
--- a/lib/carlosgoce/layout/layouts.rb
+++ b/lib/carlosgoce/layout/layouts.rb
@@ -37,7 +37,7 @@ module CarlosGoce
end
def header
- [[""] + @columns]
+ [["Uke", "Dato"] + @columns]
end
def create(file, data, year)
@@ -48,20 +48,43 @@ module CarlosGoce
rows = []
offset = 6 - month[:formatted_days].select { |d| d == "" }.length
+ days_in_month = month[:days].length
month[:days].each_index do |i|
row = []
bg = (i - offset) % 7 == 0 ? "ffcccc" : "ffffff"
+
+ if (i - offset) % 7 == 1
+ remaining_days = days_in_month - i
+ span = remaining_days < 7 ? remaining_days : 7
+ row << pdf.make_cell(:content => "#{Date.new(year, k, i + 1).cweek}", :rowspan => span, :align => :center)
+ elsif i == 0
+ row << pdf.make_cell(:content => "#{Date.new(year, k, 1).cweek}", :rowspan => offset + 1, :align => :center)
+ end
+
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 = pdf.make_table(header + rows) do
+ cells.align = :center
+ cells.padding = 2
+ cells.border_width = 1
+
+ column(0).width = 30
+ column(1).width = 70
+ column(1).align = :left
+ columns(2..5).width = 160
+
+ row(0).background_color = "cccccc"
+ row(0).font_style = :bold
+ end
+
t.draw()
+
pdf.start_new_page if k < 12
end
end