Add language_eval method.

This commit is contained in:
Markus Reiter 2016-09-18 04:15:28 +02:00
parent f52116cd26
commit 65fdfefc99
2 changed files with 13 additions and 9 deletions

View File

@ -11,7 +11,10 @@ module Hbc
@token = token
@sourcefile_path = sourcefile_path
@dsl = dsl || DSL.new(@token)
@dsl.instance_eval(&block) if block_given?
if block_given?
@dsl.instance_eval(&block)
@dsl.language_eval
end
end
DSL::DSL_METHODS.each do |method_name|

View File

@ -100,30 +100,31 @@ module Hbc
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
next unless @language.nil? || @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_eval
@language
end
end
def language_eval
if @language.is_a?(Hash) && @language.key?(:block)
@language = @language[:block].call
end
end
def url(*args, &block)
url_given = !args.empty? || block_given?
return @url unless url_given