bridgetownrb / roda-turbo

Turbo Streams support for Roda.
MIT License
16 stars 1 forks source link

turbo_stream helper block support - no method `capture` #3

Open candland opened 1 year ago

candland commented 1 year ago

I'm testing out the Turbo support and found the turbo_stream helper errors when passing a block in an ERB template.

Am I doing something wrong?

hello.rb

class Routes::Hello < Bridgetown::Rack::Routes
  route do |r|
    # route: POST /hello/:name
    r.post "hello", String do |name|
      if r.turbo_stream?
        r.respond_with_turbo_stream # Needed if not using the turbo_stream helper in the view
        render("hello", locals: {name: name})
      else
        r.redirect "/hello/#{name}"
      end
    end
  end
end

hello.erb

<% turbo_stream.append "turbo-test" do %>
  <p>Appended</p>
<% end %>
[Server]   Exception raised: NoMethodError
[Server] undefined method `capture' for #<RodaApp:0x0000000106a63d38 @_request=#<RodaApp::RodaRequest POST /hello/links>, @_response=#<RodaApp::RodaResponse 500 {} []>, @_request_timer=319009.257657, @_out_buf=nil, @turbo_stream=#<Turbo::Streams::TagBuilder:0x0000000106a3cc88 @view_context=#<RodaApp:0x0000000106a63d38 ...>, @render_method=:render>>

      @view_context.capture(&block)
                   ^^^^^^^^
[Server]                  1: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-turbo-1.0.0/lib/turbo/streams/tag_builder.rb:114:in `render_template'
[Server]                  2: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-turbo-1.0.0/lib/turbo/streams/tag_builder.rb:94:in `action'
[Server]                  3: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-turbo-1.0.0/lib/turbo/streams/tag_builder.rb:78:in `append'
[Server]                  4: /Users/dcandland/projects/proofreader/website-bridgetown/views/hello.erb:10:in `__tilt_5300'
[Server]                  5: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-3.67.0/lib/roda/plugins/render.rb:408:in `block in compiled_method_lambda'
jaredcwhite commented 1 year ago

@candland Well, a couple of things. If you're using the render plugin for Roda, that's outside of Bridgetown's way of handling template rendering…Bridgetown's own ERB rendering solution supports capture.

Nonetheless, Roda has a plugin called capture_erb: http://roda.jeremyevans.net/rdoc/files/lib/roda/plugins/capture_erb_rb.html and we should definitely support that as well. I'll try to get to that shortly.

candland commented 1 year ago

@jaredcwhite Yea, I'm using the render plugin. Is there a better / recommended way with the SSR stuff?