icon_for 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 462ea8d6dc050153f96dcce76fc1c9eb83d7c7ba
4
- data.tar.gz: 0f6e5a2b376f97798e44dc3101d9f678bc8f058d
3
+ metadata.gz: e7bcb5635acd0e370dde93b68b176ef82d23bc3d
4
+ data.tar.gz: 70e8bad3195e7ada12c79c5d1f9611e3da5b97d0
5
5
  SHA512:
6
- metadata.gz: 527dd8bcc4d44e8cd3c3d907f1f92f5970d3996ae833be6940caf50eb6f969726b0bb0a7aca5610cd66dbd50a45cbb2f5267bafcd8ffe259defedd3e7945e148
7
- data.tar.gz: 1494c481de70c0b1cb2c492ab6d510f2599767095d103acb8e9423118096d4087a1deebdc0ee77d2199b288a76296b70e0dae083f80db19ec5498dd3a972077b
6
+ metadata.gz: c4085a5912761ef2eb756d63d218fdcadbf49fdbdc042ec899af97e434bce46bfe392ce1c22298520fe66d5e90877ac443684693e75ec3fbc2538e2381bc06e0
7
+ data.tar.gz: 09983f27cf9f554c4923c62d4febea2aeb67aace3974f61e79d0ecea2eecd78edaa2f073428839df0c9aaa7c9431d335e67a4a59e053ef627b6337697de6baa3
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at orgodemir.v@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Global Women's Institute
3
+ Copyright (c) 2017 phi2dao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -26,13 +26,13 @@ TODO: Write usage instructions here
26
26
 
27
27
  ## Development
28
28
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
30
 
31
31
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
32
 
33
33
  ## Contributing
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/icon_for.
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/icon_for. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
36
 
37
37
 
38
38
  ## License
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
2
6
  task :default => :spec
