-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add before_render, around_render and after_render (#90)
- Loading branch information
Showing
3 changed files
with
104 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require "../../spec_helper" | ||
|
||
private class ExampleWithBlock | ||
include Blueprint::HTML | ||
|
||
private def blueprint(&) | ||
h1 { yield } | ||
end | ||
|
||
private def before_render(&) | ||
span { "Before render" } | ||
end | ||
|
||
private def around_render(&) | ||
span { "Around start" } | ||
yield | ||
span { "Around end" } | ||
end | ||
|
||
private def after_render(&) | ||
span { "After render" } | ||
end | ||
end | ||
|
||
private class ExampleWithoutBlock | ||
include Blueprint::HTML | ||
|
||
private def blueprint | ||
h1 "Without block" | ||
end | ||
|
||
private def before_render(&) | ||
span { "Before render" } | ||
end | ||
|
||
private def around_render(&) | ||
span { "Around start" } | ||
yield | ||
span { "Around end" } | ||
end | ||
|
||
private def after_render(&) | ||
span { "After render" } | ||
end | ||
end | ||
|
||
describe "hooks" do | ||
context "with block" do | ||
it "allows defining hooks before_render, around_render, after_render" do | ||
actual_html = ExampleWithBlock.new.to_s { "With block" } | ||
expected_html = normalize_html <<-HTML | ||
<span>Before render</span> | ||
<span>Around start</span> | ||
<h1>With block</h1> | ||
<span>Around end</span> | ||
<span>After render</span> | ||
HTML | ||
|
||
actual_html.should eq expected_html | ||
end | ||
end | ||
|
||
context "without block" do | ||
it "allows defining hooks before_render, around_render, after_render" do | ||
actual_html = ExampleWithoutBlock.new.to_s | ||
expected_html = normalize_html <<-HTML | ||
<span>Before render</span> | ||
<span>Around start</span> | ||
<h1>Without block</h1> | ||
<span>Around end</span> | ||
<span>After render</span> | ||
HTML | ||
|
||
actual_html.should eq expected_html | ||
end | ||
end | ||
end |
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