phlex-pdf 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e265d912e998c60ecf6d2d9cd8d68bbd183769525b13e60c02b3a9c82af99699
4
- data.tar.gz: a7688fbcf405741dba49938da25cb91d2c9ac7fc70a34a67379ec2724b75b23f
3
+ metadata.gz: 3ed0d33ef620bd813370875bbe924058ebaea8cb3788d9945a0f56bb909cd468
4
+ data.tar.gz: 1fef48340c15401133fbc9a9fb90482996b3edd0382b94dd6be97611a1a533b4
5
5
  SHA512:
6
- metadata.gz: d5986c26c44ebba40a95a9c254bf3e492d11e41d41b8b8e0dcb01745efe101739fcdc69fc1b62138113ae4479beda3e3dad115745b62f80dd2a0e69e056ed287
7
- data.tar.gz: 932a86b037f7a2258e6fd037bf0ebae5834f95d415cd96851838e65ea62ac9c77b255355b26da549a69cb151332c87392b5d49cc6d5a6327e6c4e657d15d9795
6
+ metadata.gz: c1a8850366e024fad4342f07c4c11c5525cb6b253603767ee79e825e1cb9c58ff6d2d46283b039504bee2f8f68ce36f5659e2b109a87f23749bee76d267b487c
7
+ data.tar.gz: d3df818ae52444f7799b7f33099f4d570caac8e5132f55401c2df646513377476883f45c41e4c9308eb884b277f48eff9fae7a8b1867d1f9120e0ff8937e331b
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Phlex::Pdf
1
+ # Phlex::PDF
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- NoticeComponent.pdf.render_file "poof.pdf"
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/[USERNAME]/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/[USERNAME]/phlex-pdf/blob/main/CODE_OF_CONDUCT.md).
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::Pdf project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/phlex-pdf/blob/main/CODE_OF_CONDUCT.md).
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).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Pdf
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
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
- before_template if respond_to?(:before_template)
16
- view_template(&block)
17
- after_template if respond_to?(:after_template)
15
+ around_template do
16
+ view_template(&block)
17
+ end
18
18
  end
19
19
 
20
- def render(component, &block)
21
- component.call(@document, &block)
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
- def self.document(document = Prawn::Document.new)
26
- new.call(document)
27
- document
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.0
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-24 00:00:00.000000000 Z
11
+ date: 2024-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn