file_to_data_uri 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: b9ff8efa62708efb190149d2a5e62112b2ec32702beeece7360e5b56dde892e1
4
- data.tar.gz: 40bb5ee786facf6af6242114e31922c3eda602d6e2faba9ec7b603b1913dc67b
3
+ metadata.gz: e69a903b1dddc2738d8774783c256f92a98e3449e17ee050b27371b425b76749
4
+ data.tar.gz: 51d706f2508bc19cf9c932362a4f9b52539a940fad4d332805e9770d05851b8c
5
5
  SHA512:
6
- metadata.gz: 27d6273e888342c32b4f1101ae8e6c07ae11f3ded13d4b8d6c618a168e69a668a64d7db522ffab118d01a06b2ffbbbc2dbec1edef822646ab6e7556281ab4963
7
- data.tar.gz: 2bc4c535e9fac1dd1eef05021363b70586689cb19b89594a85e654773e9cb90f967058d6dd3934ac3e8e9a6b4d737501b07cfc82542cdb15b39f9e50a0587bc2
6
+ metadata.gz: 48952831c00c1a4296599bffea8b2b0f1928fe9be63bd373fdeb62f72b52a076bfbefe86ab17cf7375e4d0a2d8eb4889e0c873b15b99a0673258e8bc813bbbda
7
+ data.tar.gz: 9cdd2e783859a204b1e6ed56059a7b524c5dd6529d20cd2e9c6a5601710781b8bea60940da87235e8cd1e0647e2e107c804c960e69874a82da816497dc577c09
data/README.md CHANGED
@@ -30,16 +30,22 @@ gem install file_to_data_uri
30
30
 
31
31
  ```ruby
32
32
  # With a file path
33
- data_uri = DataURI.new("path/to/image.jpg")
34
- data_uri.to_s # => "data:image/jpeg;base64,..."
33
+ data_uri = DataURI.convert("path/to/image.jpg") # => "data:image/jpeg;base64,..."
35
34
 
36
35
  # With a file-like object (anything that responds to `read`)
37
36
  file = File.open("image.png")
38
- data_uri = DataURI.new(file)
39
- data_uri.to_s # => "data:image/png;base64,..."
37
+ data_uri = DataURI.convert(file) # => "data:image/png;base64,..."
40
38
 
41
39
  # Direct use in HTML
42
- # <img src="<%= DataURI.new('logo.png').to_s %>">
40
+ # <img src="<%= DataURI.convert('logo.png') %>">
41
+ ```
42
+
43
+ ### Legacy Usage (still supported)
44
+
45
+ ```ruby
46
+ # With a file path
47
+ data_uri = DataURI.new("path/to/image.jpg")
48
+ data_uri.to_s # => "data:image/jpeg;base64,..."
43
49
  ```
44
50
 
45
51
  ### Supported Input Types
@@ -30,4 +30,4 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.extra_rdoc_files = Dir["README*", "LICENSE*", "CHANGELOG*"]
32
32
  spec.files = Dir["*.gemspec", "lib/**/*"]
33
- end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class DataURI
4
- VERSION = "0.0.1"
5
- end
4
+ VERSION = "0.0.2"
5
+ end
@@ -6,6 +6,14 @@ require_relative "file_to_data_uri/version"
6
6
 
7
7
  # DataURI class for generating data URIs from files or file-like objects
8
8
  class DataURI
9
+ # Convert a file path or file-like object to a data URI string
10
+ #
11
+ # @param source [String, #read] File path or file-like object
12
+ # @return [String] A data URI representation of the file
13
+ def self.convert(source)
14
+ new(source).to_s
15
+ end
16
+
9
17
  # Initialize with a file path or file-like object
10
18
  #
11
19
  # @param source [String, #read] File path or file-like object
@@ -52,9 +60,9 @@ class DataURI
52
60
  elsif @source.respond_to?(:path) && @source.path
53
61
  # If it's a file object with a path
54
62
  mime_from_path(@source.path)
55
- elsif @source.is_a?(String)
56
- # If it's a file path as string
57
- mime_from_path(@source)
63
+ elsif @source.is_a?(String) || @source.respond_to?(:to_s)
64
+ # If it's a file path as string or can be converted to string (like Pathname)
65
+ mime_from_path(@source.to_s)
58
66
  else
59
67
  # Default to octet-stream if we can't determine
60
68
  "application/octet-stream"
@@ -69,4 +77,4 @@ class DataURI
69
77
  mime = MIME::Types.type_for(path.to_s).first
70
78
  mime ? mime.to_s : "application/octet-stream"
71
79
  end
72
- end
80
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_to_data_uri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raghu Betina