lib/chartkick/helper.rb in chartkick-4.0.0 vs lib/chartkick/helper.rb in chartkick-4.0.1
- old
+ new
@@ -35,20 +35,26 @@
chartkick_chart "Timeline", data_source, **options
end
private
- def chartkick_chart(klass, data_source, nonce: true, **options)
- @chartkick_chart_id ||= 0
+ # don't break out options since need to merge with default options
+ def chartkick_chart(klass, data_source, **options)
options = chartkick_deep_merge(Chartkick.options, options)
+
+ @chartkick_chart_id ||= 0
element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
+
height = (options.delete(:height) || "300px").to_s
width = (options.delete(:width) || "100%").to_s
defer = !!options.delete(:defer)
+
# content_for: nil must override default
content_for = options.key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
+ nonce = options.fetch(:nonce, true)
+ options.delete(:nonce)
if nonce == true
# Secure Headers also defines content_security_policy_nonce but it takes an argument
# Rails 5.2 overrides this method, but earlier versions do not
if respond_to?(:content_security_policy_nonce) && (content_security_policy_nonce rescue nil)
# Rails 5.2
@@ -123,10 +129,10 @@
JS
if content_for
content_for(content_for) { js.respond_to?(:html_safe) ? js.html_safe : js }
else
- html += js
+ html += "\n#{js}"
end
html.respond_to?(:html_safe) ? html.html_safe : html
end