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

Implement history_back stream helper #27

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ import 'controllers'

### Browser History Actions

* `turbo_stream.history_back(**attributes)`
* `turbo_stream.history_go(delta, **attributes)`
* `turbo_stream.push_state(url, title = nil, state = nil, **attributes)`
* `turbo_stream.replace_state(url, title = nil, state = nil, **attributes)`
Expand Down
4 changes: 4 additions & 0 deletions lib/turbo_power/stream_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def set_title(title, **attributes)

# Browser History Actions

def history_back(**attributes)
custom_action :history_back, attributes: attributes
end

def history_go(delta, **attributes)
custom_action :history_go, attributes: attributes.merge(delta: delta)
end
Expand Down
15 changes: 15 additions & 0 deletions test/turbo_power/stream_helper/history_back_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "test_helper"

module TurboPower
module StreamHelper
class HistoryBackTest < StreamHelperTestCase
test "history_back" do
stream = %(<turbo-stream action="history_back"><template></template></turbo-stream>)

assert_dom_equal stream, turbo_stream.history_back
end
end
end
end