Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
bradgessler committed Feb 29, 2024
1 parent 165e055 commit 4948434
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ If bundler is not being used to manage dependencies, install the gem by executin
```ruby
require "phlex/pdf"

# Base component. You'll put methods here that are shared across all components.
class PDFComponent < Phlex::PDF
end

# Page has a `before_template` method that created a new page. Without a page
# nothing will render and an error would occur.
class PDFPage < PDFComponent
# Creates a new page
def before_template = create_new_page
Expand All @@ -31,13 +34,17 @@ class PDFPage < PDFComponent
end
end

# Example component inherits from PDFComponent. Note that it does NOT create any
# new pages.
class BoxComponent < PDFComponent
def view_template
text "I'm a box"
yield
end
end

# The final PDF that's rendered should be a subclass of PDFPage. Components
# can be rendered within a PDFPage.
class MyPage < PDFPage
def initialize(title:)
@title = title
Expand All @@ -52,7 +59,7 @@ class MyPage < PDFPage
end
end

# Render the PDF
# Render the PDF to a string.
MyPage.new(title: "This is a PDF!").to_pdf
```

Expand Down

0 comments on commit 4948434

Please sign in to comment.