pics_or_it_didnt_happen 1.0.0 → 1.1.3

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: 2a8e935ec65c38271506c2a5bece5d706a660c7386cd100c9282773e7e128b95
4
- data.tar.gz: 323232618a4d30ed8f625c976b52380185fda853fa90d21fdb5f0db322a403d2
3
+ metadata.gz: 6499a083ae19e977da132e5a4e3d9cfc87ebcd8f15ecfc5ca58abaa238e1e927
4
+ data.tar.gz: beeb9e58fed600d2eb51ef9a09ad34fa6e93106d09e585c3fa4356f8f2afdfa3
5
5
  SHA512:
6
- metadata.gz: c5974894490f3ff424a7a052f8a21dd9ab012d6debc5bba4311c302ce210a1112f75a08aede9859f3185f8d7198de6c691296d59de580c8c78d42f3581f469d6
7
- data.tar.gz: 911e9d5a72afb150d2723a20cfeeb8f46459200046525917402ec7f670090192317305971a3f4003458f02804dfed484c2199f0d49e6794ad92b87a3c9fa8572
6
+ metadata.gz: 88c6e124dcc03b22a851b26ba212c5e63ec831c53a998968c5379cffbc26759ead5363e7c2ddbd27012773b92d94a0131a839add5fdde97bee3be7bfeaa4dc9e
7
+ data.tar.gz: aab98afa1b45ca028cc70a8cbe8c1ee174f4adaed037ff89e8ee652e36e1258ab5c7557f7414b99a7497ae7adab75da92e2a75048779ecf31ebbfb5ecf18a3bb
@@ -1,16 +1,17 @@
1
1
  require 'base64'
2
2
 
3
3
  module PicsOrItDidntHappen
4
- def self.image_to_data_url_image_tag(file_path, alt_text: nil)
4
+ def self.image_to_data_url_image_tag(file_path, alt_text: nil, classes: nil)
5
5
  raise ArgumentError, "No file was found at #{file_path}" unless File.exist?(file_path)
6
+ raise ArgumentError, "alt_text must be a string" unless alt_text.is_a?(String) || alt_text.nil?
7
+ raise ArgumentError, "classes must be a string" unless classes.is_a?(String) || classes.nil?
6
8
  file_in_binary = IO.binread(file_path)
7
9
  base64_encoded_image_data = [file_in_binary].pack('m0')
8
- src_string = "data:#{mime_type_of(file_path)};base64,#{base64_encoded_image_data}"
9
- if alt_text
10
- return "<img src=\"#{src_string}\" alt=\"#{alt_text}\">"
11
- else
12
- return "<img src=\"#{src_string}\">"
13
- end
10
+ src_string = "data:#{mime_type_of(file_path)};base64,#{base64_encoded_image_data}"
11
+ html_string = "<img src=\"#{src_string}\""
12
+ html_string += " alt=\"#{alt_text}\"" if alt_text
13
+ html_string += " class=\"#{classes}\"" if classes
14
+ return html_string.strip + ">"
14
15
  end
15
16
 
16
17
  # this method was inspired by a Alain Beauvois's StackOverflow answer: https://stackoverflow.com/a/16635245
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pics_or_it_didnt_happen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Matthew Crossley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-16 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Sometimes, you might want your HTML to include a one-off image file that is just for one person. Making this file public may be undesireable for security reasons, or perhaps simply because it is not worth the overhead of multiple HTTP requests.
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
45
  requirements: []
46
- rubygems_version: 3.1.6
46
+ rubygems_version: 3.4.8
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: A Ruby gem that lets you include images in HTML using data URLs (and avoid