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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cdc71cc9f8ea88480f69ea5453c0e2f0322541f83b6ed718de2e7702bd1cc62
4
- data.tar.gz: 3c0919de400bcf4337af964911b203832d6574ef5d2252f19582699883247be9
3
+ metadata.gz: ce6edcb779358d5670da7149c518ccaedd23746a87a712b743a4d013bbb57f3a
4
+ data.tar.gz: 61eeb0de33e7b8b971187e04e5176f5fee498c83589f1d3b20ce42b91da1eebd
5
5
  SHA512:
6
- metadata.gz: 6e28183e973786a75f229cd70f306ef5408d098a2041d6578e6c6b2bbaf9b5ecf972feb0c77bd4f788c71c10bdd1e68d4bf076eeb1782eb03685211491bdb2c7
7
- data.tar.gz: 492480acd6869bf054d9553b3a6b8eb6513648ea51a04bcf12be35d21dc434934fac29624a52d95b223855d07c4c37172304b1631ef7284015b6e41d4034a1de
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://github.com/Largo/chunkybacon).
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://github.com/Largo/chunkybacon)**,
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, PNG bytes or a path) and opens it |
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 |
@@ -15,7 +15,7 @@ module ChunkyBacon
15
15
  version the version of chunky_bacon
16
16
  help this text
17
17
 
18
- The course: https://github.com/Largo/chunkybacon
18
+ The course: https://chunkybacon.idogawa.com
19
19
  TEXT
20
20
 
21
21
  def initialize(out: $stdout, err: $stderr)
@@ -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
- # PNG bytes, or the path of an image file.
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 the PNG signature or NUL bytes, naming a file
88
- if image.is_a?(String) && !image.b.start_with?("\x89PNG".b) && !image.include?("\0") && File.file?(image)
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.b
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChunkyBacon
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
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://github.com/Largo/chunkybacon).
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.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://github.com/Largo/chunkybacon
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://github.com/Largo/chunkybacon
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'