mime-types 1.25.1 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +5 -0
  5. data/.minitest.rb +2 -0
  6. data/.travis.yml +0 -4
  7. data/Contributing.rdoc +13 -14
  8. data/Gemfile +1 -0
  9. data/History.rdoc +100 -7
  10. data/Licence.rdoc +1 -1
  11. data/Manifest.txt +17 -24
  12. data/README.rdoc +26 -47
  13. data/Rakefile +42 -185
  14. data/data/mime-types.json +1 -0
  15. data/docs/COPYING.txt +339 -339
  16. data/docs/artistic.txt +127 -127
  17. data/lib/mime.rb +50 -0
  18. data/lib/mime/type.rb +634 -0
  19. data/lib/mime/types.rb +254 -912
  20. data/lib/mime/types/cache.rb +73 -0
  21. data/lib/mime/types/loader.rb +248 -0
  22. data/lib/mime/types/loader_path.rb +16 -0
  23. data/support/benchmarker.rb +55 -0
  24. data/support/convert.rb +130 -0
  25. data/support/iana_downloader.rb +201 -0
  26. data/test/fixture/json.json +1 -0
  27. data/test/fixture/old-data +9 -0
  28. data/test/fixture/yaml.yaml +75 -0
  29. data/test/minitest_helper.rb +22 -0
  30. data/test/test_mime_type.rb +337 -143
  31. data/test/test_mime_types.rb +75 -84
  32. data/test/test_mime_types_cache.rb +30 -29
  33. data/test/test_mime_types_class.rb +135 -0
  34. data/test/test_mime_types_lazy.rb +3 -2
  35. data/test/test_mime_types_loader.rb +42 -0
  36. metadata +61 -90
  37. metadata.gz.sig +0 -0
  38. data/lib/mime/types/application +0 -1010
  39. data/lib/mime/types/application.mac +0 -3
  40. data/lib/mime/types/application.nonstandard +0 -132
  41. data/lib/mime/types/application.obsolete +0 -41
  42. data/lib/mime/types/audio +0 -138
  43. data/lib/mime/types/audio.nonstandard +0 -11
  44. data/lib/mime/types/audio.obsolete +0 -1
  45. data/lib/mime/types/image +0 -46
  46. data/lib/mime/types/image.nonstandard +0 -20
  47. data/lib/mime/types/image.obsolete +0 -5
  48. data/lib/mime/types/message +0 -18
  49. data/lib/mime/types/message.obsolete +0 -2
  50. data/lib/mime/types/model +0 -15
  51. data/lib/mime/types/multipart +0 -14
  52. data/lib/mime/types/multipart.nonstandard +0 -1
  53. data/lib/mime/types/multipart.obsolete +0 -7
  54. data/lib/mime/types/other.nonstandard +0 -8
  55. data/lib/mime/types/text +0 -61
  56. data/lib/mime/types/text.nonstandard +0 -7
  57. data/lib/mime/types/text.obsolete +0 -8
  58. data/lib/mime/types/text.vms +0 -1
  59. data/lib/mime/types/video +0 -75
  60. data/lib/mime/types/video.nonstandard +0 -16
  61. data/lib/mime/types/video.obsolete +0 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDkxYjM0NzgyN2YxNTIxMTNiZjc3NThkMjEzZjViNzAyMmE2NjYyYg==
4
+ N2MyNjFiODUzNTEwYmVhMGFkOWQwZmEyMzYyMmMzNWEzMmVlYzM1YQ==
5
5
  data.tar.gz: !binary |-
6
- MzZiYzc4YTQ2NmQ5MjE5MGJiYTQxOTlmMGE3M2Q3MWUzZWI3N2E3MQ==
6
+ MmRjNzA1NGFiY2FhNzlmZTkyNGVlNzYwNzViODYxMmY3OGYxNzJhYQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Zjk0NGFhYTBjMzNmN2YxOTYwZWU0NzM2MmJlZTQ0ZjE4NzU1YTk5MDVkNTQ5
10
- Y2Y5MDk5MjA4YmI3ZTc1MWY1NDljZGJlYTg3NGU5NzcwY2I5MzRhMDc0Mzkw
11
- NTNiYjI4NDMxNTU0NzhjZjFmYjFhNGE4ZDJhNjUzYTdkNjVjYzc=
9
+ Y2FjMDNlNTI3MThiZTJhN2JlZTUxN2FiY2MyZWRjNDcxNDg2ZWNjYjgxNjA5
10
+ OTczMGNlNDZhZDJlZWY2Zjk4NmZmZDVjMjIxOGRmN2Y5MTdjNDVlMTQ0NThm
11
+ ZTg0N2JkNzc1MmVmNzU3ZWEyNDQ0NWVlN2ZkOGQ1ZGEyMWVjYTg=
12
12
  data.tar.gz: !binary |-
