lib/chartkick/helper.rb in chartkick-1.2.3 vs lib/chartkick/helper.rb in chartkick-1.2.4

- old
+ new

@@ -30,11 +30,11 @@ private def chartkick_chart(klass, data_source, options, &block) @chartkick_chart_id ||= 0 - options = options.dup + options = chartkick_deep_merge(Chartkick.options, options) element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}" height = options.delete(:height) || "300px" # content_for: nil must override default content_for = options.has_key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for @@ -53,9 +53,19 @@ else html += js end html.respond_to?(:html_safe) ? html.html_safe : html + end + + # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb + def chartkick_deep_merge(hash_a, hash_b) + hash_a = hash_a.dup + hash_b.each_pair do |k,v| + tv = hash_a[k] + hash_a[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v + end + hash_a end end end