<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: icons code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 02:27:41 GMT</pubDate>
    <description>DZone Snippets: icons code</description>
    <item>
      <title>File icon giver/getter/whatever</title>
      <link>http://snippets.dzone.com/posts/show/2560</link>
      <description>This code uses acts_as_attachment (that's the attachment.filename) but you can of course replace it with anything.&lt;br /&gt;It gets the file extension then looks up that extension in a dir full of files named extension.png&lt;br /&gt;if none is found, unknown.png is used&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%&lt;br /&gt;extension = File.extname(attachment.filename).gsub(/\./, "")&lt;br /&gt;# get a file icon&lt;br /&gt;icon_path = nil&lt;br /&gt;Dir.entries("#{RAILS_ROOT}/public/images/filetypes").each do |entry|&lt;br /&gt;	entry_extension = File.extname(entry)&lt;br /&gt;	if entry.gsub(entry_extension, "") === extension&lt;br /&gt;		icon_path = "/images/filetypes/" + entry&lt;br /&gt;		break&lt;br /&gt;	end&lt;br /&gt;end&lt;br /&gt;icon_path = "/images/filetypes/unknown.png" if icon_path.nil?&lt;br /&gt; %&gt;&lt;br /&gt;&lt;%= image_tag icon_path %&gt;&lt;br /&gt;&lt;span class="attachment_name"&gt;&lt;%= attachment.filename %&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 07 Sep 2006 19:32:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2560</guid>
      <author>aptiva (Fj&#195;&#182;lnir &#195;?sgeirsson)</author>
    </item>
  </channel>
</rss>
