diff --git a/spec/marten-turbo/turbo_stream_spec.cr b/spec/marten-turbo/turbo_stream_spec.cr
index ee83e8b..270084d 100644
--- a/spec/marten-turbo/turbo_stream_spec.cr
+++ b/spec/marten-turbo/turbo_stream_spec.cr
@@ -6,6 +6,16 @@ describe MartenTurbo::TurboStream do
stream = MartenTurbo::TurboStream.new
stream.to_s.should eq ""
end
+
+ it "accepts a block to initialize the stream" do
+ stream = MartenTurbo::TurboStream.new do |stream|
+ stream.append("messages", "
Message 1
")
+ end
+
+ stream.to_s.should contain ""
+ stream.to_s.should contain "Message 1
"
+ stream.to_s.should contain ""
+ end
end
describe "#append" do
diff --git a/src/marten_turbo/turbo_stream.cr b/src/marten_turbo/turbo_stream.cr
index 55f5c28..a27a7b4 100644
--- a/src/marten_turbo/turbo_stream.cr
+++ b/src/marten_turbo/turbo_stream.cr
@@ -8,6 +8,11 @@ module MartenTurbo
@streams = [] of String
end
+ def initialize
+ @streams = [] of String
+ yield self
+ end
+
# Creates a new TurboStream instance and adds a single action.
#
# ```