Skip to content

Commit

Permalink
Add game page
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyhre committed May 21, 2017
1 parent 01485a0 commit 27f46e4
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'bugsnag'
gem 'countries'
gem 'httparty'
gem 'money-rails'
gem 'slim-rails'
# gem 'sass-rails', '~> 5.0'

group :development, :test do
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ GEM
redis (3.3.3)
ruby_dep (1.5.0)
sixarm_ruby_unaccent (1.1.1)
slim (3.0.8)
temple (>= 0.7.6, < 0.9)
tilt (>= 1.3.3, < 2.1)
slim-rails (3.1.2)
actionpack (>= 3.1)
railties (>= 3.1)
slim (~> 3.0)
slop (3.6.0)
spring (2.0.1)
activesupport (>= 4.2)
Expand All @@ -155,8 +162,10 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
temple (0.8.0)
thor (0.19.4)
thread_safe (0.3.6)
tilt (2.0.7)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unicode_utils (1.4.0)
Expand All @@ -180,6 +189,7 @@ DEPENDENCIES
puma (~> 3.7)
rails (~> 5.1.1)
redis (~> 3.2)
slim-rails
spring
spring-watcher-listen (~> 2.0.0)

Expand Down
6 changes: 6 additions & 0 deletions app/controllers/games_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class GamesController < ApplicationController
def index
@current_page = 'games'
@games = Game.by_game_code
end
end
2 changes: 0 additions & 2 deletions app/jobs/application_job.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/models/game.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Game < ApplicationRecord
REGIONS = %w(americas europe asia).freeze
REGIONS = %w(europe americas asia).freeze
GAME_CODE_FORMAT = /\A[0-9A-Z]{4}\z/.freeze
NSUID_CODE_FORMAT = /\A7001000000[0-9]{4}\z/.freeze

Expand Down Expand Up @@ -30,6 +30,6 @@ class Game < ApplicationRecord
order(order_by.join(' '))
}

scope :by_game_code, -> { order_by_title.order_by_region.group_by(&:game_code) }
scope :by_game_code, -> { order_by_title.group_by(&:game_code).each { |_,games| games.sort_by! { |game| REGIONS.index(game.region) } } }
scope :by_region, -> { order_by_title.order_by_region.group_by(&:region) }
end
23 changes: 23 additions & 0 deletions app/views/games/index.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
table.table.table-responsive
thead.thead-default
tr
th Cover
th Code
th Region
th Title
th eShop ID (nsuid)
th Release date
tbody.games
- @games.each do |region, games|
- cover = games.map(&:cover_url).compact.first
- games.each_with_index do |game, index|
tr.game
- if index.zero?
td.game--cover-url rowspan=games.count
= cover ? image_tag(cover, style: 'max-width:120px;max-height:120px;', class: 'rounded mx-auto d-block', title: 'wat') : nil
td.game--code rowspan=games.count = game.game_code
td.game--region = game.region
td.game--title.text-overflow = game.title
td.game--nsuid = game.nsuid || 'NA'
td.game--release-date
time.text-overflow datetime=game.release_date.iso8601 = game.release_date.strftime("%b #{game.release_date.day.ordinalize}, %Y")
14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

35 changes: 35 additions & 0 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
doctype 5
html
head
meta name="viewport" content="width=device-width,initial-scale=1"
title Nintendo Switch - Full game list with prices

link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"

script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"
script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"
script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"

css:
.text-overflow {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

body
nav.navbar.navbar-toggleable-sm.navbar-light.bg-faded.sticky-top style="width: 100%"
button.navbar-toggler.navbar-toggler-right type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"
span.navbar-toggler-icon
= link_to '#', class: 'navbar-brand' do
svg width="30" height="30" viewBox="0 0 253 325" xmlns="http://www.w3.org/2000/svg"
path d="M133.913 11.52c9.36-3.87 18.72-7.71 28.11-11.52-3.34 24.9-6.56 49.83-10.02 74.72-6.14-21.03-12.11-42.12-18.09-63.2zm63.97-8.92c8.99 4.63 17.99 9.23 26.89 14.02-17.26 22.09-34.21 44.42-51.6 66.41 8.09-26.85 16.53-53.6 24.71-80.43zm-7.83 96.01c18.36-17.2 36.83-34.29 55.26-51.41 2.27 9.9 4.69 19.78 6.83 29.71-20.74 7.12-41.33 14.65-62.09 21.7zM78.573 89c20.21-5.8 42.2-6.52 62.36-.08 17.76 5.55 33.58 16.35 46.39 29.72 12.83 13.52 22.89 29.56 30.03 46.74.87 2.03-.66 4.11-2.49 4.88-50.17 25.96-100.31 51.98-150.48 77.93 9.92 15.62 25.93 27.5 44.02 31.71 19.83 4.57 41.09-1.13 57.43-12.84 18.05-12.86 28.7-34.15 31.48-55.83.02-3 3.79-4.66 6.13-2.85 9.81 5.92 19.56 11.94 29.33 17.94 1.75.93 2.86 2.9 2.1 4.88-7.59 30.1-24.64 58.78-50.77 76.25-9.41 6.31-19.85 11.1-30.76 14.12-36.35 8.12-76.69-.3-105.3-24.61-15.06-12.65-26.94-28.8-35.67-46.35-3.59-6.75-5.74-14.12-7.77-21.44-6.44-24.08-6.52-50.29 2.3-73.79 11.66-31.72 38.93-57.53 71.67-66.38zm17.36 36.91c-19.29 4.32-36.85 16.71-46.2 34.28-8.59 15.75-11.85 35.75-3.82 52.39 37.48-20.14 74.88-40.43 112.34-60.62-4.59-7.85-10.93-14.74-18.71-19.5-12.84-8.07-28.97-10.05-43.61-6.55z" fill="#D8D8D8" fill-rule="evenodd"

#navbarSupportedContent.navbar-collapse.collapse
ul.navbar-nav.mr-auto
li.nav-item class=(@current_page == 'games' ? 'active' : nil)
= link_to 'Game list', '#', class: 'nav-link'
li.nav-item
= link_to 'All prices', '#', class: 'nav-link disabled'

= yield
13 changes: 0 additions & 13 deletions app/views/layouts/mailer.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/layouts/mailer.text.erb

This file was deleted.

2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
get :rates, to: 'application#rates'
get :glossary, to: 'application#glossary'
get :about, to: 'application#about'

resources :games, only: :index
end
4 changes: 2 additions & 2 deletions lib/eshop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.list
def self.list_europe
url = 'http://search.nintendo-europe.com/en/select'
default_params = {
fl: 'product_code_txt,title,date_from,nsuid_txt,image_url',
fl: 'product_code_txt,title,date_from,nsuid_txt,image_url_sq_s',
fq: 'type:GAME AND (system_type:"nintendoswitch_gamecard" OR system_type:"nintendoswitch_downloadsoftware" OR system_type:"nintendoswitch_digitaldistribution") AND product_code_txt:*',
q: '*',
rows: 9999,
Expand All @@ -62,7 +62,7 @@ def self.list_europe
title: game[:title],
release_date: Date.parse(game[:date_from]),
nsuid: game.dig(:nsuid_txt, 0),
cover_url: game[:image_url],
cover_url: game[:image_url_sq_s],
}
end
end
Expand Down

0 comments on commit 27f46e4

Please sign in to comment.