-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from phlex-ruby/kbs/fix-render-template
Fix rendering explicit template in 1.1
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Partial A | ||
<%= yield %> | ||
Partial B |
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 @@ | ||
Plain template. |
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe Phlex::SGML do | ||
describe "#render" do | ||
context "when given a block" do | ||
it "renders content in the proper order" do | ||
component = Class.new(Phlex::HTML) do | ||
def template(&block) | ||
plain "Component A\n" | ||
render("examples/sgml/wrap", &block) | ||
plain "Component B\n" | ||
end | ||
end | ||
|
||
content = ExamplesController.render(inline: <<~ERB, locals: { component: component }) | ||
ERB A | ||
<%= render component.new do %> | ||
Hello | ||
<% end %> | ||
ERB B | ||
ERB | ||
|
||
expect(content).to eq(<<~OUTPUT) | ||
ERB A | ||
Component A | ||
Partial A | ||
Hello | ||
Partial B | ||
Component B | ||
ERB B | ||
OUTPUT | ||
end | ||
end | ||
|
||
it "renders a template without a block" do | ||
component = Class.new(Phlex::HTML) do | ||
def template | ||
render(template: "examples/sgml/template") | ||
end | ||
end | ||
|
||
content = ExamplesController.render(component) | ||
|
||
expect(content).to eq("Plain template.") | ||
end | ||
end | ||
end |