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

Make TurboStream a Marten::HTTP::Response #7

Open
treagod opened this issue Aug 28, 2024 · 0 comments
Open

Make TurboStream a Marten::HTTP::Response #7

treagod opened this issue Aug 28, 2024 · 0 comments
Assignees

Comments

@treagod
Copy link
Owner

treagod commented Aug 28, 2024

Description

In order to directly use a Turbo Stream as response instead using it in #respond it could be interesting to have MartenTurbo::TurboStream as as Marten::HTTP::Response.

Example:

class ArticleHandler < Marten::Handlers::Schema
  schema ArticleHandler
  template_name "article_form.html"
  success_route_name "articles"

  after_successful_schema_validation :turbo

  private def turbo : Nil
    return turbo_stream if request.turbo?
  end

  private def turbo_stream
    # Creating it here for demonstrating purpose
    article = Article.new(schema.validated_data)
    article.save!

    MartenTurbo::TurboStream.new do |stream|
      stream.append("articles", "<div>Article #{article.pk}</div>")
    end
  end
end
@treagod treagod self-assigned this Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant