Fix basic Ruby syntax errors in docs example code

- Blocks should open with `do` and close with `end`.
- `...` is not valid Ruby syntax, so comment it out so that the user
  knows that it's a placeholder for "other things here".
- Reword the "header line details" in `Cask-Cookbook` otherwise RuboCop
  crashes even with an `end` because of the empty block. There was
  already an example of a valid header line in the first code block on
  the page, so it's not a big loss.
This commit is contained in:
Issy Long 2024-01-21 22:55:35 +00:00
parent e2251ad4be
commit 28c513ac9d
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
2 changed files with 11 additions and 12 deletions

View File

@ -29,13 +29,7 @@ Exception: `do` blocks such as `postflight` may enclose a block of pure Ruby cod
## Header line details
The first non-comment line in a cask follows the form:
```ruby
cask "<cask-token>" do
```
[`<cask-token>`](#token-reference) should match the cask filename, without the `.rb` extension, enclosed in double quotes.
The Cask name ([`<cask-token>`](#token-reference)) on the header line `cask <cask-token> do` should match the cask filename, without the `.rb` extension, enclosed in double quotes.
There are currently some arbitrary limitations on cask tokens which are in the process of being removed. GitHub Actions will catch any errors during the transition.
@ -1197,6 +1191,7 @@ cask "libreoffice" do
url "https://download.documentfoundation.org/libreoffice/stable/#{version}/mac/#{folder}/LibreOffice_#{version}_MacOS_#{arch}.dmg",
verified: "download.documentfoundation.org/libreoffice/stable/"
end
```
If the version number is different for each architecture, locate the unique `version` and (if checked) `sha256` stanzas within `on_arm` and `on_intel` blocks. Example (from [inkscape.rb](https://github.com/Homebrew/homebrew-cask/blob/11f6966bf17628b98895d64a61a4fb0bc1bb31bf/Casks/i/inkscape.rb#L1-L13)):
@ -1215,6 +1210,7 @@ cask "inkscape" do
end
url "https://inkscape.org/gallery/item/#{version.csv.second}/Inkscape-#{version.csv.first}_#{arch}.dmg"
end
```
To adjust the installed version depending on the current macOS release, use a series of `on_<system>` blocks that cover the range of supported releases. Each block can contain stanzas that set which version to download and customize installation/uninstallation and livecheck behaviour for one or more releases. Example (from [calibre.rb](https://github.com/Homebrew/homebrew-cask/blob/482c34e950da8d649705f4aaea7b760dcb4b5402/Casks/c/calibre.rb#L1-L34)):
@ -1244,6 +1240,7 @@ cask "calibre" do
strategy :github_latest
end
end
end
```
Such `on_<system>` blocks can be nested and contain other stanzas not listed here. Examples: [calhash.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/c/calhash.rb), [openzfs.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/o/openzfs.rb), [r.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/r/r.rb), [wireshark.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/w/wireshark.rb)
@ -1260,7 +1257,7 @@ In the exceptional case that the cask DSL is insufficient, it is possible to def
cask "myapp" do
module Utils
def self.arbitrary_method
...
# ...
end
end
@ -1270,7 +1267,7 @@ cask "myapp" do
url "https://#{Utils.arbitrary_method}"
homepage "https://www.example.com/"
...
# ...
end
```

View File

@ -546,7 +546,7 @@ end
```ruby
stable do
# some other things...
# ...
patch do
url "https://example.com/example_patch.diff"
@ -700,6 +700,7 @@ class Nginx < Formula
url "https://nginx.org/download/nginx-1.23.2.tar.gz", using: :homebrew_curl
sha256 "a80cc272d3d72aaee70aa8b517b4862a635c0256790434dbfc4d618a999b0b46"
head "https://hg.nginx.org/nginx/", using: :hg
end
```
Homebrew offers these anonymous download strategies.
@ -890,13 +891,14 @@ If you want to add an [`option`](https://rubydoc.brew.sh/Formula#option-class_me
```ruby
class Yourformula < Formula
...
# ...
option "with-ham", "Description of the option"
option "without-spam", "Another description"
depends_on "foo" => :optional # automatically adds a with-foo option
depends_on "bar" => :recommended # automatically adds a without-bar option
...
# ...
end
```
And then to define the effects the [`option`](https://rubydoc.brew.sh/Formula#option-class_method)s have: