3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/vega/helper.rb', line 3
def vega_chart(chart, nonce: true)
unless chart.is_a?(Vega::BaseChart) || chart.is_a?(Hash)
raise TypeError, "expected Vega chart or spec"
end
if nonce == true
if respond_to?(:content_security_policy_nonce) && (content_security_policy_nonce rescue nil)
nonce = content_security_policy_nonce
elsif respond_to?(:content_security_policy_script_nonce)
nonce = content_security_policy_script_nonce
else
nonce = nil
end
end
if chart.is_a?(Hash)
Vega.render(chart, nonce: nonce)
else
chart.to_html(nonce: nonce)
end
end
|