-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add around_template and text rendering
- Loading branch information
1 parent
66a182b
commit c0ebef2
Showing
3 changed files
with
95 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Phlex::Pdf do | ||
it "generates a PDF" do | ||
class ApplicationComponent < Phlex::PDF | ||
def before_template | ||
text "Before #{self.class.name}" | ||
end | ||
|
||
def view_template | ||
text self.class.name | ||
end | ||
|
||
def after_template | ||
text "After #{self.class.name}" | ||
end | ||
require "phlex/pdf" | ||
|
||
class ApplicationComponent < Phlex::PDF | ||
def before_template | ||
text "Before #{self.class.name}" | ||
end | ||
|
||
def view_template | ||
text self.class.name | ||
end | ||
|
||
def after_template | ||
text "After #{self.class.name}" | ||
end | ||
end | ||
|
||
class HeaderComponent < ApplicationComponent | ||
def view_template | ||
text "Header" | ||
end | ||
end | ||
|
||
class FooterComponent < ApplicationComponent | ||
def view_template | ||
text "Footer" | ||
end | ||
end | ||
|
||
class BodyComponent < ApplicationComponent | ||
def view_template | ||
render "Body" | ||
end | ||
end | ||
|
||
class PageComponent < ApplicationComponent | ||
def view_template | ||
render HeaderComponent.new | ||
render BodyComponent.new do | ||
yield | ||
end | ||
render FooterComponent.new | ||
end | ||
end | ||
|
||
ApplicationComponent.document.render | ||
RSpec.describe Phlex::PDF do | ||
it "generates a PDF" do | ||
PageComponent.render_file "poof.pdf" | ||
end | ||
end |