7
+
8
+ task :console do
9
+ exec "irb -r icon_for -I ./lib"
10
+ end
data/data/fa.json CHANGED
@@ -1,44 +1,61 @@
1
1
  {
2
- "media": {
3
- "application": "application",
4
- "audio": "audio",
5
- "image": "image",
6
- "text": "code",
7
- "video": "video"
8
- },
9
- "extensions": {
10
- "7z": "archive",
11
- "gz": "archive",
12
- "rar": "archive",
13
- "zip": "archive",
14
- "css": "code",
15
- "html": "code",
16
- "tex": "code",
17
- "xml": "code",
18
- "doc": "document",
19
- "docx": "document",
20
- "odt": "document",
21
- "rtf": "document",
22
- "pdf": "pdf",
23
- "odp": "slideshow",
24
- "ppt": "slideshow",
25
- "pptx": "slideshow",
26
- "csv": "spreadsheet",
27
- "odc": "spreadsheet",
28
- "xls": "spreadsheet",
29
- "xlsx": "spreadsheet",
30
- "txt": "text"
2
+ "types": {
3
+ "application/*": "application",
4
+ "application/msword": "document",
5
+ "application/gzip": "archive",
6
+ "application/pdf": "pdf",
7
+ "application/vnd.ms-excel": "spreadsheet",
8
+ "application/vnd.ms-excel.addin.macroEnabled.12": "spreadsheet",
9
+ "application/vnd.ms-excel.sheet.macroEnabled.12": "spreadsheet",
10
+ "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "spreadsheet",
11
+ "application/vnd.ms-excel.template.macroEnabled.12": "spreadsheet",
12
+ "application/vnd.ms-powerpoint": "presentation",
13
+ "application/vnd.ms-powerpoint.addin.macroEnabled.12": "presentation",
14
+ "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "presentation",
15
+ "application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "presentation",
16
+ "application/vnd.ms-powerpoint.template.macroEnabled.12": "presentation",
17
+ "application/vnd.ms-word.document.macroEnabled.12": "document",
18
+ "application/vnd.ms-word.template.macroEnabled.12": "document",
19
+ "application/vnd.oasis.opendocument.chart": "image",
20
+ "application/vnd.oasis.opendocument.formula": "code",
21
+ "application/vnd.oasis.opendocument.graphics": "image",
22
+ "application/vnd.oasis.opendocument.graphics-template": "image",
23
+ "application/vnd.oasis.opendocument.image": "image",
24
+ "application/vnd.oasis.opendocument.presentation": "presentation",
25
+ "application/vnd.oasis.opendocument.presentation-template": "presentation",
26
+ "application/vnd.oasis.opendocument.spreadsheet": "spreadsheet",
27
+ "application/vnd.oasis.opendocument.spreadsheet-template": "spreadsheet",
28
+ "application/vnd.oasis.opendocument.text": "document",
29
+ "application/vnd.oasis.opendocument.text-master": "document",
30
+ "application/vnd.oasis.opendocument.text-template": "document",
31
+ "application/vnd.oasis.opendocument.text-web": "document",
32
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": "presentation",
33
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow": "presentation",
34
+ "application/vnd.openxmlformats-officedocument.presentationml.template": "presentation",
35
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "spreadsheet",
36
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template": "spreadsheet",
37
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "document",
38
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "document",
39
+ "application/x-7z-compressed": "archive",
40
+ "application/x-rar-compressed": "archive",
41
+ "application/zip": "archive",
42
+ "audio/*": "audio",
43
+ "image/*": "image",
44
+ "text/*": "code",
45
+ "text/csv": "spreadsheet",
46
+ "text/plain": "text",
47
+ "video/*": "video"
31
48
  },
32
49
  "icons": {
33
50
  "application": "file-o",
34
51
  "audio": "file-audio-o",
35
52
  "archive": "file-archive-o",
36
53
  "code": "file-code-o",
37
- "document": "file-word-o",
54
+ "document": "file-document-o",
38
55
  "fallback": "file-o",
39
56
  "image": "file-image-o",
40
57
  "pdf": "file-pdf-o",
41
- "slideshow": "file-powerpoint-o",
58
+ "presentation": "file-powerpoint-p",
42
59
  "spreadsheet": "file-excel-o",
43
60
  "text": "file-text-o",
44
61
  "video": "file-video-o"
data/icon_for.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["phi2dao"]
10
10
  spec.email = ["orgodemir.v@gmail.com"]
11
11
 
12
- spec.summary = %q{Turns mime types into icon names. Automatically works with FontAwesome.}
12
+ spec.summary = %q{Translates mime types into icon strings for use with other libraries. Works with Font Awesome out of the box.}
13
13
  spec.homepage = "https://github.com/phi2dao/icon_for"
14
14
  spec.license = "MIT"
15
15
 
@@ -31,6 +31,5 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.14"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
-
35
- spec.add_dependency "mime-types", "~> 3.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
36
35
  end
@@ -0,0 +1,20 @@
1
+ module IconFor
2
+ def self.register const, data, options = {}
3
+ IconFor.const_set const, IconFor::IconSet.new(data)
4
+ @default = const if options[:default]
5
+ end
6
+
7
+ def self.[] mime
8
+ if @default
9
+ IconFor.const_get(@default)[mime]
10
+ end
11
+ end
12
+
13
+ def self.default
14
+ @default
15
+ end
16
+
17
+ def self.default= const
18
+ @default = const
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ require "json"
2
+
3
+ module IconFor
4
+ class IconSet
5
+ def initialize data
6
+ if data.is_a? File
7
+ @data = JSON.load data
8
+ else
9
+ @data = data
10
+ end
11
+ end
12
+
13
+ def [] mime
14
+ if @data["types"].key? mime
15
+ icon = @data["types"][mime]
16
+ else
17
+ mime.match /(\w*)\/.*/
18
+ if @data["types"].key? $1 + '/*'
19
+ icon = @data["types"][$1 + '/*']
20
+ else
21
+ icon = "fallback"
22
+ end
23
+ end
24
+ @data["icons"][icon]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module IconFor
2
+ PATH = File.expand_path('../../../data', __FILE__)
3
+ end
@@ -1,3 +1,3 @@
1
1
  module IconFor
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/icon_for.rb CHANGED
@@ -1,7 +1,10 @@
1
+ require "icon_for/engine"
2
+ require "icon_for/icon_set"
3
+ require "icon_for/path"
1
4
  require "icon_for/version"
2
- require "icon_for/core"
3
- require "icon_for/data"
4
5
 
5
6
  module IconFor
6
- # Your code goes here...
7
+ File.open IconFor::PATH + "/fa.json" do |file|
8
+ IconFor.register :FA, file, default: Kernel.const_defined?(:FontAwesome)
9
+ end
7
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icon_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - phi2dao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,13 +39,13 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mime-types
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
- type: :runtime
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -60,6 +60,9 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
63
66
  - Gemfile
64
67
  - LICENSE.txt
65
68
  - README.md
@@ -69,9 +72,9 @@ files:
69
72
  - data/fa.json
70
73
  - icon_for.gemspec
71
74
  - lib/icon_for.rb
72
- - lib/icon_for/core.rb
73
- - lib/icon_for/data.rb
74
- - lib/icon_for/fa.rb
75
+ - lib/icon_for/engine.rb
76
+ - lib/icon_for/icon_set.rb
77
+ - lib/icon_for/path.rb
75
78
  - lib/icon_for/version.rb
76
79
  homepage: https://github.com/phi2dao/icon_for
77
80
  licenses:
@@ -97,5 +100,6 @@ rubyforge_project:
97
100
  rubygems_version: 2.5.1
98
101
  signing_key:
99
102
  specification_version: 4
100
- summary: Turns mime types into icon names. Automatically works with FontAwesome.
103
+ summary: Translates mime types into icon strings for use with other libraries. Works
104
+ with Font Awesome out of the box.
101
105
  test_files: []
data/lib/icon_for/core.rb DELETED
@@ -1,39 +0,0 @@
1
- require "mime-types"
2
- require "json"
3
-
4
- module IconFor
5
- @config = Struct.new(:source, :data).new(:data, nil)
6
-
7
- if defined? FontAwesome
8
- @config.source = :fa
9
- end
10
-
11
- def self.config
12
- block_given? ? yield(@config) : @config
13
- end
14
-
15
- def self.[] mime_type
16
- case @config.source.downcase
17
- when :fa
18
- require "icon_for/fa"
19
- FA[mime_type]
20
- when :data
21
- self.icon_from_source mime_type, @config.data
22
- else
23
- raise "Unknown icon source `#{@config.source.downcase}'"
24
- end
25
- end
26
-
27
- def self.icon_from_source mime_type, data
28
- raise "Invalid data object" unless data&.key?('media') and data&.key?('extensions') and data&.key?('icons')
29
- return data['icons']['fallback'] unless mime = MIME::Types[mime_type].first
30
- if data['extensions'].key? mime.preferred_extension
31
- icon = data['extensions'][mime.preferred_extension]
32
- elsif data['media'].key? mime.media_type
33
- icon = data['media'][mime.media_type]
34
- else
35
- icon = 'fallback'
36
- end
37
- data['icons'][icon]
38
- end
39
- end
data/lib/icon_for/data.rb DELETED
@@ -1,5 +0,0 @@
1
- module IconFor
2
- module Data
3
- PATH = File.expand_path('../../../data', __FILE__)
4
- end
5
- end
data/lib/icon_for/fa.rb DELETED
@@ -1,11 +0,0 @@
1
- module IconFor
2
- module FA
3
- File.open IconFor::Data::PATH + '/fa.json' do |file|
4
- @data = JSON.load file
5
- end
6
-
7
- def self.[] mime_type
8
- IconFor.icon_from_source mime_type, @data
9
- end
10
- end
11
- end