super_pdf 0.1.5 → 0.1.6
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
- data/.github/workflows/test.yml +47 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +77 -0
- data/CLAUDE.md +12 -0
- data/README.md +141 -20
- data/gemfiles/rails_7.0.gemfile +21 -0
- data/gemfiles/rails_7.1.gemfile +21 -0
- data/gemfiles/rails_8.1.gemfile +18 -0
- data/lib/super_pdf/renderer/rows.rb +1 -0
- data/lib/super_pdf/renderer.rb +4 -2
- data/lib/super_pdf/version.rb +1 -1
- metadata +6 -3
- data/gemfiles/rails_7.2.gemfile.lock +0 -73
- data/gemfiles/rails_8.0.gemfile.lock +0 -75
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b767317c59f42a442e1889f30d228e90b9ba4093e1598e33a78af5d5bbbb5936
|
|
4
|
+
data.tar.gz: 2e8b7d86dced0e852a9a54f0b2e61deacb4ad3391da36ed029fae0ae12ad4feb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38b2faaec0d4655428ed27ee70c19bdd738635ef2beb4bd8f793452184e005f26224fec36447afba1f647630300ff216d98338a54aa5361ba81f8ca9b9b9197d
|
|
7
|
+
data.tar.gz: 1bed4dd3ac17cdc33e83532bf306e843c37e0a34d6dab2d318562894070cb0e8b6bb48de78383170c747448cdb20e5e7fedcb05c4a039003d8cc7134002c6641
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master, main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master, main ]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
ruby: ["3.0", "3.1", "3.2", "3.3", "3.4"]
|
|
20
|
+
rails: ["7.0", "7.1", "7.2", "8.0", "8.1"]
|
|
21
|
+
exclude:
|
|
22
|
+
# Rails 7.2 需要 Ruby >= 3.1
|
|
23
|
+
- ruby: "3.0"
|
|
24
|
+
rails: "7.2"
|
|
25
|
+
# Rails 8.0 / 8.1 需要 Ruby >= 3.2
|
|
26
|
+
- ruby: "3.0"
|
|
27
|
+
rails: "8.0"
|
|
28
|
+
- ruby: "3.0"
|
|
29
|
+
rails: "8.1"
|
|
30
|
+
- ruby: "3.1"
|
|
31
|
+
rails: "8.0"
|
|
32
|
+
- ruby: "3.1"
|
|
33
|
+
rails: "8.1"
|
|
34
|
+
env:
|
|
35
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails }}.gemfile
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
38
|
+
with:
|
|
39
|
+
persist-credentials: false
|
|
40
|
+
|
|
41
|
+
- uses: ruby/setup-ruby@b1da4809b005e0178fe08a1d57317bffc00b7b4c # v1.332.0
|
|
42
|
+
with:
|
|
43
|
+
ruby-version: ${{ matrix.ruby }}
|
|
44
|
+
bundler-cache: true
|
|
45
|
+
|
|
46
|
+
- name: Run tests
|
|
47
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# 更新紀錄(Changelog)
|
|
2
|
+
|
|
3
|
+
本檔記錄此專案所有值得注意的變更。
|
|
4
|
+
|
|
5
|
+
格式參考 [Keep a Changelog](https://keepachangelog.com/zh-TW/1.1.0/),版本號遵循 [Semantic Versioning](https://semver.org/lang/zh-TW/)。
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- 新增 `CHANGELOG.md`。
|
|
12
|
+
- README:說明這個 gem 是什麼、環境需求、安裝、使用範例、開發與發版方式。
|
|
13
|
+
- CLAUDE.md:每個 PR 都必須同步更新 `README.md` 與 `CHANGELOG.md`;`README.md` 與 `CHANGELOG.md` 一律用繁體中文撰寫。
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- `README.md`、`CHANGELOG.md` 改以繁體中文(zh-TW)撰寫。
|
|
18
|
+
|
|
19
|
+
## [0.1.6] - 2026-10-27
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `div`、`row` 與 `row.column` 在 Ruby 3.x 會 raise `ArgumentError (wrong number of arguments (given 2, expected 1))`,原因是 `div` 把 Hash 傳給使用 keyword argument 的 `margin_div` / `padding_div`。現在改成以 `**` 展開 options,因此可在 Ruby 3.0–3.4 運作,並且所有既有的呼叫方式(`div(margin: 10)`、`div({ margin: 10 })`、`row.column(width: "50%")`)都能繼續使用。公開 API 沒有變動。
|
|
24
|
+
- `row.column(options)` 不再刪除呼叫端傳入的 Hash 裡的 `:width`(改為對複本操作)。
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- `div`(keyword / hash options、邊框、背景色、百分比寬度、不會改動傳入的 options)以及 `row` / `column` 的測試。
|
|
29
|
+
|
|
30
|
+
## [0.1.5] - 2026-10-27
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- GitHub Actions 測試 workflow:Ruby 3.0–3.4 × Rails(ActiveSupport)7.0–8.1 矩陣。
|
|
35
|
+
- GitHub Actions workflow `publish.yml`:新版本進到 `master` 時自動發佈到 RubyGems(Trusted Publishing)。
|
|
36
|
+
- CLAUDE.md:加入發版 / 跳版號規則。
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- 支援 ActiveSupport 8 與 Ruby 3.3–3.4:gemspec 宣告 `required_ruby_version >= 2.7`,並相依 `matrix` 與 `ostruct`(在較新的 Ruby 已不再是 default gem);明確 require ActiveSupport 的 `Concern` / `delegation`;`draw_border` 的 keyword arguments 改用 splat 傳遞。
|
|
41
|
+
- 依 ActiveSupport 版本拆分 Gemfile(`gemfiles/rails_7.0.gemfile` … `rails_8.1.gemfile`)。
|
|
42
|
+
|
|
43
|
+
## [0.1.4] - 2019-10-18
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- 新增 `SuperPDF.extension_add(base)` 與 `SuperPDF.extensions`,用來註冊 `Prawn::Document` 的擴充。
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- 放寬 `activesupport` 的版本限制(`>= 4`)。
|
|
52
|
+
|
|
53
|
+
## [0.1.2] - 2019-09-17
|
|
54
|
+
|
|
55
|
+
### Changed
|
|
56
|
+
|
|
57
|
+
- 動態 document:`SuperPDF::Enhance#pdf` 現在會建立一個匿名的 `Prawn::Document` 子類別(並 mix in `SuperPDF::Renderer`),不再使用靜態的 `SuperPDF::Document` class(該 class 已移除)。
|
|
58
|
+
|
|
59
|
+
## [0.1.1] - 2019-09-17
|
|
60
|
+
|
|
61
|
+
### Added
|
|
62
|
+
|
|
63
|
+
- 新增 runtime 相依套件 `prawn-icon`。
|
|
64
|
+
|
|
65
|
+
## [0.1.0] - 2019-09-02
|
|
66
|
+
|
|
67
|
+
### Added
|
|
68
|
+
|
|
69
|
+
- 首次發佈:在 Prawn 之上提供 `SuperPDF::Enhance`、`SuperPDF::Page`(頁面尺寸)、`SuperPDF::Font`(預設字型 family)與 `SuperPDF::Renderer`(`page`、`margin_div`、`padding_div`、`abs_div`、`row`/`column`、`scale`、邊框與背景色)。
|
|
70
|
+
|
|
71
|
+
[Unreleased]: https://github.com/superlanding/super_pdf/compare/v0.1.6...HEAD
|
|
72
|
+
[0.1.6]: https://github.com/superlanding/super_pdf/compare/v0.1.5...v0.1.6
|
|
73
|
+
[0.1.5]: https://github.com/superlanding/super_pdf/compare/v0.1.4...v0.1.5
|
|
74
|
+
[0.1.4]: https://github.com/superlanding/super_pdf/tree/v0.1.4
|
|
75
|
+
[0.1.2]: https://github.com/superlanding/super_pdf/tree/0.1.2
|
|
76
|
+
[0.1.1]: https://github.com/superlanding/super_pdf/tree/0.1.1
|
|
77
|
+
[0.1.0]: https://github.com/superlanding/super_pdf/commit/e85890b
|
data/CLAUDE.md
CHANGED
|
@@ -7,3 +7,15 @@
|
|
|
7
7
|
- 跳版規則(Semantic Versioning):修 bug 跳 patch(x.y.Z);新增相容功能跳 minor(x.Y.0);不相容變更跳 major(X.0.0)。
|
|
8
8
|
- 版號只改在 PR 裡。AI 帳號只能開 branch 與 PR,不得合併到 master;只有真人帳號可以合併。合併就等於批准發佈。
|
|
9
9
|
- 不得為了讓測試通過而改變程式原本的行為。
|
|
10
|
+
|
|
11
|
+
## 文件與更新紀錄(README / CHANGELOG)
|
|
12
|
+
|
|
13
|
+
- **每一個 PR 都必須同步更新文件**:
|
|
14
|
+
- 只要行為、用法、設定、相依套件或支援的 Ruby / Rails 版本有變,就要更新 `README.md`。
|
|
15
|
+
- 一律要在 `CHANGELOG.md` 新增一筆條目([Keep a Changelog](https://keepachangelog.com/zh-TW/1.1.0/) 格式,分類用 Added / Changed / Deprecated / Removed / Fixed / Security)。
|
|
16
|
+
- **語言規則**:`README.md` 與 `CHANGELOG.md` 一律用繁體中文(zh-TW,台灣用語)撰寫;程式碼、識別字(class / 方法 / 變數名稱)、指令、檔名與路徑維持英文,不要翻譯。
|
|
17
|
+
- `CHANGELOG.md` 的寫法:
|
|
18
|
+
- 沒有跳版號的 PR:寫在最上方的 `## [Unreleased]` 底下。
|
|
19
|
+
- 有跳版號的 PR:把條目寫在新的版本章節 `## [x.y.z] - YYYY-MM-DD`(日期為合併日),並同步更新檔尾的版本比較連結。
|
|
20
|
+
- 版本號必須與 rubygems.org 上實際發佈的版本一致,不得寫還沒發佈的版本。
|
|
21
|
+
- 只改文件、CI 或 CLAUDE.md 的 PR 不需要跳版號,但仍要在 `CHANGELOG.md` 的 `Unreleased` 補一筆。
|
data/README.md
CHANGED
|
@@ -1,45 +1,166 @@
|
|
|
1
1
|
# SuperPDF
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://rubygems.org/gems/super_pdf)
|
|
4
|
+
[](https://github.com/superlanding/super_pdf/actions/workflows/test.yml)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
SuperPDF 是建構在 [Prawn](https://prawnpdf.org/) 之上的一層簡易排版工具。在任何一般的 Ruby class 裡 include
|
|
7
|
+
`SuperPDF::Enhance`,就會得到一個 `pdf` 物件(也就是 `Prawn::Document`),並附帶類似 CSS 的輔助方法:
|
|
8
|
+
可設定 margin / padding / border / 背景色的區塊、絕對定位區塊、預設字型,以及具名的頁面尺寸。
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
它只依賴 `activesupport`(不需要完整的 Rails 應用程式),所以 Rails、Sidekiq job、一般腳本等環境都能使用。
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
## 環境需求
|
|
13
|
+
|
|
14
|
+
| | 支援版本(CI 都有測試) |
|
|
15
|
+
|---|---|
|
|
16
|
+
| Ruby | 3.0、3.1、3.2、3.3、3.4(gemspec:`>= 2.7`) |
|
|
17
|
+
| ActiveSupport / Rails | 7.0、7.1、7.2、8.0、8.1(gemspec:`activesupport >= 4`) |
|
|
18
|
+
| Runtime 相依套件 | `prawn ~> 2.2`、`prawn-table 0.2.2`、`prawn-icon 2.4.0`、`matrix`、`ostruct` |
|
|
19
|
+
|
|
20
|
+
CI 會跑所有該 Ruby 版本允許的 Ruby × ActiveSupport 組合
|
|
21
|
+
(Rails 7.2 需要 Ruby >= 3.1,Rails 8.0 / 8.1 需要 Ruby >= 3.2)。
|
|
22
|
+
詳見 [`.github/workflows/test.yml`](.github/workflows/test.yml)。
|
|
23
|
+
|
|
24
|
+
## 安裝
|
|
25
|
+
|
|
26
|
+
在應用程式的 Gemfile 加入這一行:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
gem "super_pdf"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
然後執行 `bundle install`,或自行執行 `gem install super_pdf` 安裝。
|
|
33
|
+
|
|
34
|
+
## 使用方式
|
|
35
|
+
|
|
36
|
+
### 1. 註冊字型與頁面尺寸(只需做一次,例如放在 initializer)
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
require "super_pdf"
|
|
40
|
+
|
|
41
|
+
# 頁面尺寸:名稱 => [寬, 高],單位為 PDF point(1 pt = 1/72 英吋),
|
|
42
|
+
# 也可以是 Prawn 的 :page_size 接受的任何值,例如 "A4"。預設為 "A4"。
|
|
43
|
+
SuperPDF::Page::SIZE["label_100x150"] = [283.46, 425.2]
|
|
44
|
+
|
|
45
|
+
# 字型:key 請用 String,value 是 Prawn 的 font family hash。
|
|
46
|
+
SuperPDF::Font::FAMILIES["NotoSansTC"] = {
|
|
47
|
+
normal: Rails.root.join("app/assets/fonts/NotoSansTC-Regular.ttf").to_s,
|
|
48
|
+
bold: Rails.root.join("app/assets/fonts/NotoSansTC-Bold.ttf").to_s
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. 在你的 class 裡 include `SuperPDF::Enhance`
|
|
10
53
|
|
|
11
54
|
```ruby
|
|
12
|
-
|
|
55
|
+
class ShippingLabelPDF
|
|
56
|
+
include SuperPDF::Enhance
|
|
57
|
+
|
|
58
|
+
page_size "label_100x150" # SuperPDF::Page::SIZE 的 key(預設:"A4")
|
|
59
|
+
default_font "NotoSansTC" # SuperPDF::Font::FAMILIES 的 key
|
|
60
|
+
|
|
61
|
+
def render
|
|
62
|
+
pdf.page(margin: 10) do
|
|
63
|
+
pdf.margin_div([0, 0, 10, 0], height: 40, border: "1pt solid #222") do
|
|
64
|
+
pdf.text "Shipping label", size: 14, align: :center
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
pdf.padding_div(5, width: 200, height: 60, border: true) do
|
|
68
|
+
pdf.text "Padded box"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
pdf.abs_div(left: 10, top: 150, right: 10, bottom: 10, background_color: "#f0ffc1") do
|
|
72
|
+
pdf.text "Absolutely positioned", size: 8
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
pdf.scale(0.8, position: :center) { pdf.text "Scaled" }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
pdf.render # => PDF 二進位字串;要寫成檔案請用 pdf.render_file("label.pdf")
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
File.binwrite("label.pdf", ShippingLabelPDF.new.render)
|
|
13
83
|
```
|
|
14
84
|
|
|
15
|
-
|
|
85
|
+
`pdf` 在每個 instance 內只會建立一次(memoize),建立時帶有 `skip_page_creation: true` 且 margin 為 0,
|
|
86
|
+
所以一律要從 `pdf.page` 開始。
|
|
87
|
+
|
|
88
|
+
### `pdf` 提供的輔助方法
|
|
16
89
|
|
|
17
|
-
|
|
90
|
+
| 方法 | 說明 |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `page(options = {}) { }` | 開新的一頁(可帶 `size:`、`layout:`、`margin:`、`font:` 等),並以預設字型執行 block。`size:` 會到 `SuperPDF::Page::SIZE` 查詢。 |
|
|
93
|
+
| `text(string, family: "Name", **prawn_options)` | 即 `Prawn::Document#text`,可用 `family:` 指定這次呼叫使用的字型。 |
|
|
94
|
+
| `margin_div(margin, width:, height:, border:, background_color:) { }` | 帶外距(margin)的區塊。寬 / 高可傳 point 數值或 `"50%"` 字串。 |
|
|
95
|
+
| `padding_div(padding, width:, height:, border:, background_color:) { }` | 帶內距(padding)的區塊。 |
|
|
96
|
+
| `div(margin:, padding:, width:, height:, border:, background_color:) { }` | 一次呼叫就同時具備 `margin_div` 與 `padding_div`(options 可用 keyword 或 Hash 傳入)。 |
|
|
97
|
+
| `row { \|row\| row.column(width: "50%", **div_options) { } }` | 類似 Bootstrap 的 grid:欄(column)在 row 內由左到右排列。 |
|
|
98
|
+
| `abs_div(left:, right:, top:, bottom:, border:, background_color:) { }` | 在目前的 bounds 內做絕對定位的區塊(數值或 `"10%"`);結束後會還原游標位置。 |
|
|
99
|
+
| `scale(factor, origin: [x, y], position: :center) { }` | 縮放 block 內的內容。 |
|
|
100
|
+
| `fill_background_color("#f0ffc1")` | 以背景色填滿目前的 bounds(`#rgb` 或 `#rrggbb`)。 |
|
|
101
|
+
| `page_width`、`page_height` | 扣除 margin 之後的可用區域大小。 |
|
|
18
102
|
|
|
19
|
-
|
|
103
|
+
margin / padding 的值沿用 CSS 簡寫規則:`10`、`[vertical, horizontal]`、`[top, horizontal, bottom]`
|
|
104
|
+
或 `[top, right, bottom, left]`。
|
|
20
105
|
|
|
21
|
-
|
|
106
|
+
border 的值可以是 `true`(1 pt 實線、黑色)、像 `"1pt dashed #222"` 這樣的字串
|
|
107
|
+
(`<width><mm|cm|dm|m|in|yd|ft|pt> <solid|dashed|dotted> #<rgb|rrggbb>`),或是 hash
|
|
108
|
+
`{ color: "222222", style: "solid", width: 1 }`。
|
|
22
109
|
|
|
23
|
-
|
|
110
|
+
### 擴充 Prawn
|
|
24
111
|
|
|
25
|
-
|
|
112
|
+
```ruby
|
|
113
|
+
SuperPDF.extension_add(MyPrawnExtension) # 等同於 Prawn::Document.extensions << MyPrawnExtension
|
|
114
|
+
SuperPDF.extensions # => Prawn::Document.extensions
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 已知限制
|
|
118
|
+
|
|
119
|
+
以下是目前實作造成的限制,先寫在這裡,避免你踩到:
|
|
26
120
|
|
|
27
|
-
|
|
121
|
+
- `div(width: "50%")` 會把百分比套用兩次(先套在 margin 區塊,再套在裡面的 padding 區塊),所以內容實際只有 25 % 寬。
|
|
122
|
+
為了相容性保留這個行為;要精確的百分比請改用 `margin_div` / `padding_div`,或使用數值寬度。
|
|
123
|
+
- 目前版本的 Prawn 是以 String 查詢字型 family 名稱,所以註冊與選用字型時請用 **String** 名稱
|
|
124
|
+
(`"NotoSansTC"`,不要用 `:NotoSansTC`)。
|
|
125
|
+
- 此 repo 內的 `test/support/font/MSJH.ttf` 是空的佔位檔;測試不會用真正的字型來 render。
|
|
28
126
|
|
|
29
|
-
|
|
127
|
+
## 開發
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
git clone https://github.com/superlanding/super_pdf.git
|
|
131
|
+
cd super_pdf
|
|
132
|
+
bin/setup # 用預設 Gemfile 執行 bundle install
|
|
133
|
+
|
|
134
|
+
# 針對單一 Ruby / Rails 組合跑測試(和 CI 的做法相同)
|
|
135
|
+
BUNDLE_GEMFILE=$PWD/gemfiles/rails_8.1.gemfile bundle install
|
|
136
|
+
BUNDLE_GEMFILE=$PWD/gemfiles/rails_8.1.gemfile bundle exec rake test
|
|
137
|
+
|
|
138
|
+
bin/console # 互動式 console
|
|
139
|
+
```
|
|
30
140
|
|
|
31
|
-
|
|
141
|
+
可用的 gemfile:`gemfiles/rails_7.0.gemfile` … `gemfiles/rails_8.1.gemfile`。測試使用 Minitest 與 Mocha
|
|
142
|
+
(`test/**/*_test.rb`)。`rake`(預設 task)會執行測試。
|
|
32
143
|
|
|
33
|
-
##
|
|
144
|
+
## 發版
|
|
34
145
|
|
|
35
|
-
|
|
146
|
+
發版透過 RubyGems [Trusted Publishing](https://guides.rubygems.org/trusted-publishing/) 自動完成
|
|
147
|
+
(repo 內不存放任何 API key):
|
|
36
148
|
|
|
149
|
+
1. 在你的 pull request 裡,依 [Semantic Versioning](https://semver.org/lang/zh-TW/) 修改 `lib/super_pdf/version.rb` 的
|
|
150
|
+
`SuperPDF::VERSION`(修 bug → patch、相容的新功能 → minor、不相容的變更 → major)。
|
|
151
|
+
2. 在 `CHANGELOG.md` 的新版本區塊新增對應條目。
|
|
152
|
+
3. PR 經過 review 後**合併進 `master`**(只有真人可以合併)。
|
|
153
|
+
4. [`.github/workflows/publish.yml`](.github/workflows/publish.yml) 會在 `master` 上執行:比對 gemspec 版本與
|
|
154
|
+
rubygems.org 上的版本,執行測試,若是新版本就發佈 gem 並推送 `vX.Y.Z` tag。
|
|
155
|
+
沒有改版本號的合併不會發佈任何東西。
|
|
37
156
|
|
|
38
|
-
|
|
157
|
+
只改文件或 CI 的 pull request 不需要跳版號。貢獻規則請見 [CLAUDE.md](CLAUDE.md)
|
|
158
|
+
(每個 PR 也都必須更新 `README.md` 與 `CHANGELOG.md`)。
|
|
39
159
|
|
|
40
|
-
|
|
160
|
+
## 貢獻
|
|
41
161
|
|
|
162
|
+
歡迎到 https://github.com/superlanding/super_pdf 回報問題與提交 pull request。
|
|
42
163
|
|
|
43
|
-
##
|
|
164
|
+
## 授權
|
|
44
165
|
|
|
45
|
-
|
|
166
|
+
本 gem 以 [MIT License](LICENSE.txt) 條款開源。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
source "https://rubygems.org"
|
|
3
|
+
|
|
4
|
+
gemspec path: ".."
|
|
5
|
+
|
|
6
|
+
gem "activesupport", "~> 7.0.0"
|
|
7
|
+
gem "rake", ">= 13"
|
|
8
|
+
gem "minitest", "~> 5.0"
|
|
9
|
+
gem "mocha", "~> 1.9"
|
|
10
|
+
|
|
11
|
+
# concurrent-ruby 1.3.5 起不再自動 require logger,Rails 7.0 / 7.1 會載入失敗
|
|
12
|
+
gem "concurrent-ruby", "< 1.3.5"
|
|
13
|
+
|
|
14
|
+
# Ruby 3.4 已不再內建這些 gem;Rails 7.0 / 7.1 沒有自行宣告,故明確列出
|
|
15
|
+
gem "logger"
|
|
16
|
+
gem "mutex_m"
|
|
17
|
+
gem "bigdecimal"
|
|
18
|
+
gem "base64"
|
|
19
|
+
gem "drb"
|
|
20
|
+
gem "matrix"
|
|
21
|
+
gem "ostruct"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
source "https://rubygems.org"
|
|
3
|
+
|
|
4
|
+
gemspec path: ".."
|
|
5
|
+
|
|
6
|
+
gem "activesupport", "~> 7.1.0"
|
|
7
|
+
gem "rake", ">= 13"
|
|
8
|
+
gem "minitest", "~> 5.0"
|
|
9
|
+
gem "mocha", "~> 1.9"
|
|
10
|
+
|
|
11
|
+
# concurrent-ruby 1.3.5 起不再自動 require logger,Rails 7.0 / 7.1 會載入失敗
|
|
12
|
+
gem "concurrent-ruby", "< 1.3.5"
|
|
13
|
+
|
|
14
|
+
# Ruby 3.4 已不再內建這些 gem;Rails 7.0 / 7.1 沒有自行宣告,故明確列出
|
|
15
|
+
gem "logger"
|
|
16
|
+
gem "mutex_m"
|
|
17
|
+
gem "bigdecimal"
|
|
18
|
+
gem "base64"
|
|
19
|
+
gem "drb"
|
|
20
|
+
gem "matrix"
|
|
21
|
+
gem "ostruct"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
source "https://rubygems.org"
|
|
3
|
+
|
|
4
|
+
gemspec path: ".."
|
|
5
|
+
|
|
6
|
+
gem "activesupport", "~> 8.1.0"
|
|
7
|
+
gem "rake", ">= 13"
|
|
8
|
+
gem "minitest", "~> 5.0"
|
|
9
|
+
gem "mocha", "~> 1.9"
|
|
10
|
+
|
|
11
|
+
# Ruby 3.4 已不再內建這些 gem;Rails 7.0 / 7.1 沒有自行宣告,故明確列出
|
|
12
|
+
gem "logger"
|
|
13
|
+
gem "mutex_m"
|
|
14
|
+
gem "bigdecimal"
|
|
15
|
+
gem "base64"
|
|
16
|
+
gem "drb"
|
|
17
|
+
gem "matrix"
|
|
18
|
+
gem "ostruct"
|
|
@@ -31,6 +31,7 @@ module SuperPDF
|
|
|
31
31
|
|
|
32
32
|
def column(options, &block)
|
|
33
33
|
@left_pos ||= pdf.bounds.left
|
|
34
|
+
options = options.dup # do not mutate the caller's hash
|
|
34
35
|
width = options.delete(:width)
|
|
35
36
|
width = pdf.percent2pt_of_width(width) if pdf.percentage?(width)
|
|
36
37
|
pdf.bounding_box([@left_pos, pdf.bounds.top], width: width, height: pdf.bounds.height) do
|
data/lib/super_pdf/renderer.rb
CHANGED
|
@@ -53,8 +53,10 @@ module SuperPDF
|
|
|
53
53
|
# ...
|
|
54
54
|
# end
|
|
55
55
|
def div(options = {}, &block)
|
|
56
|
-
margin_div
|
|
57
|
-
|
|
56
|
+
# `margin_div` / `padding_div` take keyword arguments. Ruby 3 no longer converts a
|
|
57
|
+
# trailing Hash into keywords, so splat explicitly (works on Ruby 2.x - 3.x).
|
|
58
|
+
margin_div(options[:margin], **options.slice(:width, :height, :border, :background_color)) do
|
|
59
|
+
padding_div(options[:padding], **options.slice(:width, :height), &block)
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
|
data/lib/super_pdf/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: super_pdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- vegeta
|
|
@@ -163,7 +163,9 @@ extensions: []
|
|
|
163
163
|
extra_rdoc_files: []
|
|
164
164
|
files:
|
|
165
165
|
- ".github/workflows/publish.yml"
|
|
166
|
+
- ".github/workflows/test.yml"
|
|
166
167
|
- ".gitignore"
|
|
168
|
+
- CHANGELOG.md
|
|
167
169
|
- CLAUDE.md
|
|
168
170
|
- Gemfile
|
|
169
171
|
- LICENSE.txt
|
|
@@ -171,10 +173,11 @@ files:
|
|
|
171
173
|
- Rakefile
|
|
172
174
|
- bin/console
|
|
173
175
|
- bin/setup
|
|
176
|
+
- gemfiles/rails_7.0.gemfile
|
|
177
|
+
- gemfiles/rails_7.1.gemfile
|
|
174
178
|
- gemfiles/rails_7.2.gemfile
|
|
175
|
-
- gemfiles/rails_7.2.gemfile.lock
|
|
176
179
|
- gemfiles/rails_8.0.gemfile
|
|
177
|
-
- gemfiles/rails_8.
|
|
180
|
+
- gemfiles/rails_8.1.gemfile
|
|
178
181
|
- lib/super_pdf.rb
|
|
179
182
|
- lib/super_pdf/enhance.rb
|
|
180
183
|
- lib/super_pdf/font.rb
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: ..
|
|
3
|
-
specs:
|
|
4
|
-
super_pdf (0.1.5)
|
|
5
|
-
activesupport (>= 4)
|
|
6
|
-
matrix
|
|
7
|
-
ostruct
|
|
8
|
-
prawn (~> 2.2, >= 2.2.2)
|
|
9
|
-
prawn-icon (= 2.4.0)
|
|
10
|
-
prawn-table (= 0.2.2)
|
|
11
|
-
|
|
12
|
-
GEM
|
|
13
|
-
remote: https://rubygems.org/
|
|
14
|
-
specs:
|
|
15
|
-
activesupport (7.2.3.2)
|
|
16
|
-
base64
|
|
17
|
-
benchmark (>= 0.3)
|
|
18
|
-
bigdecimal
|
|
19
|
-
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
20
|
-
connection_pool (>= 2.2.5)
|
|
21
|
-
drb
|
|
22
|
-
i18n (>= 1.6, < 2)
|
|
23
|
-
logger (>= 1.4.2)
|
|
24
|
-
minitest (>= 5.1, < 6)
|
|
25
|
-
securerandom (>= 0.3)
|
|
26
|
-
tzinfo (~> 2.0, >= 2.0.5)
|
|
27
|
-
base64 (0.3.0)
|
|
28
|
-
benchmark (0.5.0)
|
|
29
|
-
bigdecimal (4.1.3)
|
|
30
|
-
concurrent-ruby (1.3.8)
|
|
31
|
-
connection_pool (3.0.2)
|
|
32
|
-
drb (2.2.3)
|
|
33
|
-
i18n (1.15.2)
|
|
34
|
-
concurrent-ruby (~> 1.0)
|
|
35
|
-
logger (1.7.0)
|
|
36
|
-
matrix (0.4.3)
|
|
37
|
-
minitest (5.27.0)
|
|
38
|
-
mocha (1.16.1)
|
|
39
|
-
mutex_m (0.3.0)
|
|
40
|
-
ostruct (0.6.3)
|
|
41
|
-
pdf-core (0.9.0)
|
|
42
|
-
prawn (2.4.0)
|
|
43
|
-
pdf-core (~> 0.9.0)
|
|
44
|
-
ttfunk (~> 1.7)
|
|
45
|
-
prawn-icon (2.4.0)
|
|
46
|
-
prawn (>= 1.1.0, < 3.0.0)
|
|
47
|
-
prawn-table (0.2.2)
|
|
48
|
-
prawn (>= 1.3.0, < 3.0.0)
|
|
49
|
-
rake (13.4.2)
|
|
50
|
-
securerandom (0.4.1)
|
|
51
|
-
ttfunk (1.7.0)
|
|
52
|
-
tzinfo (2.0.6)
|
|
53
|
-
concurrent-ruby (~> 1.0)
|
|
54
|
-
|
|
55
|
-
PLATFORMS
|
|
56
|
-
ruby
|
|
57
|
-
x86_64-linux
|
|
58
|
-
|
|
59
|
-
DEPENDENCIES
|
|
60
|
-
activesupport (~> 7.2.0)
|
|
61
|
-
bigdecimal
|
|
62
|
-
bundler (>= 1.14)
|
|
63
|
-
logger
|
|
64
|
-
matrix
|
|
65
|
-
minitest (~> 5.0)
|
|
66
|
-
mocha (~> 1.9)
|
|
67
|
-
mutex_m
|
|
68
|
-
ostruct
|
|
69
|
-
rake (>= 13, >= 10.0)
|
|
70
|
-
super_pdf!
|
|
71
|
-
|
|
72
|
-
BUNDLED WITH
|
|
73
|
-
2.7.2
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: ..
|
|
3
|
-
specs:
|
|
4
|
-
super_pdf (0.1.5)
|
|
5
|
-
activesupport (>= 4)
|
|
6
|
-
matrix
|
|
7
|
-
ostruct
|
|
8
|
-
prawn (~> 2.2, >= 2.2.2)
|
|
9
|
-
prawn-icon (= 2.4.0)
|
|
10
|
-
prawn-table (= 0.2.2)
|
|
11
|
-
|
|
12
|
-
GEM
|
|
13
|
-
remote: https://rubygems.org/
|
|
14
|
-
specs:
|
|
15
|
-
activesupport (8.0.5.1)
|
|
16
|
-
base64
|
|
17
|
-
benchmark (>= 0.3)
|
|
18
|
-
bigdecimal
|
|
19
|
-
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
20
|
-
connection_pool (>= 2.2.5)
|
|
21
|
-
drb
|
|
22
|
-
i18n (>= 1.6, < 2)
|
|
23
|
-
logger (>= 1.4.2)
|
|
24
|
-
minitest (>= 5.1)
|
|
25
|
-
securerandom (>= 0.3)
|
|
26
|
-
tzinfo (~> 2.0, >= 2.0.5)
|
|
27
|
-
uri (>= 0.13.1)
|
|
28
|
-
base64 (0.3.0)
|
|
29
|
-
benchmark (0.5.0)
|
|
30
|
-
bigdecimal (4.1.3)
|
|
31
|
-
concurrent-ruby (1.3.8)
|
|
32
|
-
connection_pool (3.0.2)
|
|
33
|
-
drb (2.2.3)
|
|
34
|
-
i18n (1.15.2)
|
|
35
|
-
concurrent-ruby (~> 1.0)
|
|
36
|
-
logger (1.7.0)
|
|
37
|
-
matrix (0.4.3)
|
|
38
|
-
minitest (5.27.0)
|
|
39
|
-
mocha (1.16.1)
|
|
40
|
-
mutex_m (0.3.0)
|
|
41
|
-
ostruct (0.6.3)
|
|
42
|
-
pdf-core (0.9.0)
|
|
43
|
-
prawn (2.4.0)
|
|
44
|
-
pdf-core (~> 0.9.0)
|
|
45
|
-
ttfunk (~> 1.7)
|
|
46
|
-
prawn-icon (2.4.0)
|
|
47
|
-
prawn (>= 1.1.0, < 3.0.0)
|
|
48
|
-
prawn-table (0.2.2)
|
|
49
|
-
prawn (>= 1.3.0, < 3.0.0)
|
|
50
|
-
rake (13.4.2)
|
|
51
|
-
securerandom (0.4.1)
|
|
52
|
-
ttfunk (1.7.0)
|
|
53
|
-
tzinfo (2.0.6)
|
|
54
|
-
concurrent-ruby (~> 1.0)
|
|
55
|
-
uri (1.1.1)
|
|
56
|
-
|
|
57
|
-
PLATFORMS
|
|
58
|
-
ruby
|
|
59
|
-
x86_64-linux
|
|
60
|
-
|
|
61
|
-
DEPENDENCIES
|
|
62
|
-
activesupport (= 8.0.5.1)
|
|
63
|
-
bigdecimal
|
|
64
|
-
bundler (>= 1.14)
|
|
65
|
-
logger
|
|
66
|
-
matrix
|
|
67
|
-
minitest (~> 5.0)
|
|
68
|
-
mocha (~> 1.9)
|
|
69
|
-
mutex_m
|
|
70
|
-
ostruct
|
|
71
|
-
rake (>= 13, >= 10.0)
|
|
72
|
-
super_pdf!
|
|
73
|
-
|
|
74
|
-
BUNDLED WITH
|
|
75
|
-
2.7.2
|