phlex-pdf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -7
- data/lib/phlex/pdf/version.rb +1 -1
- data/lib/phlex/pdf.rb +47 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ed0d33ef620bd813370875bbe924058ebaea8cb3788d9945a0f56bb909cd468
|
4
|
+
data.tar.gz: 1fef48340c15401133fbc9a9fb90482996b3edd0382b94dd6be97611a1a533b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a8850366e024fad4342f07c4c11c5525cb6b253603767ee79e825e1cb9c58ff6d2d46283b039504bee2f8f68ce36f5659e2b109a87f23749bee76d267b487c
|
7
|
+
data.tar.gz: d3df818ae52444f7799b7f33099f4d570caac8e5132f55401c2df646513377476883f45c41e4c9308eb884b277f48eff9fae7a8b1867d1f9120e0ff8937e331b
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
# Phlex::
|
1
|
+
# Phlex::PDF
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/phlex/pdf`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
Phlex PDF lets you compose PDF files with components in pure Ruby. It's a thin layer that sits on the shoulder of giants, [Prawn](https://github.com/prawnpdf/prawn), that encourages a component-first approach to building PDF documents.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -16,6 +14,8 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
14
|
|
17
15
|
## Usage
|
18
16
|
|
17
|
+
`Phlex::PDF` is a thin wrapper around `Prawn::View`, so you'll want to become familiar with [PrawnPDF](http://prawnpdf.org/), particularly the [PrawnPDF Manual](https://prawnpdf.org/manual.pdf).
|
18
|
+
|
19
19
|
```ruby
|
20
20
|
require "phlex/pdf"
|
21
21
|
|
@@ -46,7 +46,11 @@ class NoticeComponent < ApplicationComponent
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
# Render it to a file
|
50
|
+
NoticeComponent.render_file "hello.pdf"
|
51
|
+
|
52
|
+
# Or to a string
|
53
|
+
NoticeComponent.render
|
50
54
|
```
|
51
55
|
|
52
56
|
## Development
|
@@ -57,7 +61,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
57
61
|
|
58
62
|
## Contributing
|
59
63
|
|
60
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/phlex-ruby/phlex-pdf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/phlex-ruby/phlex-pdf/blob/main/CODE_OF_CONDUCT.md).
|
61
65
|
|
62
66
|
## License
|
63
67
|
|
@@ -65,4 +69,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
65
69
|
|
66
70
|
## Code of Conduct
|
67
71
|
|
68
|
-
Everyone interacting in the Phlex::
|
72
|
+
Everyone interacting in the Phlex::PDF project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/phlex-ruby/phlex-pdf/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/phlex/pdf/version.rb
CHANGED
data/lib/phlex/pdf.rb
CHANGED
@@ -12,19 +12,58 @@ module Phlex
|
|
12
12
|
|
13
13
|
def call(document, &block)
|
14
14
|
@document = document
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
around_template do
|
16
|
+
view_template(&block)
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# @abstract Override this method to hook in around a template render. You can do things before and after calling `super` to render the template. You should always call `super` so that callbacks can be added at different layers of the inheritance tree.
|
21
|
+
# @return [nil]
|
22
|
+
def around_template
|
23
|
+
before_template
|
24
|
+
yield
|
25
|
+
after_template
|
22
26
|
nil
|
23
27
|
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
# @abstract Override this method to hook in right before a template is rendered. Please remember to call `super` so that callbacks can be added at different layers of the inheritance tree.
|
30
|
+
# @return [nil]
|
31
|
+
def before_template
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
# @abstract Override this method to hook in right after a template is rendered. Please remember to call `super` so that callbacks can be added at different layers of the inheritance tree.
|
36
|
+
# @return [nil]
|
37
|
+
def after_template
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def render(renderable, &block)
|
42
|
+
case renderable
|
43
|
+
when String
|
44
|
+
@document.text renderable
|
45
|
+
when Phlex::PDF
|
46
|
+
renderable.call(@document, &block)
|
47
|
+
else
|
48
|
+
raise ArgumentError, "You can't render a #{renderable.inspect}."
|
49
|
+
end
|
50
|
+
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
class << self
|
55
|
+
def document(document = Prawn::Document.new)
|
56
|
+
new.call(document)
|
57
|
+
document
|
58
|
+
end
|
59
|
+
|
60
|
+
def render(...)
|
61
|
+
document.render(...)
|
62
|
+
end
|
63
|
+
|
64
|
+
def render_file(...)
|
65
|
+
document.render_file(...)
|
66
|
+
end
|
28
67
|
end
|
29
68
|
end
|
30
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlex-pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|