-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class HomeController < ApplicationController | ||
before_action :set_frame | ||
|
||
protected | ||
|
||
def set_frame | ||
@frame = request.headers['HTTP_TURBO_FRAME'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module HomeHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="tester" | ||
export default class extends Controller { | ||
static values = { | ||
frame: String | ||
}; | ||
|
||
connect() { | ||
console.log("Connected", this.element); | ||
} | ||
|
||
open(e) { | ||
e.preventDefault(); | ||
|
||
const a = e.currentTarget; | ||
if (!a.href) return; | ||
const frame = document.getElementById(this.frameValue); | ||
console.log("YOO HOO", frame, e.currentTarget); | ||
if (!frame) return; | ||
|
||
if (frame.src == a.href) { | ||
frame.reload(); | ||
} else { | ||
frame.src = a.href; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<h1>Hello there!</h1> | ||
|
||
<div class="frame"> | ||
<%= turbo_frame_tag 'testing' do %> | ||
<p>I am the index page. It's <%= Time.now %> now.</p> | ||
<% end %> | ||
</div> | ||
|
||
<div data-controller="tester" data-tester-frame-value="testing"> | ||
<ul> | ||
<li> | ||
Clicking the link below sets the <code>src</code> property of the | ||
Turbo Frame with ID <code>testing</code> to <code>"/other"</code>. | ||
</li> | ||
<li> | ||
This should make a request to <code>/other</code> with the | ||
header <code>Turbo-Frame: testing</code>. | ||
</li> | ||
<li> | ||
The other page contains a Turbo Frame, too. If the <code>Turbo-Frame</code> | ||
header is set, it will be used for its ID. Otherwise it's set to something | ||
irrelevant. | ||
</li> | ||
<li> | ||
So if the header was properly set for the request, we'll see the frame update, | ||
otherwise we'll get a <strong>Content missing</strong> message. | ||
</li> | ||
</ul> | ||
|
||
<p> | ||
<a href="/other" data-action="tester#open">Go load that frame</a> | ||
</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<h1>Other</h1> | ||
|
||
<div class="frame"> | ||
<%= turbo_frame_tag(@frame || 'something') do %> | ||
<p>I am the other page at <%= Time.now %>.</p> | ||
<p>Turbo Frame header was <code><%= @frame.inspect %></code></p> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class HomeControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |