prawn_calendar 0.0.1 → 1.0.0
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/README.md +8 -2
- data/lib/prawn_calendar.rb +89 -99
- data/lib/prawn_calendar/version.rb +1 -1
- data/prawn_calendar.gemspec +1 -1
- data/spec/output/testcalendar.pdf +2 -2
- data/testresults/test_results.html +5 -5
- metadata +8 -8
data/README.md
CHANGED
@@ -32,7 +32,7 @@ For the impatient ...
|
|
32
32
|
|
33
33
|
~~~~ruby
|
34
34
|
it "implicit creates a calendar" do
|
35
|
-
Prawn::Document.generate("
|
35
|
+
Prawn::Document.generate("calendar.pdf") do
|
36
36
|
calendar=PrawnCalendar::WeeklyCalendar.new(self)
|
37
37
|
calendar.mk_calendar([20,700], width:500,height:250) do
|
38
38
|
cal_entry("2013-05-04T08:00:00+01:00", "2013-05-04T19:00:00", "cc 7as ist ein test, der laufen muss")
|
@@ -40,9 +40,15 @@ For the impatient ...
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
43
|
~~~~
|
45
44
|
|
45
|
+
## History
|
46
|
+
|
47
|
+
* 1.0.0 2014-08-14
|
48
|
+
|
49
|
+
Released as 1.0.0 after testing with Prawn 1.2.1
|
50
|
+
|
51
|
+
|
46
52
|
## Limitations
|
47
53
|
|
48
54
|
* It does not handle schedules over multiple days
|
data/lib/prawn_calendar.rb
CHANGED
@@ -4,26 +4,11 @@ require 'time'
|
|
4
4
|
require 'date'
|
5
5
|
|
6
6
|
|
7
|
-
module
|
8
|
-
class Document
|
9
|
-
|
10
|
-
# Defines the grid system for a particular document. Takes the number of
|
11
|
-
# rows and columns and the width to use for the gutter as the
|
12
|
-
# keys :rows, :columns, :gutter, :row_gutter, :column_gutter
|
13
|
-
#
|
14
|
-
def define_grid(options = {})
|
15
|
-
@grid = Grid.new(self, options)
|
16
|
-
@boxes = nil # see
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
7
|
+
# this module holds all the stuff for PrawnCalendar
|
21
8
|
module PrawnCalendar
|
22
9
|
|
23
10
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# @author [author]
|
11
|
+
# This Class represents a weekly calendar
|
27
12
|
#
|
28
13
|
class WeeklyCalendar
|
29
14
|
# the Prawn instance xxx
|
@@ -38,6 +23,9 @@ module PrawnCalendar
|
|
38
23
|
# the number of divisions in calender columns
|
39
24
|
# this is to adjust the proportion of the first and
|
40
25
|
# the subsequent columns
|
26
|
+
#
|
27
|
+
# for example c_col_division = 5 and c_first_col_division = 2
|
28
|
+
# makes the first column width be 2/5 of the calender column width
|
41
29
|
attr_accessor :c_col_division
|
42
30
|
|
43
31
|
# the end of the interval
|
@@ -64,6 +52,8 @@ module PrawnCalendar
|
|
64
52
|
|
65
53
|
# the number of divisions in the first column
|
66
54
|
# the one showing the time
|
55
|
+
#
|
56
|
+
# see [c_col_division] for more details.
|
67
57
|
attr_accessor :c_firstcol_division
|
68
58
|
|
69
59
|
# The font size of the calendar annotations
|
@@ -97,7 +87,7 @@ module PrawnCalendar
|
|
97
87
|
d = Date.iso8601(day)
|
98
88
|
# note that we start the week on monday, therefore d -(d-1).wday
|
99
89
|
# note that Date adds days, while Time adds seconds
|
100
|
-
#
|
90
|
+
#
|
101
91
|
# compute the beginning of the week
|
102
92
|
@c_date_start = (d -(d-1).wday).to_time
|
103
93
|
# set end to the last second of end date
|
@@ -180,7 +170,7 @@ module PrawnCalendar
|
|
180
170
|
# @param text [String] The text of calender entry
|
181
171
|
# @param extraargs [Hash] additional arguments
|
182
172
|
# :recurring true/false
|
183
|
-
#
|
173
|
+
#
|
184
174
|
# @return nil
|
185
175
|
#
|
186
176
|
def cal_entry(starttime, endtime, text, extraargs={})
|
@@ -292,108 +282,108 @@ module PrawnCalendar
|
|
292
282
|
end
|
293
283
|
|
294
284
|
if recurring==true then
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
285
|
+
@pdf.rounded_rectangle([@pdf.bounds.width - 2, @c_entry_gutter], # startpoint
|
286
|
+
2 , # width
|
287
|
+
2 , # height
|
288
|
+
@c_entry_radius # radius
|
289
|
+
)
|
290
|
+
@pdf.fill_and_stroke
|
291
|
+
end
|
302
292
|
|
303
293
|
|
304
294
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
295
|
+
# text is limited to gutter. Therefore gutter needs to be doubled
|
296
|
+
# no limit at right and bottom
|
297
|
+
excess_text = @pdf.text_box text,
|
298
|
+
:at => [@c_entry_gutter +2, @pdf.bounds.height- 2*@c_entry_gutter-1], # need 1 pixel more a the top
|
299
|
+
:width => @pdf.bounds.width-4*@c_entry_gutter -2*@c_entry_right_gutter,
|
300
|
+
:height => @pdf.bounds.height-4*@c_entry_gutter,
|
301
|
+
:overflow => :truncate,
|
302
|
+
:kerning => true,
|
303
|
+
:inline_format => true,
|
304
|
+
:size => @c_entry_fontsize
|
305
|
+
end
|
306
|
+
nil
|
315
307
|
end
|
316
|
-
nil
|
317
|
-
end
|
318
308
|
|
319
309
|
|
320
310
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
311
|
+
#
|
312
|
+
# Creates an empty calendar
|
313
|
+
#
|
314
|
+
# @param ll [Array] the start point of the calendar
|
315
|
+
# values are points, 0,0 is the lower left corner of the calender
|
316
|
+
# see Prawn::Document.bounding_box for details
|
317
|
+
# @param opts [Hash] [the options, keys: :width, :height]
|
318
|
+
# @param &block [Proc] The statements to fill the calendar.
|
319
|
+
#
|
320
|
+
# @return [type] [description]
|
321
|
+
def mk_calendar(ll, opts, &block)
|
322
|
+
@pdf.bounding_box(ll, width: opts[:width], height: opts[:height]) do
|
323
|
+
@pdf.stroke_bounds
|
324
|
+
rows = (2 + @c_time_end - @c_time_start +1 + @c_extra_rows) * @c_row_division
|
325
|
+
columns = @c_firstcol_division + @c_days.count * @c_col_division
|
336
326
|
|
337
|
-
|
327
|
+
@pdf.define_grid(:columns => columns, :rows => rows, :gutter => 0)
|
338
328
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
329
|
+
# the frames
|
330
|
+
@pdf.line_width 1
|
331
|
+
mk_entry([0,0],
|
332
|
+
[rows - 1, columns-1], "") # outer frame
|
343
333
|
|
344
|
-
|
345
|
-
|
334
|
+
mk_entry([2 * @c_row_division, @c_firstcol_division],
|
335
|
+
[rows - 1 , columns-1], "") # inner frame
|
346
336
|
|
347
|
-
|
348
|
-
|
337
|
+
mk_entry([2 * @c_row_division, 0],
|
338
|
+
[rows -1, @c_firstcol_division - 1], "") # left frame
|
349
339
|
|
350
|
-
|
351
|
-
|
352
|
-
|
340
|
+
# the day - line
|
341
|
+
row=0;col=@c_firstcol_division
|
342
|
+
curday=@c_date_start.to_date
|
353
343
|
|
354
|
-
|
344
|
+
@c_days.each do |i|
|
355
345
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
346
|
+
columnhead="#{i} #{curday.strftime('%d.%m.')}"
|
347
|
+
mk_entry([row,col], [row+@c_row_division-1, col+@c_col_division-1], columnhead)
|
348
|
+
#require 'pry';binding.pry
|
349
|
+
curday=curday+1
|
350
|
+
col += @c_col_division
|
351
|
+
end
|
362
352
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
353
|
+
# the day after line
|
354
|
+
row=@c_row_division; col=@c_firstcol_division
|
355
|
+
@pdf.line_width 0.75
|
356
|
+
@c_days.each do |i|
|
357
|
+
mk_entry([row, col], [rows -1, col + @c_col_division - 1], "")
|
358
|
+
col+=@c_col_division
|
359
|
+
end
|
370
360
|
|
371
|
-
|
372
|
-
|
373
|
-
|
361
|
+
#the calendar fields
|
362
|
+
@pdf.line_width "0.1"
|
363
|
+
col=0;row=@c_row_division
|
374
364
|
|
375
|
-
|
376
|
-
|
365
|
+
# the rows
|
366
|
+
rowlabels=Array(@c_time_start .. @c_time_end).map{|i| "0#{i}.00"[-5..5]}
|
377
367
|
|
378
|
-
|
379
|
-
|
368
|
+
a=[" ", rowlabels, [].fill(" ", 0, @c_extra_rows)]
|
369
|
+
a.flatten.each do |i|
|
380
370
|
|
381
|
-
|
382
|
-
|
383
|
-
|
371
|
+
# the first column
|
372
|
+
# -1 bcause it denotes tha last filled cell, not the next unfilled one
|
373
|
+
mk_entry([row,col],[row + @c_row_division - 1, col+@c_firstcol_division - 1], "#{i}")
|
384
374
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
375
|
+
# the other columns
|
376
|
+
icol=@c_firstcol_division
|
377
|
+
(1..7).each do |i|
|
378
|
+
mk_entry([row, icol], [row + @c_row_division -1, icol + @c_col_division - 1], " ")
|
379
|
+
icol=icol + @c_col_division
|
380
|
+
end
|
381
|
+
row += @c_row_division
|
390
382
|
end
|
391
|
-
row += @c_row_division
|
392
|
-
end
|
393
383
|
|
394
|
-
|
395
|
-
|
384
|
+
#yield the block
|
385
|
+
instance_eval(&block)
|
386
|
+
end
|
396
387
|
end
|
397
388
|
end
|
398
389
|
end
|
399
|
-
end
|
data/prawn_calendar.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "prawn"
|
21
|
+
spec.add_dependency "prawn", "~> 1.2.1"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency "rspec"
|
@@ -17,7 +17,7 @@ endobj
|
|
17
17
|
>>
|
18
18
|
endobj
|
19
19
|
4 0 obj
|
20
|
-
<< /Length
|
20
|
+
<< /Length 39763
|
21
21
|
>>
|
22
22
|
stream
|
23
23
|
q
|
@@ -3220,7 +3220,7 @@ endobj
|
|
3220
3220
|
>>
|
3221
3221
|
endobj
|
3222
3222
|
8 0 obj
|
3223
|
-
<< /Length
|
3223
|
+
<< /Length 34120
|
3224
3224
|
>>
|
3225
3225
|
stream
|
3226
3226
|
q
|
@@ -286,16 +286,16 @@ a {
|
|
286
286
|
<dl style="margin-left: 0px;">
|
287
287
|
<dt id="example_group_1" class="passed">PrawnCalendar::WeeklyCalendar</dt>
|
288
288
|
<script type="text/javascript">moveProgressBar('25.0');</script>
|
289
|
-
<dd class="example passed"><span class="passed_spec_name">connects to a pdf document</span><span class='duration'>0.
|
289
|
+
<dd class="example passed"><span class="passed_spec_name">connects to a pdf document</span><span class='duration'>0.00038s</span></dd>
|
290
290
|
<script type="text/javascript">moveProgressBar('50.0');</script>
|
291
|
-
<dd class="example passed"><span class="passed_spec_name">creates a calendar</span><span class='duration'>0.
|
291
|
+
<dd class="example passed"><span class="passed_spec_name">creates a calendar</span><span class='duration'>0.39653s</span></dd>
|
292
292
|
<script type="text/javascript">moveProgressBar('75.0');</script>
|
293
|
-
<dd class="example passed"><span class="passed_spec_name">implicit creates a calendar</span><span class='duration'>0.
|
293
|
+
<dd class="example passed"><span class="passed_spec_name">implicit creates a calendar</span><span class='duration'>0.05935s</span></dd>
|
294
294
|
<script type="text/javascript">moveProgressBar('100.0');</script>
|
295
|
-
<dd class="example passed"><span class="passed_spec_name">explicit creates a calendar</span><span class='duration'>0.
|
295
|
+
<dd class="example passed"><span class="passed_spec_name">explicit creates a calendar</span><span class='duration'>0.05927s</span></dd>
|
296
296
|
</dl>
|
297
297
|
</div>
|
298
|
-
<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>0.
|
298
|
+
<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>0.51654 seconds</strong>";</script>
|
299
299
|
<script type="text/javascript">document.getElementById('totals').innerHTML = "4 examples, 0 failures";</script>
|
300
300
|
</div>
|
301
301
|
</div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: prawn
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.2.1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bundler
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
156
|
version: '0'
|
157
157
|
segments:
|
158
158
|
- 0
|
159
|
-
hash: -
|
159
|
+
hash: -965068968699314115
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
segments:
|
167
167
|
- 0
|
168
|
-
hash: -
|
168
|
+
hash: -965068968699314115
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
171
|
rubygems_version: 1.8.25
|