repolho 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +31 -0
- data/lib/repolho/main.rb +16 -0
- data/lib/repolho/page.rb +22 -0
- data/lib/repolho/version.rb +1 -1
- data/test/main_test.rb +32 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2947412a1701b9659d7abb8c24137db2bf71245dcd17dc6c7f2bc5524602e646
|
|
4
|
+
data.tar.gz: 8bb7baf19c2dff982915c782ddb45699b9b134cb841ca23d5712feca21a019d7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc19d0a464fc9abe19eabcb06ea687b4ead5f401165a137f29ba76d6d3d7f8db422bf749e8627f3054357f93cd04928d928054b2ea2d5bcda4e64de303074122
|
|
7
|
+
data.tar.gz: 263caa4a89a5fe552b484dc36e4cee55600ce5d63f21c2d279d29e35c8ebb28cb75cc557a574db332a0435431ec49d965f621bbb9313dd6f6c659d2311b208ee
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.md
CHANGED
|
@@ -64,6 +64,37 @@ sections). Everything inside the custom elements is processed as ERB.
|
|
|
64
64
|
| `<report-header>` | Header of the current container | — |
|
|
65
65
|
| `<report-footer>` | Footer of the current container | — |
|
|
66
66
|
| `<report-row>` | Template for each data row (inside the innermost group) | — |
|
|
67
|
+
| `<report-last-page>` | Optional block rendered only at the end of the report, as additional rows on the last page. Counts toward the page row limit and can force a page break. | — |
|
|
68
|
+
|
|
69
|
+
### Last page content (`<report-last-page>`)
|
|
70
|
+
|
|
71
|
+
Optional element that is rendered **only after all data rows** have been processed.
|
|
72
|
+
Its content is injected as normal rows into the page flow, so:
|
|
73
|
+
|
|
74
|
+
- It counts toward the `rows` limit of `<report-page>`.
|
|
75
|
+
- If it does not fit on the current page, a new page is opened automatically.
|
|
76
|
+
- The page footer of the final page is rendered **after** this block.
|
|
77
|
+
|
|
78
|
+
Because the block is only ever emitted at the end, you do not need to check `last_page?` inside it.
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<report>
|
|
84
|
+
<report-page rows="40">
|
|
85
|
+
<report-header>...</report-header>
|
|
86
|
+
<report-row>...</report-row>
|
|
87
|
+
<report-footer>
|
|
88
|
+
<tr><td>Page <%= page_number %></td></tr>
|
|
89
|
+
</report-footer>
|
|
90
|
+
</report-page>
|
|
91
|
+
|
|
92
|
+
<report-last-page>
|
|
93
|
+
<tr><td colspan="5">Final notes and signature</td></tr>
|
|
94
|
+
<tr><td colspan="5">______________________________</td></tr>
|
|
95
|
+
</report-last-page>
|
|
96
|
+
</report>
|
|
97
|
+
```
|
|
67
98
|
|
|
68
99
|
### Allowed HTML inside page content
|
|
69
100
|
|
data/lib/repolho/main.rb
CHANGED
|
@@ -79,6 +79,7 @@ module Repolho
|
|
|
79
79
|
@pagination = false
|
|
80
80
|
@orientation = nil
|
|
81
81
|
@paper = nil
|
|
82
|
+
@last_page_template = nil
|
|
82
83
|
@pagination_labels = {
|
|
83
84
|
first: "First",
|
|
84
85
|
prev: "<",
|
|
@@ -104,6 +105,8 @@ module Repolho
|
|
|
104
105
|
@report.call(:row, row)
|
|
105
106
|
end
|
|
106
107
|
|
|
108
|
+
inject_last_page_content
|
|
109
|
+
|
|
107
110
|
@report.call(:finish, nil)
|
|
108
111
|
@page.finalize
|
|
109
112
|
|
|
@@ -140,6 +143,16 @@ module Repolho
|
|
|
140
143
|
|
|
141
144
|
private
|
|
142
145
|
|
|
146
|
+
def inject_last_page_content
|
|
147
|
+
return if @last_page_template.nil? || @last_page_template.strip.empty?
|
|
148
|
+
|
|
149
|
+
@page.mark_as_last!
|
|
150
|
+
rendered = render_erb(@last_page_template)
|
|
151
|
+
@page.inject_as_rows(rendered)
|
|
152
|
+
# Page footer is rendered later by the normal :finish path,
|
|
153
|
+
# after any remaining group footers.
|
|
154
|
+
end
|
|
155
|
+
|
|
143
156
|
def inject_pagination_labels
|
|
144
157
|
@page.instance_variable_set(:@pagination_first, @pagination_labels[:first])
|
|
145
158
|
@page.instance_variable_set(:@pagination_prev, @pagination_labels[:prev])
|
|
@@ -247,6 +260,9 @@ module Repolho
|
|
|
247
260
|
|
|
248
261
|
build_page(report)
|
|
249
262
|
build_groups(report)
|
|
263
|
+
|
|
264
|
+
last_page = report.search("report-last-page").first
|
|
265
|
+
@last_page_template = last_page.inner_html if last_page
|
|
250
266
|
end
|
|
251
267
|
|
|
252
268
|
def build_page(report)
|
data/lib/repolho/page.rb
CHANGED
|
@@ -14,6 +14,7 @@ module Repolho
|
|
|
14
14
|
@row_number = 1
|
|
15
15
|
@page_number = 1
|
|
16
16
|
@page_open = false
|
|
17
|
+
@last_page = false
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def rows=(number)
|
|
@@ -21,6 +22,27 @@ module Repolho
|
|
|
21
22
|
@valid_rows = @rows
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def last_page?
|
|
26
|
+
@last_page
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def mark_as_last!
|
|
30
|
+
@last_page = true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Injects pre-rendered HTML (expected to contain <tr>s) as additional rows.
|
|
34
|
+
# Each <tr> is appended individually so normal page-break logic applies.
|
|
35
|
+
def inject_as_rows(html)
|
|
36
|
+
return if html.nil? || html.strip.empty?
|
|
37
|
+
|
|
38
|
+
Nokogiri::HTML(html).search("tr").each do |tr|
|
|
39
|
+
check_page_break
|
|
40
|
+
# After a break, status is FINISHED; reopen so later :finish can still emit the footer
|
|
41
|
+
@status = STARTED if @status == FINISHED
|
|
42
|
+
self << tr.to_html
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
24
46
|
def <<(content)
|
|
25
47
|
return unless content
|
|
26
48
|
|
data/lib/repolho/version.rb
CHANGED
data/test/main_test.rb
CHANGED
|
@@ -370,6 +370,38 @@ module Repolho
|
|
|
370
370
|
refute_includes columns, "state"
|
|
371
371
|
end
|
|
372
372
|
|
|
373
|
+
def test_last_page_content_is_injected_and_counts_as_rows
|
|
374
|
+
template_html = <<~HTML
|
|
375
|
+
<!DOCTYPE html>
|
|
376
|
+
<html><body>
|
|
377
|
+
<table>
|
|
378
|
+
<report>
|
|
379
|
+
<report-page rows="3">
|
|
380
|
+
<report-header><tr><th>H</th></tr></report-header>
|
|
381
|
+
<report-row><tr><td><%= attr(:id) %></td></tr></report-row>
|
|
382
|
+
<report-footer><tr><td>F</td></tr></report-footer>
|
|
383
|
+
</report-page>
|
|
384
|
+
<report-last-page>
|
|
385
|
+
<tr><td>LAST BLOCK LINE 1</td></tr>
|
|
386
|
+
<tr><td>LAST BLOCK LINE 2</td></tr>
|
|
387
|
+
</report-last-page>
|
|
388
|
+
</report>
|
|
389
|
+
</table>
|
|
390
|
+
</body></html>
|
|
391
|
+
HTML
|
|
392
|
+
template = write_temp_template(template_html)
|
|
393
|
+
main = Main.new(template.path, @data) # 3 rows
|
|
394
|
+
main.run
|
|
395
|
+
html = main.content.join
|
|
396
|
+
|
|
397
|
+
assert_includes html, "LAST BLOCK LINE 1"
|
|
398
|
+
assert_includes html, "LAST BLOCK LINE 2"
|
|
399
|
+
# Should have caused a page break because 3 data + 2 last = more than rows=3
|
|
400
|
+
assert_operator html.scan(/repolho-page/).size, :>=, 2
|
|
401
|
+
ensure
|
|
402
|
+
template&.unlink
|
|
403
|
+
end
|
|
404
|
+
|
|
373
405
|
def test_page_number_available_in_after_erb
|
|
374
406
|
after_erb = <<~HTML
|
|
375
407
|
<!DOCTYPE html>
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|