From b6c4f3128d1db181893cfbae888f783e9b59502d Mon Sep 17 00:00:00 2001 From: Armando Fox Date: Wed, 6 Sep 2023 15:03:52 -0700 Subject: [PATCH] improve formatting of game views using bootstrap and layout file --- .../ch03-saas/sinatra-sessions/#app.rb# | 12 --- flipped-demos/ch03-saas/ttt/tic_tac_toe.rb | 3 +- flipped-demos/ch03-saas/ttt/views/game.erb | 76 ++++++------------- flipped-demos/ch03-saas/ttt/views/layout.erb | 12 +++ 4 files changed, 39 insertions(+), 64 deletions(-) delete mode 100644 flipped-demos/ch03-saas/sinatra-sessions/#app.rb# create mode 100644 flipped-demos/ch03-saas/ttt/views/layout.erb diff --git a/flipped-demos/ch03-saas/sinatra-sessions/#app.rb# b/flipped-demos/ch03-saas/sinatra-sessions/#app.rb# deleted file mode 100644 index c204d4d..0000000 --- a/flipped-demos/ch03-saas/sinatra-sessions/#app.rb# +++ /dev/null @@ -1,12 +0,0 @@ -require 'sinatra' -class DemoApp < Sinatra::Base - enable :sessions - get '/' do - @someone = session[:thing] - erb :hello - end - get '/set/:something' do - session[:thing] = params[:something] - redirect '/' - end -end diff --git a/flipped-demos/ch03-saas/ttt/tic_tac_toe.rb b/flipped-demos/ch03-saas/ttt/tic_tac_toe.rb index ffeb190..b8e82df 100644 --- a/flipped-demos/ch03-saas/ttt/tic_tac_toe.rb +++ b/flipped-demos/ch03-saas/ttt/tic_tac_toe.rb @@ -25,8 +25,9 @@ def move(player,square) end def board_full - # ! @board.any?(&:empty?) ! @board.any? { |square| square.empty? } + # or more concise: + # ! @board.any?(&:empty?) end def over? diff --git a/flipped-demos/ch03-saas/ttt/views/game.erb b/flipped-demos/ch03-saas/ttt/views/game.erb index 202a492..aa8be54 100644 --- a/flipped-demos/ch03-saas/ttt/views/game.erb +++ b/flipped-demos/ch03-saas/ttt/views/game.erb @@ -1,54 +1,28 @@ - - - - - - - - <% if session[:message] %> -
- <%= session[:message] %> +<% if session[:message] %> +
+ <%= session[:message] %> +
+<% end %> +
+ + <% row = col = 0 %> + <% 0.upto(2) do |row| %> +
+ <% 0.upto(2) do |col| %> +
+ <% square_num = row * 3 + col %> + <%= if (val = @game.board[square_num]).empty? then square_num else val end %>
<% end %> -
- - - - <% i = 0 %> - <% 3.times do %> - - <% 3.times do %> - - <% end %> - - <% end %> - -
- <% val = @game.board[i] %> - <% if val.empty? %> - <%= i %> - <% else %> - <%= val %> - <% end %> - <% i += 1 %> -
-
+
+ <% end %> +
-
-

<%= @game.turn %>'s move

-

Enter square 0-8

- - -
- - +
+

<%= @game.turn %>'s move

+

Enter square 0-8

+ + +
diff --git a/flipped-demos/ch03-saas/ttt/views/layout.erb b/flipped-demos/ch03-saas/ttt/views/layout.erb new file mode 100644 index 0000000..4d641d0 --- /dev/null +++ b/flipped-demos/ch03-saas/ttt/views/layout.erb @@ -0,0 +1,12 @@ + + + + + Tic Tac Toe + + +
+ <%= yield %> +
+ +