Skip to content
Snippets Groups Projects
Commit f52116cd authored by Markus Reiter's avatar Markus Reiter
Browse files

Add `language` stanza to cask DSL.

parent 929c594f
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment