-
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.
Refactor game-state-view containers organization
This is a follow-up on my original restructuring (back in cf21337) after playing with it for a bit. I was having pain with using `show` pages as both a template and a "partial". e.g. having to do `<%# locals: (view: @view) %>` in the games/new.html.erb template was hard to reason about. Templates shouldn't have local variables, and especially not *sometimes*. This just adds to cognitive load. So now, we have a convention of using a "container" (partial + view model) instead.
- Loading branch information
Paul DobbinSchmaltz
committed
Nov 10, 2024
1 parent
9015ccc
commit 921051d
Showing
24 changed files
with
101 additions
and
90 deletions.
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,17 @@ | ||
<%# locals: (container:) %> | ||
<% content_for(:page_nav) do %> | ||
<%= render("games/current/page_nav", nav: container.nav) %> | ||
<% end %> | ||
<%= turbo_frame_tag(container.turbo_frame_name, class: "space-y-12") do %> | ||
<% container.content.tap do |content| %> | ||
<%= turbo_frame_tag(content.turbo_frame_name) do %> | ||
<%= render("games/current/content", content:) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="container mx-auto"> | ||
<%= render("games/current/footer", footer: container.footer(self)) %> | ||
</div> | ||
<% 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
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
<%# locals: (container:) %> | ||
<%= turbo_frame_tag(container.turbo_frame_name) do %> | ||
<div class="space-y-12"> | ||
<%= render("games/just_ended/content", content: container.content) %> | ||
|
||
<div class="container mx-auto"> | ||
<%= render( | ||
"games/just_ended/footer", | ||
footer: container.footer(user: current_user)) %> | ||
</div> | ||
</div> | ||
<% end %> |
12 changes: 6 additions & 6 deletions
12
app/views/games/just_ended/show.rb → app/views/games/just_ended/container.rb
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<% @view.show.tap do |show| %> | ||
<% @view.container.tap do |container| %> | ||
<%= turbo_stream.update( | ||
show.turbo_frame_name, | ||
template: "games/just_ended/show", | ||
locals: { view: show }) %> | ||
container.turbo_frame_name, | ||
partial: "games/just_ended/container", | ||
locals: { container: }) %> | ||
<% 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 |
---|---|---|
@@ -1,9 +1,3 @@ | ||
<%# locals: (view: @view) %> | ||
<% title("New Game") %> | ||
<% title("New Game") unless title %> | ||
|
||
<div class="container mx-auto md:mt-24 space-y-16"> | ||
<h1 class="text-center"><%= t("game.new_html").sample %></h1> | ||
|
||
<%= render("games/new/content", content: view.content) %> | ||
</div> | ||
<%= render("games/new/container", container: @view.container) %> |
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 @@ | ||
<%# locals: (container:) %> | ||
|
||
<div class="container mx-auto md:mt-24 space-y-16"> | ||
<h1 class="text-center"><%= t("game.new_html").sample %></h1> | ||
|
||
<%= render("games/new/content", content: container.content) %> | ||
</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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
# Games::New::Container represents the entire view context surrounding new | ||
# {Game}s, as a partial for reuse. | ||
class Games::New::Container | ||
def partial_path | ||
"games/new/container" | ||
end | ||
|
||
def content | ||
Games::New::Content.new | ||
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,13 @@ | ||
<%# locals: (container:) %> | ||
<%= turbo_frame_tag(container.turbo_frame_name) do %> | ||
<div class="space-y-12"> | ||
<% cache_unless(App.debug?, container.cache_key(context: layout)) do %> | ||
<%= render("games/past/content", content: container.content) %> | ||
<% end %> | ||
|
||
<div class="container mx-auto"> | ||
<%= render("games/past/footer", footer: container.footer) %> | ||
</div> | ||
</div> | ||
<% 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
5 changes: 3 additions & 2 deletions
5
app/views/games/past/show.rb → app/views/games/past/container.rb
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
This file was deleted.
Oops, something went wrong.
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
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
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