font_awesome_file_icons 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +27 -0
- data/lib/font_awesome_file_icons/railtie.rb +9 -0
- data/lib/font_awesome_file_icons/version.rb +3 -0
- data/lib/font_awesome_file_icons.rb +72 -0
- data/lib/tasks/font_awesome_file_icons_tasks.rake +4 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f236224f2cda5d3c6d245a892924260d1cadd68
|
4
|
+
data.tar.gz: d49ff95ba3f4382bd0a3eed3238728398e299670
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c49d10a8cc9be5fba6cc6023f0d149d5f5670d3a17ba1753310339b16d4e95f8e055a89c884b80dd00541f5e7d807030ba0d0217027676b294e2f57348a51ea
|
7
|
+
data.tar.gz: 7b64f6e2db691ad7a15adbf6699697ef22bb18e2e6039619a9606666efcb38bb3805f5c3b058e32661da690ae1ce18f27a736bbac71994a8ae13beace34a943d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Igor Kasyanchuk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Font Awesome file icons
|
2
|
+
|
3
|
+
Sometimes you need to output filename with an icon from font-awesome. And you need to take an extension of file and use some mapping.
|
4
|
+
|
5
|
+
This gem is doing this for you, so you can focus on more important things.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Gem is adding method-wrapper `fa_file_icon` which behaves very similar to `fa_icon` and can receive same arguments as `fa_icon`.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'font_awesome_file_icons'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
```bash
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Gem depends on `font-awesome-rails` and `mimemagic` gems.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
* Fork
|
28
|
+
* git clone
|
29
|
+
* cd test/dummy
|
30
|
+
* rails s
|
31
|
+
* open localhost:3000
|
32
|
+
* make fixes in lib folder, restart server
|
33
|
+
* push changes & send a PR
|
34
|
+
|
35
|
+
## License
|
36
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'FontAwesomeFileIcons'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'mimemagic'
|
2
|
+
require 'font-awesome-rails'
|
3
|
+
require "font_awesome_file_icons/railtie"
|
4
|
+
|
5
|
+
module FontAwesomeFileIcons
|
6
|
+
module Helpers
|
7
|
+
DEFAULT_ICON = 'file-o'
|
8
|
+
FILE_ICONS_MAPPING = {
|
9
|
+
/image/ => 'file-image-o',
|
10
|
+
/audio/ => 'file-audio-o',
|
11
|
+
/video/ => 'file-video-o',
|
12
|
+
'application/pdf' => 'file-pdf-o',
|
13
|
+
'application/msword' => 'file-word-o',
|
14
|
+
'application/vnd.ms-word' => 'file-word-o',
|
15
|
+
'application/vnd.oasis.opendocument.text' => 'file-word-o',
|
16
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml' => 'file-word-o',
|
17
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'file-word-o',
|
18
|
+
'application/vnd.ms-excel' => 'file-excel-o',
|
19
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml' => 'file-excel-o',
|
20
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.document' => 'file-excel-o',
|
21
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'file-excel-o',
|
22
|
+
'text/csv' => 'file-excel-o',
|
23
|
+
'application/vnd.oasis.opendocument.spreadsheet' => 'file-excel-o',
|
24
|
+
'application/vnd.ms-powerpoint' => 'file-powerpoint-o',
|
25
|
+
'application/vnd.openxmlformats-officedocument.presentationml' => 'file-powerpoint-o',
|
26
|
+
'application/vnd.openxmlformats-officedocument.presentationml.document' => 'file-powerpoint-o',
|
27
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'file-powerpoint-o',
|
28
|
+
'application/vnd.oasis.opendocument.presentation' => 'file-powerpoint-o',
|
29
|
+
'text/plain' => 'file-text-o',
|
30
|
+
'text/html' => 'file-code-o',
|
31
|
+
'application/json' => 'file-code-o',
|
32
|
+
'application/sql' => 'file-code-o',
|
33
|
+
'application/javascript' => 'file-code-o',
|
34
|
+
'text/css' => 'file-code-o',
|
35
|
+
'application/x-ruby' => 'file-code-o',
|
36
|
+
'text/x-python' => 'file-code-o',
|
37
|
+
'text/x-c++src' => 'file-code-o',
|
38
|
+
'text/x-java' => 'file-code-o',
|
39
|
+
'application/gzip' => 'file-archive-o',
|
40
|
+
'application/zip' => 'file-archive-o',
|
41
|
+
'application/x-tar' => 'file-archive-o',
|
42
|
+
'application/x-rar' => 'file-archive-o',
|
43
|
+
/compressed/ => 'file-archive-o',
|
44
|
+
nil => DEFAULT_ICON,
|
45
|
+
'' => DEFAULT_ICON
|
46
|
+
}.freeze
|
47
|
+
|
48
|
+
FILE_ICONS_MAPPING_REGEXP = FILE_ICONS_MAPPING.keys.select{|e| e.is_a?(Regexp)}.freeze
|
49
|
+
|
50
|
+
def fa_file_icon(filename, *options)
|
51
|
+
icon = get_icon(filename)
|
52
|
+
fa_icon(icon, *options)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def get_icon(filename)
|
58
|
+
extension = File.extname(filename.to_s)
|
59
|
+
mime_type = MimeMagic.by_extension(extension)&.type
|
60
|
+
icon = FILE_ICONS_MAPPING[mime_type]
|
61
|
+
|
62
|
+
if icon.nil?
|
63
|
+
key = FILE_ICONS_MAPPING_REGEXP.detect{|e| e =~ mime_type }
|
64
|
+
icon = FILE_ICONS_MAPPING[key] if key
|
65
|
+
end
|
66
|
+
|
67
|
+
#puts "#{extension} -> #{mime_type} -> #{icon}"
|
68
|
+
icon ||= DEFAULT_ICON
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: font_awesome_file_icons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Kasyanchuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mimemagic
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: font-awesome-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Return font awesome icon based on filename.
|
70
|
+
email:
|
71
|
+
- igorkasyanchuk@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/font_awesome_file_icons.rb
|
80
|
+
- lib/font_awesome_file_icons/railtie.rb
|
81
|
+
- lib/font_awesome_file_icons/version.rb
|
82
|
+
- lib/tasks/font_awesome_file_icons_tasks.rake
|
83
|
+
homepage: https://github.com/igorkasyanchuk/font_awesome_file_icons
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.6.8
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Return font awesome icon based on filename.
|
107
|
+
test_files: []
|