13
- Zjk4MzQyODgwODQyOWZiN2ZhYWE0YWJmNmY1MjIwNTAxM2ZiYjQ0OGMwOGNj
14
- ODAyYmUzZjQ5NmVkMzk0MzJmZmZhZmRiMzBiNzllMWQ5ZDA2OTA0ZjQxMTIw
15
- MjI4Njg0YmQ4YmUwNDgxZDg4OGRhMzQ2NDMzOTM5OTdlMjRhMzc=
13
+ MTc4ZDNlYTc5MGU2OWZhZDQ4YmI0NDhlMzk5ZTM0OTk2Y2VkODYzZTQ1ZTJl
14
+ Nzk1YjgzZDYzOTM3Mjc3YWE0ZGUwZTFmZGFlNzY1ZGI2OTdiMjNlNDg1MmFj
15
+ ZDEwMjkzZTYwMjNlOWJhNWYyYzcyYzgxOGFkYWU4ZWZlMzA2Mzg=
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,5 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.testlib = ".minitest"
5
+ end
@@ -0,0 +1,2 @@
1
+ gem "minitest"
2
+ require "minitest/autorun"
@@ -11,12 +11,8 @@ rvm:
11
11
  - 2.0.0
12
12
  - 1.9.3
13
13
  - 1.9.2
14
- - 1.8.7
15
14
  - jruby-19mode
16
- - jruby-18mode
17
15
  - rbx-19mode
18
- - rbx-18mode
19
- - ree
20
16
  # - ruby-head
21
17
  # - jruby-head
22
18
  matrix:
@@ -1,13 +1,12 @@
1
1
  == Contributing
2
2
 
3
- I value any contribution to MIME::Types you can provide: a bug report, a feature
3
+ I value any contribution to mime-types you can provide: a bug report, a feature
4
4
  request, or code contributions.
5
5
 
6
- Code contributions to MIME::Types are especially <del>welcome</del>encouraged.
7
- Because MIME::Types is a complex codebase, there are a few guidelines:
6
+ As mime-types is a complex codebase, there are a few guidelines:
8
7
 
9
- * Changes (aside from new MIME types) <strong>will not</strong> be accepted
10
- without tests. The test suite is written with MiniTest.
8
+ * Changes (aside from new MIME types) *will* *not* be accepted
9
+ without tests. The test suite is written with Minitest.
11
10
  * Match my coding style.
12
11
  * Use a thoughtfully-named topic branch that contains your change. Rebase your
13
12
  commits into logical chunks as necessary.
@@ -15,16 +14,16 @@ Because MIME::Types is a complex codebase, there are a few guidelines:
15
14
  * Do not change the version number; when your patch is accepted and a release
16
15
  is made, the version will be updated at that point.
17
16
  * Submit a GitHub pull request with your changes.
18
- * New features require new documentation.
17
+ * New behaviours require new or updated documentation.
19
18
 
20
19
  === Test Dependencies
21
20
 
22
21
  To run the test suite, you will need to install the development dependencies
23
- for MIME::Types. If you have Bundler, you can accomplish this easily:
22
+ for mime-types. If you have Bundler, you can accomplish this easily:
24
23
 
25
24
  $ bundle install
26
25
 
