Skip to content

Commit f52116c

Browse files
committed
Add language stanza to cask DSL.
1 parent 929c594 commit f52116c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Library/Homebrew/cask/lib/hbc/dsl.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class DSL
6464
:depends_on,
6565
:gpg,
6666
:homepage,
67+
:language,
6768
:license,
6869
:name,
6970
:sha256,
@@ -98,6 +99,31 @@ def homepage(homepage = nil)
9899
@homepage ||= homepage
99100
end
100101

102+
def language(*args, &block)
103+
@language ||= {}
104+
105+
if !args.empty? && block_given?
106+
args.each do |arg|
107+
MacOS.languages.each_with_index do |l, index|
108+
string_or_regex = arg == :default ? %r{^en} : arg
109+
next unless l.match(string_or_regex)
110+
next unless @language[:level].nil? || @language[:level] > index
111+
@language = {
112+
block: block,
113+
level: index,
114+
}
115+
end
116+
end
117+
118+
if args.include?(:default)
119+
# :default has to be the last language block in order to assign return value of the selected `language` block to `@language`
120+
@language = @language[:block].call
121+
end
122+
else
123+
@language
124+
end
125+
end
126+
101127
def url(*args, &block)
102128
url_given = !args.empty? || block_given?
103129
return @url unless url_given

Library/Homebrew/cask/lib/hbc/dsl/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(cask, command = SystemCommand)
88
@command = command
99
end
1010

11-
def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir
11+
def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir, :language
1212

1313
def system_command(executable, options = {})
1414
@command.run!(executable, options)

0 commit comments

Comments
 (0)