Skip to content

Commit

Permalink
[modify] Controller, Views最適化
Browse files Browse the repository at this point in the history
+ Configファイルを作成し、Controller・Viewsの冗長をなくす
+ テストフレームワークをMiniTestからRSpecに変更
+ Rakefileの中身もConfigを読み込むように変更
  • Loading branch information
kkarakawa committed Feb 17, 2016
1 parent 9df52f8 commit fa0b134
Show file tree
Hide file tree
Showing 20 changed files with 413 additions and 185 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
/tmp

# Ignore bundler
/Gemfile.lock
/vendor/*

# Ignore DB seeds
Expand Down
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--warnings
--require spec_helper
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ gem 'sdoc', '~> 0.4.0', group: :doc
gem 'anemone'

group :development, :test do
# Test flamework
gem 'rspec-rails', '~> 3.0.0'

# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'

Expand Down
199 changes: 199 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.3)
actionpack (= 4.2.3)
actionview (= 4.2.3)
activejob (= 4.2.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.3)
actionview (= 4.2.3)
activesupport (= 4.2.3)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.3)
activesupport (= 4.2.3)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.3)
activesupport (= 4.2.3)
globalid (>= 0.3.0)
activemodel (4.2.3)
activesupport (= 4.2.3)
builder (~> 3.1)
activerecord (4.2.3)
activemodel (= 4.2.3)
activesupport (= 4.2.3)
arel (~> 6.0)
activesupport (4.2.3)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
anemone (0.7.2)
nokogiri (>= 1.3.0)
robotex (>= 1.0.0)
arel (6.0.3)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
byebug (8.2.2)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.0)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.6.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
jbuilder (2.4.1)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (4.1.0)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
libv8 (3.16.14.13)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.99)
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
mysql2 (0.3.20)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.3)
actionmailer (= 4.2.3)
actionpack (= 4.2.3)
actionview (= 4.2.3)
activejob (= 4.2.3)
activemodel (= 4.2.3)
activerecord (= 4.2.3)
activesupport (= 4.2.3)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.3)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.3)
actionpack (= 4.2.3)
activesupport (= 4.2.3)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.5.0)
rdoc (4.2.2)
json (~> 1.4)
ref (2.0.0)
robotex (1.0.0)
rspec-core (3.0.4)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.4)
rspec-support (~> 3.0.0)
rspec-rails (3.0.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
sass (3.4.21)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
slim (3.0.6)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
slim-rails (3.0.1)
actionmailer (>= 3.1, < 5.0)
actionpack (>= 3.1, < 5.0)
activesupport (>= 3.1, < 5.0)
railties (>= 3.1, < 5.0)
slim (~> 3.0)
spring (1.6.3)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
temple (0.7.6)
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.2)
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)

PLATFORMS
ruby

DEPENDENCIES
anemone
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
mysql2 (~> 0.3.20)
rails (= 4.2.3)
rspec-rails (~> 3.0.0)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
slim-rails
spring
therubyracer
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.11.2
11 changes: 2 additions & 9 deletions app/controllers/ranking_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
class RankingController < ApplicationController

def history
@products = []
params[:cate] ||= "all"

video = Video.order(view: 'desc').limit(100)
video.where!(category: params[:cate]) unless params[:cate] == "all"

video.each do |v|
@products += [{img: v.image, date: v.created_at.strftime('%Y年%m月%d日 %H時%M分%S秒'), comment: v.comment.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,'), view: v.view.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,'), title: v.title, link: v.url}]
end

@video = Video.order(view: 'desc').limit(100)
@video.where!(category: params[:cate]) unless params[:cate] == "all"
end

end
130 changes: 15 additions & 115 deletions app/views/ranking/history.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,116 +4,16 @@ ul.nav.nav-tabs
li role="presentation" class="#{"active" if params[:cate] == "all"}"
a href="/ranking/history/all" 全て

li.dropdown role="presentation" class="#{"active" if ["g_ent2", "ent", "music", "sing", "play", "dance", "vocaloid", "nicoindies"].include?(params[:cate])}"
a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aria-expanded="false"
| エンタメ・音楽
span.caret
- YAML.load_file("#{Rails.root}/config/config.yml")[:nico_cate].each do |title, content|
li.dropdown role="presentation" class="#{"active" if content.values.include?(params[:cate])}"
a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aria-expanded="false"
| #{title}
span.caret

ul.dropdown-menu
li class="#{"active" if params[:cate] == "g_ent2"}"
a href="/ranking/history/g_ent2" 合算
li class="#{"active" if params[:cate] == "ent"}"
a href="/ranking/history/ent" エンターテイメント
li class="#{"active" if params[:cate] == "music"}"
a href="/ranking/history/music" 音楽
li class="#{"active" if params[:cate] == "sing"}"
a href="/ranking/history/sing" 歌ってみた
li class="#{"active" if params[:cate] == "play"}"
a href="/ranking/history/play" 演奏してみた
li class="#{"active" if params[:cate] == "dance"}"
a href="/ranking/history/dance" 踊ってみた
li class="#{"active" if params[:cate] == "vocaloid"}"
a href="/ranking/history/vocaloid" VOCALOID
li class="#{"active" if params[:cate] == "nicoindies"}"
a href="/ranking/history/nicoindies" ニコニコインディーズ

li.dropdown role="presentation" class="#{"active" if ["g_life2", "animal", "cooking", "nature", "travel", "sport", "lecture", "drive", "history"].include?(params[:cate])}"

a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aria-expanded="false"
| 生活・一般・スポ
span.caret

ul.dropdown-menu
li class="#{"active" if params[:cate] == "g_life2"}"
a href="/ranking/history/g_life2" 合算
li class="#{"active" if params[:cate] == "animal"}"
a href="/ranking/history/animal" 動物
li class="#{"active" if params[:cate] == "cooking"}"
a href="/ranking/history/cooking" 料理
li class="#{"active" if params[:cate] == "nature"}"
a href="/ranking/history/nature" 自然
li class="#{"active" if params[:cate] == "travel"}"
a href="/ranking/history/travel" 旅行
li class="#{"active" if params[:cate] == "sport"}"
a href="/ranking/history/sport" スポーツ
li class="#{"active" if params[:cate] == "lecture"}"
a href="/ranking/history/lecture" ニコニコ動画講座
li class="#{"active" if params[:cate] == "drive"}"
a href="/ranking/history/drive" 車載動画
li class="#{"active" if params[:cate] == "history"}"
a href="/ranking/history/history" 歴史

li.dropdown role="presentation" class="#{"active" if params[:cate] == "g_politics"}"
a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false"
| 政治
span.caret

ul.dropdown-menu
li class="#{"active" if params[:cate] == "g_politics"}"
a href="/ranking/history/g_politics" 合算

li.dropdown role="presentation" class="#{"active" if ["g_tech", "science", "tech", "handcraft", "make"].include?(params[:cate])}"
a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false"
| 科学・技術
span.caret

ul.dropdown-menu
li class="#{"active" if params[:cate] == "g_tech"}"
a href="/ranking/history/g_tech" 合算
li class="#{"active" if params[:cate] == "science"}"
a href="/ranking/history/science" 科学
li class="#{"active" if params[:cate] == "tech"}"
a href="/ranking/history/tech" ニコニコ技術部
li class="#{"active" if params[:cate] == "handcraft"}"
a href="/ranking/history/handcraft" ニコニコ手芸部
li class="#{"active" if params[:cate] == "make"}"
a href="/ranking/history/make" 作ってみた

li.dropdown role="presentation" class="#{"active" if ["g_culture2", "anime", "game", "toho", "imas", "radio", "draw"].include?(params[:cate])}"
a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false"
| アニメ・ゲーム・絵
span.caret

ul.dropdown-menu
li class="#{"active" if params[:cate] == "g_culture2"}"
a href="/ranking/history/g_culture2" 合算
li class="#{"active" if params[:cate] == "anime"}"
a href="/ranking/history/anime" アニメ
li class="#{"active" if params[:cate] == "game"}"
a href="/ranking/history/game" ゲーム
li class="#{"active" if params[:cate] == "toho"}"
a href="/ranking/history/toho" 東方
li class="#{"active" if params[:cate] == "imas"}"
a href="/ranking/history/imas" アイドルマスター
li class="#{"active" if params[:cate] == "radio"}"
a href="/ranking/history/radio" ラジオ
li class="#{"active" if params[:cate] == "draw"}"
a href="/ranking/history/draw" 描いてみた

li.dropdown role="presentation" class="#{"active" if ["g_other", "are", "diary", "other"].include?(params[:cate])}"
a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false"
| その他
span.caret

ul.dropdown-menu
li class="#{"active" if params[:cate] == "g_other"}"
a href="/ranking/history/g_other" 合算
li class="#{"active" if params[:cate] == "are"}"
a href="/ranking/history/are" 例のアレ
li class="#{"active" if params[:cate] == "diary"}"
a href="/ranking/history/diary" 日記
li class="#{"active" if params[:cate] == "other"}"
a href="/ranking/history/other" その他
ul.dropdown-menu
- content.each do |name, url|
li class="#{"active" if params[:cate] == url}"
a href="/ranking/history/#{url}" #{name}

table.table.table-hover
thead
Expand All @@ -124,8 +24,8 @@ ul.nav.nav-tabs
th 再生数

tbody
- @products.each.with_index(1) do |item, idx|
tr onclick="window.open('http://www.nicovideo.jp#{item[:link]}', '_blank');" style="cursor: pointer;"
- @video.each.with_index(1) do |item, idx|
tr onclick="window.open('#{YAML.load_file("#{Rails.root}/config/config.yml")[:nico_url]}#{item[:url]}', '_blank');" style="cursor: pointer;"
- if idx < 4
td
h1
Expand All @@ -143,12 +43,12 @@ ul.nav.nav-tabs
h4
span.label.label-default #{idx}
td
img src="#{item[:img]}" width="160"
img src="#{item[:image]}" width="160"
td
span.text-info #{item[:title]}
br
= item[:date]
= item[:created_at].strftime('%Y年%m月%d日 %H時%M分%S秒')
td
= item[:comment]
= item[:comment].to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,')
td
= item[:view]
= item[:view].to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,')
Loading

0 comments on commit fa0b134

Please sign in to comment.