Skip to content

Commit

Permalink
Add language stanza to cask DSL.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Oct 3, 2016
1 parent 929c594 commit f52116c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Library/Homebrew/cask/lib/hbc/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class DSL
:depends_on,
:gpg,
:homepage,
:language,
:license,
:name,
:sha256,
Expand Down Expand Up @@ -98,6 +99,31 @@ def homepage(homepage = nil)
@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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/lib/hbc/dsl/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(cask, command = SystemCommand)
@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)
Expand Down

0 comments on commit f52116c

Please sign in to comment.