datauris 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b17d925dd560274e1e3a4f21e5caa118762e74c1d5b1e4e07777c9456b64f0f
4
- data.tar.gz: 34c7263eea9cd31e1bfede00bb4002d303dc59d7870d3bad620a88a7345d292a
3
+ metadata.gz: d1a65cebd38591b1ea9416cbb69498707019dd6e422c0aacc72b404f546270da
4
+ data.tar.gz: 559e1dbe5a26c70a872ca242b0e4c93a06b8883a0dbe080a3cd38f560019390f
5
5
  SHA512:
6
- metadata.gz: 509299375bebbc22eee68c3c3a704030df51c1d555a57ee5ff83435b1b5d6a0cf9de75c49d1551f277e89db01280bb7f15dc2f2ddd42cfa9bf3ef7279cef0ce4
7
- data.tar.gz: b0aba84982c23968350395e3aedf91e11bf7f31a20566e1262f715f9638fdcf05b91aa2e575f4189ca0d58318f8702de0d587efbd7262d7a0c466a3b8e1e33e9
6
+ metadata.gz: b60dd18069dee8bcb18b6fbb834964f4a55423fe595c8a8b3cad3f50219c39283920f2b14a4dedf72870eddc0575b555729e5763b3369e43aac809fb61b26ef0
7
+ data.tar.gz: 6872aa3cc3aeffeaebf0632e6dbc287dec2e17d7d3151bf4fd52ec22a9b93580db2ed61821145fc61b2522345ddbc6828e27279abf523990bc72c58190339921
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 1.0.0
1
+ ### 1.0.1
2
2
  ### 0.0.1 / 2023-11-23
3
3
 
4
4
  * Everything is new. First release
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Data URI Helpers
2
2
 
3
- datauris - helpers to parse (decode) and build (encode) data uris incl. (strict)base64-encoded/decoded images and more
3
+ datauris - helpers to parse (decode) and build (encode) data uris incl. (strict) base64-encoded/decoded images and more
4
4
 
5
5
  * home :: [github.com/s6ruby/rubidity](https://github.com/s6ruby/rubidity)
6
6
  * bugs :: [github.com/s6ruby/rubidity/issues](https://github.com/s6ruby/rubidity/issues)
@@ -58,21 +58,21 @@ Let's try and parse the Wikipedia Data URI examples:
58
58
  uri = "data:text/vnd-example+xyz;foo=bar;base64,R0lGODdh"
59
59
  DataUri.valid?( uri )
60
60
  #=> true
61
- mediatype, data = DataUri.parse( uri ) ## returns 1) mediatype (+parameters), 2) data
62
- #=> "text/vnd-example+xyz;foo=bar", "<blob>"
61
+ data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
62
+ #=> "<blob>", "text/vnd-example+xyz;foo=bar"
63
63
 
64
64
  uri = "data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678"
65
65
  DataUri.valid?( uri )
66
66
  #=> true
67
- mediatype, data = DataUri.parse( uri ) ## returns 1) mediatype (+parameters), 2) data
68
- #=> "text/plain;charset=UTF-8;page=21", "the data:1234,5678"
67
+ data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
68
+ #=> "the data:1234,5678", "text/plain;charset=UTF-8;page=21"
69
69
 
70
70
 
71
71
  uri = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/"
72
72
  DataUri.valid?( uri )
73
73
  #=> true
74
- mediatype, data = DataUri.parse( uri ) ## returns 1) mediatype (+parameters), 2) data
75
- #=> "image/jpeg", "<blob>"
74
+ data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
75
+ #=> "<blob>", "image/jpeg"
76
76
  ```
77
77
 
78
78
 
@@ -87,7 +87,7 @@ uri = "data:,"
87
87
 
88
88
  DataUri.valid?( uri )
89
89
  #=> true
90
- mediatype, data = DataUri.parse( uri ) ## returns 1) mediatype (+parameters), 2) data
90
+ data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
91
91
  #=> "", ""
92
92
  ```
93
93
 
@@ -98,8 +98,8 @@ uri = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHV..."
98
98
 
99
99
  DataUri.valid?( uri )
100
100
  #=> true
101
- mediatype, data = DataUri.parse( uri ) ## returns 1) mediatype (+parameters), 2) data
102
- #=> "image/jpeg", "<blob>"
101
+ data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
102
+ #=> "<blob>", "image/jpeg"
103
103
 
104
104
  ## let's save the jpeg image (blob)
105
105
  write_blob( "0.jpeg", data )
@@ -117,8 +117,8 @@ uri = "data:image/png;base64,/9j/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAAB..."
117
117
 
118
118
  DataUri.valid?( uri )
119
119
  #=> true
120
- mediatype, data = DataUri.parse( uri ) ## returns 1) mediatype (+parameters), 2) data
121
- #=> "image/png", "<blob>"
120
+ data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
121
+ #=> "<blob>", "image/png"
122
122
 
123
123
  ## let's save the png image (blob)
124
124
  write_blob( "15.png", data )
@@ -2,7 +2,7 @@
2
2
  module DataUri
3
3
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
4
4
  MINOR = 0
5
- PATCH = 0
5
+ PATCH = 1
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
data/lib/datauris.rb CHANGED
@@ -58,7 +58,7 @@ module DataUri
58
58
  (?<subtype> [\w.+-]+? )
59
59
  )?
60
60
  (?<parameters> (?: ;
61
- [\w.+-]+?
61
+ [\w-]+?
62
62
  =
63
63
  .+?
64
64
  )*
@@ -89,7 +89,11 @@ module DataUri
89
89
  ## todo/double check - use a different URI decoder - why? why not?
90
90
  URI.decode_uri_component(m[:data])
91
91
  end
92
- [mediatype, data]
92
+
93
+ ## returns data first!!!
94
+ ## and mediatype second (to follow the order in build)
95
+ ## - also mediatype is optional - arguable more intuitive - yes,no?
96
+ [data, mediatype]
93
97
  else
94
98
  raise ArgumentError, "invalid datauri - cannot match regex; sorry"
95
99
  end
@@ -201,8 +205,8 @@ module DataUri
201
205
  ## add alias convenience names - why? why not?
202
206
  class << self
203
207
  alias_method :is_valid?, :valid?
204
- alias_method :decode, :parse
205
- alias_method :encode, :build
208
+ alias_method :decode, :parse ### add decode - why? why not?
209
+ alias_method :encode, :build ### add encode - why? why not?
206
210
  end
207
211
  end # module DataUri
208
212
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datauris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-24 00:00:00.000000000 Z
11
+ date: 2023-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc