Skip to content

Commit 5862a02

Browse files
committed
Add image fetching logic
1 parent 9f3cb88 commit 5862a02

5 files changed

+23
-21
lines changed

lib/rails-file-icons.rb

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
require "rails_file_icons/version"
1+
require "rails-file-icons/engine"
22

3-
module RailsFileIcons
4-
require "rails_file_icons/engine"
3+
module Icon
54

6-
def self.icon_for_mime_type mime_type
7-
'file_extension_doc.png'
5+
KNOWN_EXTENSIONS = %w{
6+
3gp 7z ace ai aif aiff amr asf asx bat bin bmp bup cab cbr cda cdl cdr chm
7+
dat divx dll dmg doc dss dvf dwg eml eps exe fla flv gif gz hqx htm html
8+
ifo indd iso jar jpeg jpg lnk log m4a m4b m4p m4v mcd mdb mid mov mp2 mp4
9+
mpeg mpg msi mswmm ogg pdf png pps ps psd pst ptb pub qbb qbw qxd ram
10+
rar rm rmvb rtf sea ses sit sitx ss swf tgz thm tif tmp torrent ttf txt
11+
vcd vob wav wma wmv wps xls xpi zip
12+
}.inject({}) do |known_extensions, ext|
13+
known_extensions[ext] = "file_extension_#{ext}.png"
14+
known_extensions
15+
end
16+
17+
18+
19+
def self.for_filename filename
20+
for_ext File.extname(filename)
821
end
922

10-
def self.icon_for_file_extension file_extension
11-
'file_extension_ace.png'
23+
def self.for_ext file_extension
24+
ext = file_extension.start_with?('.') ? file_extension[1..-1] : file_extension
25+
KNOWN_EXTENSIONS[ext.downcase] || 'file_extension_unknown.png'
1226
end
13-
14-
end
27+
end

rails-file-icons.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- encoding: utf-8 -*-
22
lib = File.expand_path('../lib', __FILE__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require 'rails_file_icons/version'
4+
require 'rails-file-icons/version'
55

66
Gem::Specification.new do |gem|
77
gem.name = "rails-file-icons"

spec/rails_file_icons_spec.rb

-9
This file was deleted.

spec/spec_helper.rb

-2
This file was deleted.
Loading

0 commit comments

Comments
 (0)