wagon 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/wagon +1 -1
- data/lib/wagon/directory.rb +34 -16
- data/lib/wagon/page.rb +2 -2
- data/lib/wagon/ward.rb +1 -1
- data/spec/wagon/directory_spec.rb +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
data/bin/wagon
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# -h, --help Displays this help message
|
8
8
|
# -v, --version Display the version, then exit
|
9
9
|
# -V, --verbose Verbose output
|
10
|
-
# -t, --title
|
10
|
+
# -t, --title The title displayed on each page (default is the ward name)
|
11
11
|
# -r, --rows Number of rows per page (default is 6)
|
12
12
|
# -c, --columns Number of columns per page (default is 7)
|
13
13
|
# -p, --padding Padding between households (default is 2)
|
data/lib/wagon/directory.rb
CHANGED
@@ -4,6 +4,10 @@ require 'stringio'
|
|
4
4
|
|
5
5
|
module Wagon
|
6
6
|
class Directory < Page
|
7
|
+
def ward
|
8
|
+
@parent
|
9
|
+
end
|
10
|
+
|
7
11
|
def photo_directory_path
|
8
12
|
return @photo_directory_path unless @photo_directory_path.nil?
|
9
13
|
|
@@ -24,42 +28,56 @@ module Wagon
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def to_pdf(options = {})
|
27
|
-
options = {
|
31
|
+
options = {
|
32
|
+
:columns => 7,
|
33
|
+
:rows => 6,
|
34
|
+
:padding => 2,
|
35
|
+
:font_size => 8,
|
36
|
+
:address => true,
|
37
|
+
:phone_number => true,
|
38
|
+
:email => true,
|
39
|
+
:title => "#{ward.name}"
|
40
|
+
}.merge(options.delete_if {|k,v| v.nil? })
|
28
41
|
|
29
|
-
Prawn::Document.new(:
|
42
|
+
Prawn::Document.new(:left_margin => 10, :right_margin => 10, :top_margin => 10, :bottom_margin => 10) do |pdf|
|
43
|
+
header_height = 10
|
44
|
+
footer_height = 10
|
30
45
|
columns = options[:columns].to_f
|
31
46
|
rows = options[:rows].to_f
|
32
47
|
padding = options[:padding].to_f
|
33
48
|
grid_width = pdf.bounds.width / columns
|
34
|
-
grid_height = pdf.bounds.height / rows
|
49
|
+
grid_height = (pdf.bounds.height - header_height - footer_height) / rows
|
35
50
|
box_width = grid_width - (padding * 2)
|
36
51
|
box_height = grid_height - (padding * 2)
|
37
52
|
pages = (households.size.to_f / (columns * rows)).ceil()
|
38
|
-
info_lines = 1 + [:address, :phone_number, :email].inject(0) { |sum, item| sum += item ? 1 : 0 }
|
39
53
|
pdf.font_size = options[:font_size].to_i
|
54
|
+
info_count = 1 + [:address, :phone_number, :email].inject(0) { |sum, item| sum += options[item] ? 1 : 0 }
|
55
|
+
info_height = pdf.font.height*info_count
|
40
56
|
|
41
57
|
(0...pages).each do |page|
|
42
|
-
pdf.start_new_page
|
58
|
+
pdf.start_new_page unless page == 0
|
59
|
+
pdf.text(options[:title], :at => [pdf.bounds.right/2 - pdf.width_of(options[:title], :size => 12)/2, pdf.bounds.top - header_height/2], :size => 12)
|
60
|
+
pdf.text("For Church Use Only", :at => [pdf.bounds.right/2 - pdf.width_of("For Church Use Only")/2, pdf.bounds.bottom + footer_height/2])
|
43
61
|
(0...rows).each do |row|
|
44
|
-
y = pdf.bounds.top - row*grid_height
|
62
|
+
y = pdf.bounds.top - row*grid_height - header_height
|
45
63
|
(0...columns).each do |column|
|
46
64
|
break if (index = page*rows*columns+row*columns+column) >= households.size
|
47
65
|
household = households[index]
|
48
66
|
x = pdf.bounds.left + column*grid_width
|
49
67
|
pdf.bounding_box([x, y], :width => grid_width, :height => grid_height) do
|
50
68
|
pdf.bounding_box([pdf.bounds.left + padding, pdf.bounds.top - padding], :width => box_width, :height => box_height) do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
69
|
+
info = []
|
70
|
+
info.push(household.name)
|
71
|
+
info.push(*household.address.street) if options[:address]
|
72
|
+
info.push(household.phone_number) if options[:phone_number]
|
73
|
+
info.push(household.members.first.email) if options[:email]
|
56
74
|
|
57
|
-
pdf.image(household.has_image? ? StringIO.new(household.image_data) : './extra/placeholder.jpg',
|
58
|
-
:position => :center, :fit => [box_width, box_height - (padding*2 + pdf.font.height*info_lines)] )
|
75
|
+
pdf.image(household.has_image? ? StringIO.new(household.image_data) : './extra/placeholder.jpg', :position => :center, :fit => [box_width, box_height - (padding*2 + info_height)] )
|
59
76
|
|
60
|
-
pdf.
|
61
|
-
|
62
|
-
|
77
|
+
pdf.bounding_box([pdf.bounds.left, pdf.bounds.bottom + info_height], :height => info_height+1, :width => pdf.bounds.width) do
|
78
|
+
info.compact.each do |line|
|
79
|
+
pdf.text(line, :align => :center, :size => pdf.font_size.downto(1).detect() { |size| pdf.width_of(line.to_s, :size => size) <= box_width })
|
80
|
+
end
|
63
81
|
end
|
64
82
|
end
|
65
83
|
end
|
data/lib/wagon/page.rb
CHANGED
data/lib/wagon/ward.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
|
3
3
|
describe "Wagon::Directory" do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@page = Wagon::Directory.new($user, $user.ward.directory_path)
|
6
|
+
@page = Wagon::Directory.new($user, $user.ward.directory_path, $user.ward)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should find the photo directory link" do
|