27
- MIME::Types uses Ryan Davis’s excellent {Hoe}[https://github.com/seattlerb/hoe]
26
+ mime-types uses Ryan Davis’s excellent {Hoe}[https://github.com/seattlerb/hoe]
28
27
  to manage the release process, and it adds a number of rake tasks. You will
29
28
  mostly be interested in:
30
29
 
@@ -42,20 +41,20 @@ will do.
42
41
  Here's the most direct way to get your work merged into the project:
43
42
 
44
43
  * Fork the project.
45
- * Clone down your fork (+git clone git://github.com/<username>/mime-types.git+).
46
- * Create a topic branch to contain your change (+git checkout -b my\_awesome\_feature+).
44
+ * Clone down your fork (<tt>git clone git://github.com/<username>/mime-types.git</tt>).
45
+ * Create a topic branch to contain your change (<tt>git checkout -b my\_awesome\_feature</tt>).
47
46
  * Hack away, add tests. Not necessarily in that order.
48
- * Make sure everything still passes by running `rake`.
47
+ * Make sure everything still passes by running +rake+.
49
48
  * If necessary, rebase your commits into logical chunks, without errors.
50
- * Push the branch up (+git push origin my\_awesome\_feature+).
49
+ * Push the branch up (<tt>git push origin my\_awesome\_feature</tt>).
51
50
  * Create a pull request against halostatue/mime-types and describe what your
52
51
  change does and the why you think it should be merged.
53
52
 
54
53
  === Contributors
55
54
 
56
- * Austin Ziegler created MIME::Types.
55
+ * Austin Ziegler created mime-types.
57
56
 
58
- Thanks to everyone else who has contributed to MIME::Types:
57
+ Thanks to everyone else who has contributed to mime-types:
59
58
 
60
59
  * Andre Pankratz
61
60
  * Mauricio Linhares
data/Gemfile CHANGED
@@ -15,6 +15,7 @@ gem "hoe-git", "~>1.5", :group => [:development, :test]
15
15
  gem "hoe-rubygems", "~>1.0", :group => [:development, :test]
16
16
  gem "hoe-travis", "~>1.2", :group => [:development, :test]
17
17
  gem "rake", "~>10.0", :group => [:development, :test]
18
+ gem "simplecov", "~>0.7", :group => [:development, :test]
18
19
  gem "hoe", "~>3.7", :group => [:development, :test]
19
20
 
20
21
  # vim: syntax=ruby
@@ -1,9 +1,102 @@
1
- == 1.25.1 / 201-11-24
1
+ == 2.0 / 2013-10-DD
2
2
 
3
- * Bugs:
4
- * Fix an issue with priority comparison in the 1.x release series. Found by
5
- sdbondi. This issue does not exist in the 2.x release series.
6
- https://github.com/halostatue/mime-types/issues/47
3
+ * API Changes (General):
4
+ * mime-types is no longer compatible with Ruby 1.8. Additionally, for its
5
+ YAML operations (normally development and test), it requires a YAML parser
6
+ that conforms to the Psych parser, not the Syck parser. This would only be
7
+ a problem with an alternative Ruby 1.9.2 interpreter that does not
8
+ implement the Psych parser conventions by requiring +psych+.
9
+ * MIME::InvalidContentType has been renamed to
10
+ MIME::Type::InvalidContentType.
11
+ * API Changes (MIME::Type):
12
+ * Construction of a MIME::Type can be with any of the following objects:
13
+ * An array containing a valid content type identifier and an optional array
14
+ of extensions. This allows MIME::Type.new to be used instead of
15
+ MIME::Type.from_array for the most common use-case. Fixes #43.
16
+ https://github.com/halostatue/mime-types/pull/43
17
+ * A Hash containing the output of MIME::Type#to_h, as would be deserialized
18
+ from the JSON representation of a MIME::Type. This replaces
19
+ MIME::Type.from_hash using a different parameter set.
20
+ * Another MIME::Type.
21
+ * A content type identifier string.
22
+ * Assignment of an invalid encoding to MIME::Type#encoding= will raise a
23
+ MIME::Type::InvalidEncoding exception rather than a plain ArgumentError.
24
+ * MIME::Type#url has been renamed to MIME::Type#references.
25
+ * MIME::Type#use_instead is now tracked as its own attribute, not as part of
26
+ MIME::Type#docs.
27
+ * MIME::Type#system, MIME::Type#system?, MIME::Type#platform?,
28
+ MIME::Type#to_a, MIME::Type#to_hash, MIME::Type.from_array,
29
+ MIME::Type.from_hash, and MIME::Type.from_mime_type have been deprecated
30
+ for removal.
31
+ * Implemented YAML object encoding and decoding methods,
32
+ MIME::Type#encode_with and MIME::Type#init_with.
33
+ * Implemented JSON hash encoding methods.
34
+ * Added MIME::Type#add_extensions to easily add extensions to a MIME::Type.
35
+ Fixes #44. https://github.com/halostatue/mime-types/pull/44
36
+ * API Changes (MIME::Types):
37
+ * MIME type caching has been extracted to its own class. It is structurally
38
+ similar to what was introduced with mime-types 1.25, but is no longer
39
+ considered an experimental interface.
40
+ * MIME type loading has been extracted to its own class. Loading has changed
41
+ substantially.
42
+ * MIME::Types#[] accepts a new filter flag, :registered. The :platform flag
43
+ has been deprecated.
44
+ * The MIME::Types#type_for platform parameter has been deprecated.
45
+ * Added the ability for MIME::Types#type_for produce results for multiple
46
+ filenames or extensions by providing an array as the first parameter. Fixes
47
+ #42. https://github.com/halostatue/mime-types/pull/42
48
+ * MIME::Types#add_type_variant and MIME::Types#index_extensions have been
49
+ deprecated as public methods. They will be private in a future version.
50
+ * MIME::Types#defined_types, MIME::Types.cache_file,
51
+ MIME::Types.add_type_variant, and MIME::Types.index_extensions have been
52
+ deprecated for removal.
53
+ * Default Registry Changes:
54
+ * The default registry is now a file in the directory data/, located via
55
+ MIME::Types::Loader::PATH. +PATH+ is defined in the file
56
+ lib/mime/types/path.rb so that system packagers only have to modify one
57
+ file in order to put the registry in a location that is not where a gem
58
+ version of mime-types would expect it. This resolves issue #36, reported by
59
+ postmodern. https://github.com/halostatue/mime-types/pull/36
60
+ * The default registry is now a single file in JSON format. This resolves
61
+ issue #28 reported by jasonlor (an error with mime-types in MacRuby).
62
+ https://github.com/halostatue/mime-types/pull/28
63
+ * The default registry is compiled from YAML files in type-lists/, resolving
64
+ issue #37 reported by postmodern requesting an easier-to-edit format.
65
+ https://github.com/halostatue/mime-types/pull/37
66
+ * New or Updated MIME Types:
67
+ * Major updates to the registered MIME type list from IANA using the improved
68
+ developer tools.
69
+ * Added:
70
+ * application/xhtml\+xml (HTML5)
71
+ * multipart/x-mixed-replace (HTML5)
72
+ * application/vnd.apple.pkpass (Apple PassBook) with extension pkpass.
73
+ * Modified:
74
+ * application/gzip (RFC6713) added extension (gz) and encoding.
75
+ * application/epub\+zip is not a registered MIME type.
76
+ * application/rss\+xml is not a registered MIME type.
77
+ * application/x-director reported incorrect extensions.
78
+ * application/x-gzip marked as obsolete (use application/gzip instead).
79
+ * application/x-maker marked as obsolete (use application/vnd.framemaker
80
+ instead).
81
+ * image/webp is not a registered MIME type; added a URL to Google's
82
+ proposed standard document.
83
+ * text/html added URL to the HTML5 specification.
84
+ * text/cache-manifest added URL to the HTML5 specification.
85
+ * text/plain (VMS .doc files) marked as non-standard. This type will be
86
+ merged with the standard text/plain type in a future release.
87
+ * Added md, markdown, rst, and textile extensions to text/plain.
88
+ * MIME Type Development Tools
89
+ * The benchmarking task has been moved mostly to support/benchmarker.rb.
90
+ * A task for SimpleCov coverage has been added (<tt>rake test:coverage</tt>).
91
+ * IANA type registry downloading has been substantially improved and the
92
+ implementation no longer resides in the Rakefile; it has instead been moved
93
+ to support/iana_downloader.rb. This takes advantage of the new YAML
94
+ encoding functionality to update added or modified MIME types
95
+ non-destructively in <tt>type-lists/</tt> by default.
96
+ * Rake tasks <tt>convert:yaml:json</tt> and <tt>convert:json:yaml</tt>
97
+ provide functionality to convert the human-editable YAML format in
98
+ <tt>type-lists/</tt> to the JSON format in <tt>data/</tt> and vice-versa.
99
+ This is powered by support/convert.rb.
7
100
 
8
101
  == 1.25 / 2013-08-30
9
102
 
@@ -17,7 +110,7 @@
17
110
  * New extensions:
18
111
  * mjpeg (video/x-motion-jpeg) based on a change by punkrats, found in the
19
112
  vidibus fork.
20
- * Modernized MiniTest configuration.
113
+ * Modernized Minitest configuration.
21
114
 
22
115
  == 1.24 / 2013-08-14
23
116
 
@@ -144,7 +237,7 @@
144
237
  * New MIME Types:
145
238
  * Types reported in https://github.com/halostatue/mime-types/issues/6:
146
239
  * CoffeeScript (text/x-coffeescript; .coffee; 8bit).
147
- * AIR (application/vnd.adobe.air-applicationinstaller-package+zip, .air; base64).
240
+ * AIR (application/vnd.adobe.air-applicationinstaller-package\+zip, .air; base64).
148
241
  * WOFF (application/font-woff; .woff; base64).
149
242
  * TrueType (application/x-font-truetype; .ttf; base64).
150
243
  * OpenType (application/x-font-opentype; .otf; base64).
@@ -13,7 +13,7 @@ licensing terms.
13
13
 
14
14
  === MIT License
15
15
 
16
- this software and associated documentation files (the "Software"), to deal in
16
+ This software and associated documentation files (the "Software"), to deal in
17
17
  the Software without restriction, including without limitation the rights to
18
18
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
19
19
  of the Software, and to permit persons to whom the Software is furnished to do
@@ -1,5 +1,7 @@
1
+ .autotest
1
2
  .gemtest
2
3
  .hoerc
4
+ .minitest.rb
3
5
  .travis.yml
4
6
  Contributing.rdoc
5
7
  Gemfile
@@ -8,35 +10,26 @@ Licence.rdoc
8
10
  Manifest.txt
9
11
  README.rdoc
10
12
  Rakefile
13
+ data/mime-types.json
11
14
  docs/COPYING.txt
12
15
  docs/artistic.txt
13
16
  lib/mime-types.rb
17
+ lib/mime.rb
18
+ lib/mime/type.rb
14
19
  lib/mime/types.rb
15
- lib/mime/types/application
16
- lib/mime/types/application.mac
17
- lib/mime/types/application.nonstandard
18
- lib/mime/types/application.obsolete
19
- lib/mime/types/audio
20
- lib/mime/types/audio.nonstandard
21
- lib/mime/types/audio.obsolete
22
- lib/mime/types/image
23
- lib/mime/types/image.nonstandard
24
- lib/mime/types/image.obsolete
25
- lib/mime/types/message
26
- lib/mime/types/message.obsolete
27
- lib/mime/types/model
28
- lib/mime/types/multipart
29
- lib/mime/types/multipart.nonstandard
30
- lib/mime/types/multipart.obsolete
31
- lib/mime/types/other.nonstandard
32
- lib/mime/types/text
33
- lib/mime/types/text.nonstandard
34
- lib/mime/types/text.obsolete
35
- lib/mime/types/text.vms
36
- lib/mime/types/video
37
- lib/mime/types/video.nonstandard
38
- lib/mime/types/video.obsolete
20
+ lib/mime/types/cache.rb
21
+ lib/mime/types/loader.rb
22
+ lib/mime/types/loader_path.rb
23
+ support/benchmarker.rb
24
+ support/convert.rb
25
+ support/iana_downloader.rb
26
+ test/fixture/json.json
27
+ test/fixture/old-data
28
+ test/fixture/yaml.yaml
29
+ test/minitest_helper.rb
39
30
  test/test_mime_type.rb
40
31
  test/test_mime_types.rb
41
32
  test/test_mime_types_cache.rb
33
+ test/test_mime_types_class.rb
42
34
  test/test_mime_types_lazy.rb
35
+ test/test_mime_types_loader.rb
@@ -1,4 +1,4 @@
1
- = MIME::Types for Ruby
1
+ = mime-types
2
2
 
3
3
  home :: http://mime-types.rubyforge.org/
4
4
  code :: https://github.com/halostatue/mime-types/
@@ -9,54 +9,33 @@ continuous integration :: {<img src="https://travis-ci.org/halostatue/mime-types
9
9
 
10
10
  == Description
11
11
 
12
- This library allows for the identification of a file's likely MIME content
13
- type. This is release 1.25.1, fixing an issue with priority comparison for
14
- mime-types 1.x. The current release is 2.0, which only supports Ruby 1.9 or
15
- later.
16
-
17
- Release 1.25.1 contains all features of 1.25, including the experimental
18
- caching and lazy loading functionality. The caching and lazy loading features
19
- were initially implemented by Greg Brockman (gdb). As these features are
20
- experimental, they are disabled by default and must be enabled through the use
21
- of environment variables. The cache is invalidated on a per-version basis; the
22
- cache for version 1.25 will not be reused for any later version.
23
-
24
- To use lazy loading, set the environment variable +RUBY_MIME_TYPES_LAZY_LOAD+
25
- to any value other than 'false'. When using lazy loading, the initial startup
26
- of MIME::Types is around 12–25× faster than normal startup (on my system,
27
- normal startup is about 90 ms; lazy startup is about 4 ms). This isn't
28
- generally useful, however, as the MIME::Types database has not been loaded.
29
- Lazy startup and load is just *slightly* faster—around 1 ms. The real advantage
30
- comes from using the cache.
31
-
32
- To enable the cache, set the environment variable +RUBY_MIME_TYPES_CACHE+ to a
33
- filename where MIME::Types will have read-write access. The first time a new
34
- version of MIME::Types is run using this file, it will be created, taking a
35
- little longer than normal. Subsequent loads using the same cache file will be
36
- approximately 3½× faster (25 ms) than normal loads. This can be combined with
37
- +RUBY_MIME_TYPES_LAZY_LOAD+, but this is *not* recommended in a multithreaded
38
- or multiprocess environment where all threads or processes will be using the
39
- same cache file.
40
-
41
- As the caching interface is still experimental, the only values cached are the
42
- default MIME::Types database, not any custom MIME::Types added by users.
43
-
44
- MIME types are used in MIME-compliant communications, as in e-mail or HTTP
45
- traffic, to indicate the type of content which is transmitted. MIME::Types
46
- provides the ability for detailed information about MIME entities (provided as
47
- a set of MIME::Type objects) to be determined and used programmatically. There
48
- are many types defined by RFCs and vendors, so the list is long but not
49
- complete; don't hesitate to ask to add additional information. This library
50
- follows the IANA collection of MIME types (see below for reference).
51
-
52
- MIME::Types for Ruby was originally based on MIME::Types for Perl by Mark
53
- Overmeer, copyright 2001 - 2009.
54
-
55
- MIME::Types is built to conform to the MIME types of RFCs 2045 and 2231. It
56
- tracks the {IANA registry}[http://www.iana.org/assignments/media-types/]
12
+ The mime-types library provides a library and registry for information about
13
+ MIME content type definitions. It can be used to determine defined filename
14
+ extensions for MIME types, or to use filename extensions to look up the likely
15
+ MIME type definitions.
16
+
17
+ MIME content types are used in MIME-compliant communications, as in e-mail or
18
+ HTTP traffic, to indicate the type of content which is transmitted. The
19
+ mime-types library provides the ability for detailed information about MIME
20
+ entities (provided as an enumerable collection of MIME::Type objects) to be
21
+ determined and used programmatically. There are many types defined by RFCs and
22
+ vendors, so the list is long but by definition incomplete; don't hesitate to to
23
+ add additional type definitions (see Contributing.rdoc). The primary sources
24
+ for MIME type definitions found in mime-types is the IANA collection of
25
+ registrations (see below for the link), RFCs, and W3C recommendations.
26
+
27
+ The mime-types library uses semantic versioning. This is release 2.0; there are
28
+ incompatible changes in the API provided by mime-types, mostly around registry
29
+ initialization (see History.rdoc for full details), and the removal of support
30
+ for Ruby 1.8 interpreters.
31
+
32
+ mime-types (previously called MIME::Types for Ruby) was originally based on
33
+ MIME::Types for Perl by Mark Overmeer, copyright 2001 - 2009. It is built to
34
+ conform to the MIME types of RFCs 2045 and 2231. It tracks the {IANA
35
+ registry}[http://www.iana.org/assignments/media-types/]
57
36
  ({ftp}[ftp://ftp.iana.org/assignments/media-types]) with some unofficial types
58
37
  added from the {LTSW collection}[http://www.ltsw.se/knbase/internet/mime.htp]
59
- and added by the users of MIME::Types.
38
+ and added by the users of mime-types.
60
39
 
61
40
  == Synopsis
62
41
 
data/Rakefile CHANGED
@@ -14,6 +14,9 @@ Hoe.plugin :travis
14
14
 
15
15
  spec = Hoe.spec 'mime-types' do
16
16
  developer('Austin Ziegler', 'austin@rubyforge.org')
17
+ self.need_tar = true
18
+
19
+ self.require_ruby_version '>= 1.9.2'
17
20
 
18
21
  self.remote_rdoc_dir = '.'
19
22
  self.rsync_args << ' --exclude=statsvn/'
@@ -31,202 +34,34 @@ spec = Hoe.spec 'mime-types' do
31
34
  self.extra_dev_deps << ['hoe-travis', '~> 1.2']
32
35
  self.extra_dev_deps << ['minitest', '~> 4.5']
33
36
  self.extra_dev_deps << ['rake', '~> 10.0']
34
- end
35
-
36
- def reload_mime_types(repeats = 1, force_load = false)
37
- repeats.times {
38
- Object.send(:remove_const, :MIME) if defined? MIME
39
- load 'lib/mime/types.rb'
40
- MIME::Types.send(:__types__) if force_load
41
- }
37
+ self.extra_dev_deps << ['simplecov', '~> 0.7']
42
38
  end
43
39
 
44
40
  desc 'Benchmark'
45
41
  task :benchmark, :repeats do |t, args|
46
- repeats = args.repeats.to_i
47
- repeats = 50 if repeats.zero?
48
- require 'benchmark'
49
- $LOAD_PATH.unshift 'lib'
50
-
51
- cache_file = File.expand_path('../cache.mtx', __FILE__)
52
- rm cache_file if File.exist? cache_file
53
-
54
- Benchmark.bm(17) do |x|
55
- x.report("Normal:") { reload_mime_types repeats }
56
-
57
- ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
58
- x.report("Lazy:") { reload_mime_types repeats }
59
- x.report("Lazy+Load:") { reload_mime_types repeats, true }
42
+ $LOAD_PATH.unshift('support')
43
+ require 'benchmarker'
60
44
 
61
- ENV.delete('RUBY_MIME_TYPES_LAZY_LOAD')
62
-
63
- ENV['RUBY_MIME_TYPES_CACHE'] = cache_file
64
- reload_mime_types
65
-
66
- x.report("Cached:") { reload_mime_types repeats }
67
- ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
68
- x.report("Lazy Cached:") { reload_mime_types repeats }
69
- x.report("Lazy Cached Load:") { reload_mime_types repeats, true }
45
+ Benchmarker.benchmark(args.repeats)
46
+ end
70
47
 
48
+ namespace :test do
49
+ task :coverage do
50
+ spec.test_prelude = [
51
+ 'require "simplecov"',
52
+ 'SimpleCov.start("test_frameworks") { command_name "Minitest" }',
53
+ 'gem "minitest"'
54
+ ].join('; ')
55
+ Rake::Task['test'].execute
71
56
  end
72
-
73
- rm cache_file
74
57
  end
75
58
 
76
59
  namespace :mime do
77
60
  desc "Download the current MIME type registrations from IANA."
78
- task :iana, :save, :destination do |t, args|
79
- save_type = (args.save || :text).to_sym
80
-
81
- case save_type
82
- when :text, :both, :html
83
- nil
84
- else
85
- raise "Unknown save type provided. Must be one of text, both, or html."
86
- end
87
-
88
- destination = args.destination || "type-lists"
89
-
90
- require 'open-uri'
91
- require 'nokogiri'
92
- require 'cgi'
93
-
94
- class IANAParser
95
- include Comparable
96
-
97
- INDEX = %q(http://www.iana.org/assignments/media-types/)
98
- CONTACT_PEOPLE = %r{http://www.iana.org/assignments/contact-people.html?#(.*)}
99
- RFC_EDITOR = %r{http://www.rfc-editor.org/rfc/rfc(\d+).txt}
100
- IETF_RFC = %r{http://www.ietf.org/rfc/rfc(\d+).txt}
101
- IETF_RFC_TOOLS = %r{http://tools.ietf.org/html/rfc(\d+)}
102
-
103
- class << self
104
- def load_index
105
- @types ||= {}
106
-
107
- Nokogiri::HTML(open(INDEX) { |f| f.read }).xpath('//p/a').each do |tag|
108
- href_match = %r{^/assignments/media-types/(.+)/$}.match(tag['href'])
109
- next if href_match.nil?
110
- type = href_match.captures[0]
111
- @types[tag.content] = IANAParser.new(tag.content, type)
112
- end
113
- end
114
-
115
- attr_reader :types
116
- end
117
-
118
- def initialize(name, type)
119
- @name = name
120
- @type = type
121
- @url = File.join(INDEX, @type)
122
- end
123
-
124
- attr_reader :name
125
- attr_reader :type
126
- attr_reader :url
127
- attr_reader :html
128
-
129
- def download(name = nil)
130
- @html = Nokogiri::HTML(open(name || @url) { |f| f.read })
131
- end
132
-
133
- def save_html
134
- File.open("#@name.html", "wb") { |w| w.write @html }
135
- end
136
-
137
- def <=>(o)
138
- self.name <=> o.name
139
- end
140
-
141
- def parse
142
- nodes = html.xpath("//table//table//tr")
143
-
144
- # How many <td> children does the first node have?
145
- node_count = nodes.first.children.select { |n| n.elem? }.size
146
-
147
- if node_count == 1
148
- # The title node doesn't have what we expect. Let's try it based
149
- # on the first real node.
150
- node_count = nodes.first.next.children.select { |n| n.elem? }.size
151
- end
152
-
153
- @mime_types = nodes.map do |node|
154
- next if node == nodes.first
155
- elems = node.children.select { |n| n.elem? }
156
- next if elems.size.zero?
157
-
158
- if elems.size != node_count
159
- warn "size mismatch (#{elems.size} != #{node_count}) in node: #{node}"
160
- next
161
- end
162
-
163
- case elems.size
164
- when 3
165
- subtype_index = 1
166
- refnode_index = 2
167
- when 4
168
- subtype_index = 1
169
- refnode_index = 3
170
- else
171
- raise "Unknown element size."
172
- end
173
-
174
- subtype = elems[subtype_index].content.chomp.strip
175
- refnodes = elems[refnode_index].children.select { |n| n.elem? }.map { |ref|
176
- case ref['href']
177
- when CONTACT_PEOPLE
178
- tag = CGI::unescape($1).chomp.strip
179
- if tag == ref.content
180
- "[#{ref.content}]"
181
- else
182
- "[#{ref.content}=#{tag}]"
183
- end
184
- when RFC_EDITOR, IETF_RFC, IETF_RFC_TOOLS
185
- "RFC#$1"
186
- when %r{(https?://.*)}
187
- "{#{ref.content}=#$1}"
188
- else
189
- ref
190
- end
191
- }
192
- refs = refnodes.join(',')
193
-
194
- "#@type/#{subtype} 'IANA,#{refs}"
195
- end.compact
196
-
197
- @mime_types
198
- end
199
-
200
- def save_text
201
- File.open("#@name.txt", "wb") { |w| w.write @mime_types.join("\n") }
202
- end
203
- end
204
-
205
- puts "Downloading index of MIME types from #{IANAParser::INDEX}."
206
- IANAParser.load_index
207
-
208
- require 'fileutils'
209
- FileUtils.mkdir_p destination
210
- Dir.chdir destination do
211
- IANAParser.types.values.sort.each do |parser|
212
- next if parser.name == "example" or parser.name == "mime"
213
- puts "Downloading #{parser.name} from #{parser.url}"
214
- parser.download
215
-
216
- if :html == save_type || :both == save_type
217
- puts "Saving #{parser.name}.html"
218
- parser.save_html
219
- end
220
-
221
- if :text == save_type || :both == save_type
222
- puts "Parsing #{parser.name} HTML"
223
- parser.parse
224
-
225
- puts "Saving #{parser.name}.txt"
226
- parser.save_text
227
- end
228
- end
229
- end
61
+ task :iana, :destination do |t, args|
62
+ $LOAD_PATH.unshift('support')
63
+ require 'iana_downloader'
64
+ IANADownloader.download_to(args.destination)
230
65
  end
231
66
 
232
67
  desc "Shows known MIME type sources."
@@ -242,4 +77,26 @@ http://www.iana.org/assignments/media-types/
242
77
  end
243
78
  end
244
79
 
80
+ Rake::Task['gem'].prerequisites.unshift("convert:yaml:json")
81
+
82
+ namespace :convert do
83
+ namespace :yaml do
84
+ desc "Convert from YAML to JSON"
85
+ task :json, :source, :destination, :multiple_files do |t, args|
86
+ $LOAD_PATH.unshift('support')
87
+ require 'convert'
88
+ Convert.from_yaml_to_json(args)
89
+ end
90
+ end
91
+
92
+ namespace :json do
93
+ desc "Convert from JSON to YAML"
94
+ task :yaml, :source, :destination, :multiple_files do |t, args|
95
+ $LOAD_PATH.unshift('support')
96
+ require 'convert'
97
+ Convert.from_json_to_yaml(args)
98
+ end
99
+ end
100
+ end
101
+
245
102
  # vim: syntax=ruby