Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering explicit template in 1.1 #125

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ gemspec

gem "phlex", github: "phlex-ruby/phlex"
gem "phlex-testing-capybara", github: "phlex-ruby/phlex-testing-capybara"
gem "rspec-rails"
gem "combustion"
gem "rubocop"
gem "solargraph"
gem "view_component"
gem "appraisal", github: "excid3/appraisal", branch: "fix-bundle-env"
gem "yard"

# Ensure rails is loaded before rspec-rails.
gem "rails"
gem "rspec-rails"
3 changes: 2 additions & 1 deletion lib/phlex/rails/sgml/overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def render(*args, **kwargs, &block)
when Enumerable
return super unless renderable.is_a?(ActiveRecord::Relation)
else
@_context.target << @_view_context.render(*args, **kwargs) { capture(&block) }
captured_block = -> { capture(&block) } if block
@_context.target << @_view_context.render(*args, **kwargs, &captured_block)
end

nil
Expand Down
3 changes: 3 additions & 0 deletions spec/internal/app/views/examples/sgml/_wrap.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Partial A
<%= yield %>
Partial B
1 change: 1 addition & 0 deletions spec/internal/app/views/examples/sgml/template.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Plain template.
51 changes: 51 additions & 0 deletions spec/phlex/sgml_spec.rb
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: })
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
Loading