phlexing icon indicating copy to clipboard operation
phlexing copied to clipboard

Stray `text` calls on method calls that render or capture for `Phlex::DeferredRender

Open hangsu opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe. Phlexing can't tell when to leave out the text method call on methods that render

image

Expected:

render SomeComponent.new do |c|
  c.section { "hello world" }
end

Not sure what the solution might be. Phlexing obviously doesn't know if c.section is rendering, capturing for Phlex::DeferredRender or returning a String.

hangsu avatar Feb 07 '23 16:02 hangsu

Hey @hangsu, thanks for bringing this up!

This is indeed something I haven't considered yet, and I'm actually not sure if and how we could support this.

Unless we add a rule that doesn't output the text call if the method which is being called takes in a block. But I'm not sure if that would be correct in 100% of the cases. Probably not, but it's probably more cases where that would be the more "desirable" outcome.

For the string inside the block we could do something similar as we do with regular HTML elements. Currently this:

<div>123</div>
<div><span>123</span>456</div>

gets converted to:

div { "123" }

div do
  span { "123" }
  text "456"
end

where we also omit the text call in the first example if there are other siblings. Maybe we could also do something similar for this case too.

marcoroth avatar Feb 07 '23 16:02 marcoroth