Permalink
Browse files

Refactoring.

  • Loading branch information...
mat committed Sep 8, 2008
1 parent 15dfb81 commit 66e4d49f8d5a5652fbd113a7ae65577f3916b76a
Showing with 23 additions and 26 deletions.
  1. +8 −11 bin/pdf-calendar
  2. +15 −15 templates/default.xslfo.xml
View
@@ -123,24 +123,21 @@ end # class Optparse
options = Optparse.parse(ARGV)
-cal_title = options.title
-
-year = options.year
-
-cal = (1..12).to_a.map{ |month| Calendar::Layout.new(Time.mktime(year, month), :weekstart => options.weekstart) }.map{ |calendar| calendar.table}
template_file = File.expand_path(
File.join(File.dirname(__FILE__), '..', 'templates', 'default.xslfo.xml'))
caltemplate = ERB.new(File.read(template_file))
-cal_title ||= year
-weekstart = Calendar::Layout.check_weekstart(options.weekstart)
-weekdays = Calendar::Languages.weekdays(options.lang, weekstart)
+options.title ||= options.year
+marks = options.marks
+
+weekstart = Calendar::Layout.check_weekstart(options.weekstart)
+weekdays = Calendar::Languages.weekdays(options.lang, weekstart)
month_names = Calendar::Languages.months(options.lang)
-cal = cal
-paper = options.paper
-marks = options.marks
+
+
+cal = (1..12).to_a.map{ |month| Calendar::Layout.new(Time.mktime(options.year, month), :weekstart => options.weekstart) }.map{ |calendar| calendar.table}
fo_stylesheet = caltemplate.result(binding)
@@ -20,7 +20,7 @@ end
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
-<% if paper == 'letter' %>
+<% if options.paper == 'letter' %>
<fo:simple-page-master margin-right="1cm" margin-left="1cm" margin-bottom="1cm" margin-top="1cm" page-width="279mm" page-height="216mm" master-name="letter">
<% else %>
<fo:simple-page-master margin-right="1cm" margin-left="1cm" margin-bottom="1cm" margin-top="1cm" page-width="297mm" page-height="210mm" master-name="din-a4">
@@ -32,7 +32,7 @@ end
</fo:simple-page-master>
</fo:layout-master-set>
-<% if paper == 'letter' %>
+<% if options.paper == 'letter' %>
<fo:page-sequence initial-page-number="1" master-reference="letter">
<% else %>
<fo:page-sequence initial-page-number="1" master-reference="din-a4">
@@ -46,7 +46,7 @@ end
<fo:block font-size="18pt" line-height="24pt"
space-after="5pt" background-color="gray" color="white"
text-align="center" padding-top="3pt">
- <%= cal_title %>
+ <%= options.title %>
</fo:block>
</fo:block-container>
@@ -80,7 +80,7 @@ end
<% for week in cal[0] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 1, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 1, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -119,7 +119,7 @@ end
<% for week in cal[1] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 2, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 2, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -158,7 +158,7 @@ end
<% for week in cal[2] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 3, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 3, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -197,7 +197,7 @@ end
<% for week in cal[3] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 4, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 4, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -239,7 +239,7 @@ end
<% for week in cal[4] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 5, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 5, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -280,7 +280,7 @@ end
<% for week in cal[5] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 6, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 6, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -321,7 +321,7 @@ end
<% for week in cal[6] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 7, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 7, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -362,7 +362,7 @@ end
<% for week in cal[7] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 8, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 8, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -403,7 +403,7 @@ end
<% for week in cal[8] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 9, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 9, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -444,7 +444,7 @@ end
<% for week in cal[9] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 10, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 10, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -482,7 +482,7 @@ end
<% for week in cal[10] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 11, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 11, day, marks) %> <% end %>
</fo:table-row>
<% end %>
@@ -524,7 +524,7 @@ end
<% for week in cal[11] %>
<fo:table-row color="black" font-weight="normal" font-size="8pt" line-height="9pt" height="0.6cm">
- <% for day in week %> <%= render_day(year, 12, day, marks) %> <% end %>
+ <% for day in week %> <%= render_day(options.year, 12, day, marks) %> <% end %>
</fo:table-row>
<% end %>

0 comments on commit 66e4d49

Please sign in to comment.