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

Add `language_eval` method.

parent f52116cd
No related branches found
No related tags found
No related merge requests found
......@@ -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|
......
......@@ -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
......
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