data_uri 0.0.1

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.
Files changed (4) hide show
  1. data/README.rdoc +39 -0
  2. data/Rakefile +10 -0
  3. data/lib/data_uri.rb +24 -0
  4. metadata +66 -0
data/README.rdoc ADDED
@@ -0,0 +1,39 @@
1
+ = Data URI
2
+
3
+ == Introduction
4
+
5
+ Data URIs allow resources to be embedding inside a URI. The URI::Data class
6
+ provides support for parsing these URIs using the normal URI.parse method.
7
+
8
+ == Usage
9
+
10
+ require 'data_uri'
11
+
12
+ uri = URI.parse('data:image/gif;base64,...')
13
+ uri.content_type # 'image/gif
14
+ uri.data # Base64 decoded data
15
+
16
+ == License:
17
+
18
+ (The MIT License)
19
+
20
+ Copyright (c) 2010
21
+
22
+ Permission is hereby granted, free of charge, to any person obtaining
23
+ a copy of this software and associated documentation files (the
24
+ 'Software'), to deal in the Software without restriction, including
25
+ without limitation the rights to use, copy, modify, merge, publish,
26
+ distribute, sublicense, and/or sell copies of the Software, and to
27
+ permit persons to whom the Software is furnished to do so, subject to
28
+ the following conditions:
29
+
30
+ The above copyright notice and this permission notice shall be
31
+ included in all copies or substantial portions of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
34
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
36
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
37
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
38
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ desc "Build a gem file"
2
+ task :build do
3
+ system "gem build data_uri.gemspec"
4
+ end
5
+
6
+ task :default => :test
7
+
8
+ task :test do
9
+ system "ruby -Ilib test/test_*.rb"
10
+ end
data/lib/data_uri.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'uri'
2
+ require 'base64'
3
+
4
+ module URI
5
+
6
+ class Data < Generic
7
+
8
+ COMPONENT = [:scheme, :opaque].freeze
9
+ OPAQUE_REGEXP = /^([^;]+);base64,(.+)$/.freeze
10
+
11
+ attr_reader :content_type, :data
12
+
13
+ def initialize(*args)
14
+ super(*args)
15
+ if OPAQUE_REGEXP.match(@opaque)
16
+ @content_type = $1
17
+ @data = Base64.decode64($2)
18
+ end
19
+ end
20
+ end
21
+
22
+ @@schemes['DATA'] = Data
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_uri
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Donald Ball
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-11 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: URI class for parsing data URIs
22
+ email: donald.ball@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ files:
30
+ - README.rdoc
31
+ - Rakefile
32
+ - lib/data_uri.rb
33
+ has_rdoc: true
34
+ homepage: http://github.com/dball/data_uri
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.7
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A URI class for parsing data URIs as per RFC2397
65
+ test_files: []
66
+