diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2013-06-06 02:21:42 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2013-06-06 02:21:42 -0700 |
| commit | 0ccec419fa44d958a46eaac365b8c8b64072329c (patch) | |
| tree | b0f38be156162197d8e56b563516bdeddd0dfab6 /lib | |
| parent | 78e4caac40d2ada4825e6ceb3aeeb6a70aec79f4 (diff) | |
| parent | 91ecba62431d3274c8155933016084ea37e654c5 (diff) | |
Merge pull request #397 from mojavelinux/attributes-option-type
resolves #396 allow JRuby Map as attributes
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/asciidoctor.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb index 55427ba8..60eecdcb 100755 --- a/lib/asciidoctor.rb +++ b/lib/asciidoctor.rb @@ -1,3 +1,4 @@ +RUBY_ENGINE = 'unknown' unless defined? RUBY_ENGINE if RUBY_VERSION < '1.9' require 'rubygems' end @@ -677,7 +678,7 @@ module Asciidoctor end attrs = (options[:attributes] ||= {}) - if attrs.is_a? Hash + if attrs.is_a?(Hash) || (RUBY_ENGINE == 'jruby' && attrs.is_a?(Java::JavaUtil::Map)) # all good; placed here as optimization elsif attrs.is_a? Array attrs = options[:attributes] = attrs.inject({}) do |accum, entry| @@ -695,8 +696,15 @@ module Asciidoctor accum[k] = v || '' accum end + elsif attrs.respond_to?('keys') && attrs.respond_to?('[]') + # convert it to a Hash as we know it + original_attrs = attrs + attrs = options[:attributes] = {} + original_attrs.keys.each do |key| + attrs[key] = original_attrs[key] + end else - raise ArgumentError, 'illegal type for attributes option' + raise ArgumentError, "illegal type for attributes option: #{attrs.class.ancestors}" end lines = nil |
