-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inline component throws error with strip_trailing_whitespace (#2015)
* add rstrip failing test case * simplify failing tests * final failig test revision * fix failing tests * add: changelog entry * fix linting errors * add: inline benchmark * refcator benchmark * fix: linting * Update docs/CHANGELOG.md --------- Co-authored-by: Hans Lemuet <[email protected]>
- Loading branch information
1 parent
7eac9a7
commit 66dcb7c
Showing
7 changed files
with
89 additions
and
2 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
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
class Performance::NewInlineComponent < ViewComponent::Base | ||
class NestedComponent < ViewComponent::Base | ||
def initialize(name:) | ||
@name = name | ||
end | ||
|
||
erb_template <<~ERB | ||
<p>nested hello #{@name}</p> | ||
ERB | ||
end | ||
|
||
def initialize(name:) | ||
@name = name | ||
end | ||
|
||
erb_template <<~ERB | ||
<h1>hello #{@name}</h1> | ||
<%= | ||
safe_join( | ||
[ | ||
content, | ||
50.times.map { render NestedComponent.new(name: @name) } | ||
], | ||
"\n\n" | ||
) | ||
%> | ||
ERB | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
# Run `bundle exec rake benchmark` to execute benchmark. | ||
# This is very much a work-in-progress. Please feel free to make/suggest improvements! | ||
|
||
require "benchmark/ips" | ||
|
||
# Configure Rails Environment | ||
ENV["RAILS_ENV"] = "production" | ||
require File.expand_path("../test/sandbox/config/environment.rb", __dir__) | ||
|
||
module Performance | ||
require_relative "components/new_inline_component" | ||
end | ||
|
||
class BenchmarksController < ActionController::Base | ||
end | ||
|
||
BenchmarksController.view_paths = [File.expand_path("./views", __dir__)] | ||
controller_view = BenchmarksController.new.view_context | ||
|
||
Benchmark.ips do |x| | ||
x.time = 10 | ||
x.warmup = 2 | ||
|
||
x.report("inline_component") do | ||
controller_view.render(Performance::NewInlineComponent.new(name: "Reegan")) | ||
end | ||
|
||
x.compare! | ||
end |
10 changes: 10 additions & 0 deletions
10
test/sandbox/app/components/inline_trailing_whitespace_component.rb
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class InlineTrailingWhitespaceComponent < ViewComponent::Base | ||
strip_trailing_whitespace | ||
|
||
erb_template <<~ERB | ||
<h1>Template does not contain any trailing whitespace</h1> | ||
ERB | ||
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