Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

トップ: 導線追加 #63

Merged
merged 3 commits into from
Jan 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/assets/stylesheets/home.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
}
}

#home > .matomes {
margin: 0 auto 50px;
text-align: center;

li {
@include inline-block;
}
}

#home > .tags {
margin: 0 auto 50px;
width: $contents_width;
text-align: center;

li {
display: inline;
margin: 0 10px;
}
}

// bookmarklet
#bookmarklet {
margin: 20px auto;
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class HomeController < ApplicationController

def index
@clips = Clip.paginate(page: params[:page]).includes([ { image: :likes, comments: :user }, :user, :likes, :tags ])
@hot_tags = Tag.hot(50).shuffle
@new_matomes = Matome.limit(5).all
render action: 'next_page' unless first_page?
end

Expand Down
7 changes: 7 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
module HomeHelper
def font_size_for_tag_cloud(tag, options={})
options[:base_font_size] = 9
options[:offset_ratio] = 0.5
options[:max_offset_size] = 50
offset_font_size = [tag.name_count * options[:offset_ratio], options[:max_offset_size]].min.floor
"font-size: #{options[:base_font_size] + offset_font_size}pt"
end
end
2 changes: 1 addition & 1 deletion app/models/matome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Matome < ActiveRecord::Base
where(user_id: matome.user_id).
where.not(id: matome.id)
}

scope :related_by_clips, lambda {|matome|
related_clip_ids = matome.clips.map(&:id) + matome.clips.map(&:parent_id)
joins(:clips).
where(Clip.arel_table[:id].in(related_clip_ids).or(Clip.arel_table[:parent_id].in(related_clip_ids))).
where.not('matomes.id' => matome.id).
group('matomes.id')
}
scope :hot, lambda {|limit| reorder('view_count desc').limit(limit) }

default_scope order: 'matomes.created_at DESC'

Expand Down
1 change: 1 addition & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Tag < ActiveRecord::Base
scope :uniques, group(:name)
scope :by, lambda {|user| where(user_id: user.is_a?(User) ? user.id : user) if user }
scope :for, lambda {|tagged| where(tagged_id: tagged.id, tagged_type: tagged.class.name) }
scope :hot, lambda {|limit| uniques.select("name, COUNT(name) AS name_count").reorder('name_count desc').limit(limit) }

validates :tagged_id, :presence => true
validates :user_id, :presence => true
Expand Down
12 changes: 11 additions & 1 deletion app/views/home/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#home
h2 新着クリップ
.matomes
h2 新着まとめ
== render partial: 'base/matomes', locals: { matomes: @new_matomes }

.tags
h2 人気タグ
ul
- @hot_tags.each do |tag|
li style="#{font_size_for_tag_cloud(tag)}"
= link_to "#{tag.name} (#{tag.name_count})", tag_path(tag.name)

h2 新着クリップ
- if @clips.present?
== render partial: '/base/clip_wall'
- else
Expand Down