lib/chartkick/helper.rb in chartkick-1.2.4 vs lib/chartkick/helper.rb in chartkick-1.2.5
- old
+ new
@@ -31,22 +31,19 @@
private
def chartkick_chart(klass, data_source, options, &block)
@chartkick_chart_id ||= 0
options = chartkick_deep_merge(Chartkick.options, options)
- element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
- height = options.delete(:height) || "300px"
+ element_id = options[:id] || "chart-#{@chartkick_chart_id += 1}"
+ height = options[:height] || "300px"
# content_for: nil must override default
content_for = options.has_key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
- html = <<HTML
-<div id="#{ERB::Util.html_escape(element_id)}" style="height: #{ERB::Util.html_escape(height)}; text-align: center; color: #999; line-height: #{ERB::Util.html_escape(height)}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">
- Loading...
-</div>
-HTML
- js = <<JS
+ html = (options[:html] || %[<div id="%{id}" style="height: %{height}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">Loading...</div>]) % {id: ERB::Util.html_escape(element_id), height: ERB::Util.html_escape(height)}
+
+ js = <<JS
<script type="text/javascript">
- new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.to_json}, #{options.to_json});
+ new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json}, #{options.except(:id, :height, :html).to_json});
</script>
JS
if content_for
content_for(content_for) { js.respond_to?(:html_safe) ? js.html_safe : js }
else