Add language stanza to cask DSL.

This commit is contained in:
Markus Reiter 2016-09-14 23:11:21 +02:00
parent 929c594f41
commit f52116cd26
2 changed files with 27 additions and 1 deletions

View File

@ -64,6 +64,7 @@ module Hbc
:depends_on, :depends_on,
:gpg, :gpg,
:homepage, :homepage,
:language,
:license, :license,
:name, :name,
:sha256, :sha256,
@ -98,6 +99,31 @@ module Hbc
@homepage ||= homepage @homepage ||= homepage
end 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) def url(*args, &block)
url_given = !args.empty? || block_given? url_given = !args.empty? || block_given?
return @url unless url_given return @url unless url_given

View File

@ -8,7 +8,7 @@ module Hbc
@command = command @command = command
end 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 = {}) def system_command(executable, options = {})
@command.run!(executable, options) @command.run!(executable, options)