Add language stanza to cask DSL.
This commit is contained in:
parent
929c594f41
commit
f52116cd26
@ -64,6 +64,7 @@ module Hbc
|
||||
:depends_on,
|
||||
:gpg,
|
||||
:homepage,
|
||||
:language,
|
||||
:license,
|
||||
:name,
|
||||
:sha256,
|
||||
@ -98,6 +99,31 @@ module Hbc
|
||||
@homepage ||= homepage
|
||||
end
|
||||
|
||||
def language(*args, &block)
|
||||
@language ||= {}
|
||||
|
||||
if !args.empty? && block_given?
|
||||
args.each do |arg|
|
||||
MacOS.languages.each_with_index do |l, index|
|
||||
string_or_regex = arg == :default ? %r{^en} : arg
|
||||
next unless l.match(string_or_regex)
|
||||
next unless @language[:level].nil? || @language[:level] > index
|
||||
@language = {
|
||||
block: block,
|
||||
level: index,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
if args.include?(:default)
|
||||
# :default has to be the last language block in order to assign return value of the selected `language` block to `@language`
|
||||
@language = @language[:block].call
|
||||
end
|
||||
else
|
||||
@language
|
||||
end
|
||||
end
|
||||
|
||||
def url(*args, &block)
|
||||
url_given = !args.empty? || block_given?
|
||||
return @url unless url_given
|
||||
|
||||
@ -8,7 +8,7 @@ module Hbc
|
||||
@command = command
|
||||
end
|
||||
|
||||
def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir
|
||||
def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir, :language
|
||||
|
||||
def system_command(executable, options = {})
|
||||
@command.run!(executable, options)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user