lib/vega/spec.rb in vega-0.2.5 vs lib/vega/spec.rb in vega-0.2.6

- old
+ new

@@ -4,15 +4,16 @@ spec = spec.spec if spec.respond_to?(:spec) raise ArgumentError, "Expected Hash, not #{spec.class.name}" unless spec.is_a?(Hash) @spec = spec.transform_keys!(&:to_s) end - def to_s + def to_html(nonce: nil) html, js = generate_output + nonce_html = nonce ? " nonce=\"#{ERB::Util.html_escape(nonce)}\"" : nil output = <<~EOS #{html} - <script> + <script#{nonce_html}> (function() { var createChart = function() { #{js} }; if ("vegaEmbed" in window) { createChart(); } else { @@ -21,9 +22,10 @@ })(); </script> EOS output.respond_to?(:html_safe) ? output.html_safe : output end + alias_method :to_s, :to_html # TODO only load vega-lite if $schema requires it def to_iruby html, js = generate_output output = <<~EOS