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

Commit

Permalink
クリップ詳細: 画像が表示できない場合のデザイン崩れを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Nov 28, 2013
1 parent 49f4eaa commit 5a58d5c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def avatar_url(user, options={})
end

def image_tag_by_clip(clip, options={})
style = clip.thumb_size_for_style_sheet(options)
style = clip.size_for_stylesheet(options)
image_tag image_path(clip.image.thumb_url), alt: clip.title, style: style
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/clip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def url
self.image.try(:url) || @url
end

delegate :thumb_size_for_style_sheet, to: :image
delegate :size_for_stylesheet, to: :image

def create_html_only_images
images = [ @url ] if @url
Expand Down
7 changes: 4 additions & 3 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def thumb_height(crop_size=nil)
end
end

def thumb_size_for_style_sheet(options={})
return "width: #{self.thumb_width}px;" if self.thumb_height.zero? # for 下位互換
def size_for_stylesheet(options={})
case options[:mode]
when :crop
crop_size = options[:size]
Expand All @@ -66,8 +65,10 @@ def thumb_size_for_style_sheet(options={})
width_offset = width - crop_size
height_offset = height - crop_size
"width: #{width}px; height: #{height}px; margin-left: -#{width_offset / 2}px; margin-top: -#{height_offset / 2}px;"
else
when :thumbnail
"width: #{self.thumb_width}px; height: #{self.thumb_height}px;"
else
"width: #{self.width}px; height: #{self.height}px;"
end
end
end
2 changes: 1 addition & 1 deletion app/views/base/_wall.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- @clips.each do |clip|
li.box id="clip_#{clip.id}"
.image_box
= link_to image_tag_by_clip(clip), clip, remote: true
= link_to image_tag_by_clip(clip, mode: :thumbnail), clip, remote: true
.status
p.tag
- if clip.tags.any?
Expand Down
2 changes: 1 addition & 1 deletion app/views/clips/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

.info id="clip_#{@clip.id}"
.image_box
= link_to image_tag(image_path(@clip.image)), @clip.url
= link_to image_tag_by_clip(@clip), @clip.url

- if @clip.title.present?
h2.title = @clip.title
Expand Down

0 comments on commit 5a58d5c

Please sign in to comment.