Skip to content

Commit

Permalink
Added icons for non-image Assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Glen committed May 23, 2014
1 parent 683095c commit b9b8615
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 1 deletion.
Binary file added app/assets/images/smithy/icons/_blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/smithy/icons/_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/smithy/icons/doc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/smithy/icons/pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/smithy/icons/ppt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/smithy/icons/txt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/smithy/icons/xls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/smithy/icons/xlsx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions app/helpers/smithy/assets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,26 @@ def asset_image_tag(asset_id)
return unless asset
image_tag(asset.file.url(:host => "#{request.protocol}#{request.host_with_port}"), :alt => asset.name)
end

def file_type_icon(asset)
case asset.file_type
when :image
nil
when :pdf
'smithy/icons/pdf.png'
when :word
'smithy/icons/doc.png'
when :excel
'smithy/icons/xls.png'
when :powerpoint
'smithy/icons/ppt.png'
when :text
'smithy/icons/txt.png'
when :document
'smithy/icons/_page.png'
when :default
'smithy/icons/_blank.png'
end
end
end
end
22 changes: 22 additions & 0 deletions app/models/smithy/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ def file
dragonfly_attachments[:file].to_value
end

def file_type
ext = File.extname(file.name).sub(/^\./, '')
case ext
when 'jpg', 'jpeg', 'gif', 'png'
:image
when 'pdf'
:pdf
when 'doc', 'docx'
:word
when 'xls', 'xlsx'
:excel
when 'ppt', 'pps', 'pptx', 'ppsx'
:powerpoint
when 'txt'
:text
when 'rtf'
:document
else
:default
end
end

def to_liquid
{
'id' => self.id,
Expand Down
8 changes: 7 additions & 1 deletion app/views/smithy/assets/_asset.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<li>
<div class="thumbnail clearfix">
<%= link_to "<img src=\"#{asset.file.thumb("170x114#").url}\" width=\"170\" height=\"114\" alt=\"\">".html_safe, asset.file.url %>
<%= link_to asset.file.remote_url do %>
<% if asset.file_type == :image %>
<%= image_tag asset.file.thumb("170x114#").url, width: 170, height: 114, alt: '' %>
<% else %>
<div style="width:170px;height:78px;padding-top:36px;text-align:center;"><%= image_tag file_type_icon(asset), alt: '' %></div>
<% end %>
<% end %>
<p class="name"><strong><%= asset.name %></strong></p>
<div class="pull-right">
<%= link_to "Edit", [:edit, asset], :class => "btn btn-mini" %>
Expand Down

0 comments on commit b9b8615

Please sign in to comment.