Skip to content

Commit

Permalink
Add support for Live:View#to_s.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 12, 2024
1 parent 90f5ed7 commit 17abdf0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/live/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,11 @@ def to_html
end
end
end

# Convenience method for rendering the view as a string.
# @returns [String] The generated HTML.
def to_s
to_html.to_s
end
end
end
14 changes: 14 additions & 0 deletions test/live/view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'live/view'

describe Live::View do
let(:view) {subject.new('test-id')}

with "#to_s" do
it "can generate string representation" do
expect(view.to_s).to be == <<~HTML.chomp
<div id="test-id" class="live" data-class="Live::View">
</div>
HTML
end
end
end

0 comments on commit 17abdf0

Please sign in to comment.