pics_or_it_didnt_happen 1.0.0 → 1.1.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 +4 -4
- data/lib/pics_or_it_didnt_happen.rb +8 -7
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e2deb3126a3a76370cbccc28d21117c6fd47f178a2215fc2e349bebd85af6af4
|
|
4
|
+
data.tar.gz: e8d45945d12c22a5023532fc4e21779dc8a4a760d406c4db49dd1527cbc83b0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d623bfe462941f22b8d579e131d2635d9e69db6dc327f444541a9ed7ad911e720bf3b946dd6b95036783a80658a1f2c94135267b2bfc39ed2dc38a8d11df8f2
|
|
7
|
+
data.tar.gz: 2a0241679d4f306d6d4b1d446c6c2782cdd61d8432b90fa1f3fdc73c306469419b1db7baa5a85ebf5e9fe54dee8429ef847545df9011bb542da78601501d4b94
|
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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.
|
|
4
|
+
version: 1.1.2
|
|
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:
|
|
11
|
+
date: 2023-04-19 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.
|
|
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
|