Skip to content

Commit

Permalink
Allowing multiple externs to be passed in options
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazek committed Apr 12, 2011
1 parent 70b2ab0 commit 7fb8f71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/closure/compiler.rb
Expand Up @@ -51,7 +51,13 @@ def compile(io)

# Serialize hash options to the command-line format.
def serialize_options(options)
options.map {|k, v| ["--#{k}", v.to_s] }.flatten
options.map do |k, v|
if (v.is_a?(Array))
v.map {|v2| ["--#{k}", v2.to_s]}
else
["--#{k}", v.to_s]
end
end.flatten
end

def command
Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_closure_compiler.rb
Expand Up @@ -60,4 +60,13 @@ def test_permissions
assert File.executable?(COMPILER_JAR)
end

def test_serialize_options
assert_equal ["--externs", "library1.js", "--compilation_level", "ADVANCED_OPTIMIZATIONS"], Closure::Compiler.new.send(:serialize_options, 'externs' => 'library1.js', "compilation_level" => "ADVANCED_OPTIMIZATIONS")
end

def test_serialize_options_for_arrays
compiler = Closure::Compiler.new('externs' => ['library1.js', "library2.js"])
assert_equal ["--externs", "library1.js", "--externs", "library2.js"], compiler.send(:serialize_options, 'externs' => ['library1.js', "library2.js"])
end

end

0 comments on commit 7fb8f71

Please sign in to comment.