chunky_bacon 0.1.1 → 0.1.3
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/CHANGELOG.md +12 -0
- data/LICENSE-ASSETS +1 -1
- data/README.md +2 -2
- data/lib/chunky_bacon/cli.rb +1 -1
- data/lib/chunky_bacon/helpers.rb +19 -6
- data/lib/chunky_bacon/version.rb +1 -1
- data/lib/chunky_bacon.rb +1 -1
- 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: ce6edcb779358d5670da7149c518ccaedd23746a87a712b743a4d013bbb57f3a
|
|
4
|
+
data.tar.gz: 61eeb0de33e7b8b971187e04e5176f5fee498c83589f1d3b20ce42b91da1eebd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e0e229104f116c447bde017803a62e27f20bb6b439715eb130e5401e83cdf8db92f994902aa0bb5dbc618f8f930cd356242dbc518f3804f97d5c454e8443f9d2
|
|
7
|
+
data.tar.gz: 95e9ad045d5fbcd2318294847e2ee9201ce006ce27dca1be32d2c512aa442e2da1defc56f5d3825130dfc9da5e2493e9a9a7c11acdd3ea5fda8e6bff2ae2519b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
- `show_image` takes JPEGs, as the course's lesson 22 (pure_jpeg) makes
|
|
6
|
+
them: what `PureJPEG.encode` returns (anything with `to_bytes`), and the
|
|
7
|
+
bytes of a JPEG, GIF or WebP, saved with their own extension.
|
|
8
|
+
|
|
9
|
+
## 0.1.2
|
|
10
|
+
|
|
11
|
+
- The homepage is the course itself, https://chunkybacon.idogawa.com (also
|
|
12
|
+
in the README, the license notes and `chunkybacon help`); the source stays
|
|
13
|
+
on GitHub. The aliases `chunkybacon` and `chunky-bacon` 0.1.1 link it too.
|
|
14
|
+
|
|
3
15
|
## 0.1.1
|
|
4
16
|
|
|
5
17
|
- The course is named by its English title, "Learn Ruby with Chunky Bacon",
|
data/LICENSE-ASSETS
CHANGED
|
@@ -4,7 +4,7 @@ Attribution-ShareAlike 4.0 International License (CC BY-SA 4.0):
|
|
|
4
4
|
https://creativecommons.org/licenses/by-sa/4.0/
|
|
5
5
|
|
|
6
6
|
Copyright (c) 2026 Andi Idogawa. Chunky is the mascot of the Ruby course
|
|
7
|
-
"Learn Ruby with Chunky Bacon" (https://
|
|
7
|
+
"Learn Ruby with Chunky Bacon" (https://chunkybacon.idogawa.com).
|
|
8
8
|
|
|
9
9
|
You may share and adapt the drawing, also commercially, as long as you give
|
|
10
10
|
credit (name the course and Andi Idogawa, link the license) and share
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# chunky_bacon
|
|
2
2
|
|
|
3
|
-
The companion gem of **[Learn Ruby with Chunky Bacon](https://
|
|
3
|
+
The companion gem of **[Learn Ruby with Chunky Bacon](https://chunkybacon.idogawa.com)**,
|
|
4
4
|
an interactive Ruby course that runs in the browser.
|
|
5
5
|
|
|
6
6
|
In the course, notebook cells and the workshop have helpers like `show_image`,
|
|
@@ -33,7 +33,7 @@ never mix with your program's output.
|
|
|
33
33
|
| Helper | On your computer |
|
|
34
34
|
|---|---|
|
|
35
35
|
| `install_gem "name"` | installs the gem unless it is there, and activates it |
|
|
36
|
-
| `show_image image` | saves `chunky-image-N.png` (ChunkyPNG image,
|
|
36
|
+
| `show_image image` | saves `chunky-image-N.png` (or `.jpg`, `.gif`, `.webp`: a ChunkyPNG image, a PureJPEG encoder, the bytes or a path) and opens it |
|
|
37
37
|
| `show_pdf pdf` | saves `chunky-document-N.pdf` (Prawn/HexaPDF document, bytes or a path) and opens it |
|
|
38
38
|
| `download_file data, "name"` | saves the data as `name` in the program's folder |
|
|
39
39
|
| `show_browser App, "/path"` | starts the Rack app (Sinatra, Roda, ...) on 127.0.0.1 and opens it; after the program's last line the server runs on until Ctrl+C |
|
data/lib/chunky_bacon/cli.rb
CHANGED
data/lib/chunky_bacon/helpers.rb
CHANGED
|
@@ -34,6 +34,16 @@ module ChunkyBacon
|
|
|
34
34
|
path
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
IMAGE_SIGNATURES = {
|
|
38
|
+
"\x89PNG".b => "png", "\xFF\xD8\xFF".b => "jpg", "GIF8".b => "gif", "RIFF".b => "webp"
|
|
39
|
+
}.freeze
|
|
40
|
+
|
|
41
|
+
# "png", "jpg", "gif" or "webp" for a picture's bytes, nil for anything else
|
|
42
|
+
def image_type(bytes)
|
|
43
|
+
bytes = bytes.b
|
|
44
|
+
IMAGE_SIGNATURES.find { |magic, _type| bytes.start_with?(magic) }&.last
|
|
45
|
+
end
|
|
46
|
+
|
|
37
47
|
def relative(path)
|
|
38
48
|
path = File.expand_path(path)
|
|
39
49
|
base = File.expand_path(output_dir) + File::SEPARATOR
|
|
@@ -82,10 +92,11 @@ module ChunkyBacon
|
|
|
82
92
|
end
|
|
83
93
|
|
|
84
94
|
# A picture: a ChunkyPNG image (anything with to_blob or to_data_url),
|
|
85
|
-
#
|
|
95
|
+
# what PureJPEG.encode returns (anything with to_bytes), the bytes of a
|
|
96
|
+
# PNG, JPEG, GIF or WebP, or the path of an image file.
|
|
86
97
|
def show_image(image)
|
|
87
|
-
# a path: text without
|
|
88
|
-
if image.is_a?(String) && !
|
|
98
|
+
# a path: text without a picture's signature or NUL bytes, naming a file
|
|
99
|
+
if image.is_a?(String) && !ChunkyBacon.image_type(image) && !image.include?("\0") && File.file?(image)
|
|
89
100
|
ChunkyBacon::Opener.open(File.expand_path(image))
|
|
90
101
|
return nil
|
|
91
102
|
end
|
|
@@ -93,10 +104,12 @@ module ChunkyBacon
|
|
|
93
104
|
image.to_blob
|
|
94
105
|
elsif image.respond_to?(:to_data_url)
|
|
95
106
|
image.to_data_url.split(",", 2).last.unpack1("m0")
|
|
107
|
+
elsif image.respond_to?(:to_bytes)
|
|
108
|
+
image.to_bytes
|
|
96
109
|
else
|
|
97
|
-
image.to_s
|
|
98
|
-
end
|
|
99
|
-
path = ChunkyBacon.save(ChunkyBacon.next_file("chunky-image", "png"), bytes)
|
|
110
|
+
image.to_s
|
|
111
|
+
end.b
|
|
112
|
+
path = ChunkyBacon.save(ChunkyBacon.next_file("chunky-image", ChunkyBacon.image_type(bytes) || "png"), bytes)
|
|
100
113
|
ChunkyBacon::Opener.open(path)
|
|
101
114
|
nil
|
|
102
115
|
end
|
data/lib/chunky_bacon/version.rb
CHANGED
data/lib/chunky_bacon.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# chunky_bacon: the companion gem of "Learn Ruby with Chunky Bacon", the Ruby
|
|
4
|
-
# course that runs in the browser (https://
|
|
4
|
+
# course that runs in the browser (https://chunkybacon.idogawa.com).
|
|
5
5
|
#
|
|
6
6
|
# On your own computer, `require "chunky_bacon"` gives a program the helpers
|
|
7
7
|
# the course's notebook cells and workshop have - show_image, show_browser,
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chunky_bacon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andi Idogawa
|
|
@@ -36,12 +36,12 @@ files:
|
|
|
36
36
|
- lib/chunky_bacon/rack_env.rb
|
|
37
37
|
- lib/chunky_bacon/server.rb
|
|
38
38
|
- lib/chunky_bacon/version.rb
|
|
39
|
-
homepage: https://
|
|
39
|
+
homepage: https://chunkybacon.idogawa.com
|
|
40
40
|
licenses:
|
|
41
41
|
- MIT
|
|
42
42
|
- CC-BY-SA-4.0
|
|
43
43
|
metadata:
|
|
44
|
-
homepage_uri: https://
|
|
44
|
+
homepage_uri: https://chunkybacon.idogawa.com
|
|
45
45
|
source_code_uri: https://github.com/Largo/chunkybacon/tree/main/gem/chunky_bacon
|
|
46
46
|
changelog_uri: https://github.com/Largo/chunkybacon/blob/main/gem/chunky_bacon/CHANGELOG.md
|
|
47
47
|
rubygems_mfa_required: 'true'
|