Skip to content

Commit

Permalink
Merge branch 'main' into add-tests-and-kwargs-support-for-remaining-a…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
marcoroth authored Mar 3, 2023
2 parents 5c6ce8f + 2845086 commit 8ea1770
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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 = 0, **attributes)`
* `turbo_stream.push_state(url, title = "", state = {}, **attributes)`
* `turbo_stream.replace_state(url, title = "", state = {}, **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 @@ -183,6 +183,10 @@ def set_title(title = nil, **attributes)
end

# Browser History Actions

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

def history_go(delta = 0, **attributes)
custom_action :history_go, attributes: attributes.reverse_merge(delta: delta)
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

0 comments on commit 8ea1770

Please sign in to comment.