6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/phraseapp-in-context-editor-ruby/view_helpers.rb', line 6
def load_in_context_editor(opts = {})
return "" unless PhraseApp::InContextEditor.enabled?
opts = opts.nil? ? {} : opts.each_with_object({}) { |(k, v), conf|
conf[k.to_s] = v
}
configuration = {
"projectId" => PhraseApp::InContextEditor.project_id,
"accountId" => PhraseApp::InContextEditor.account_id,
"datacenter" => PhraseApp::InContextEditor.datacenter,
"prefix" => PhraseApp::InContextEditor.prefix,
"suffix" => PhraseApp::InContextEditor.suffix,
"origin" => PhraseApp::InContextEditor.origin
}.merge(opts)
snippet = <<-EOS
<script nonce='#{content_security_policy_nonce}'>
window.PHRASEAPP_CONFIG = #{configuration.to_json};
(function() {
let phraseapp = document.createElement('script');
phraseapp.type = 'module';
phraseapp.async = true;
phraseapp.src = "https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js";
let script = document.getElementsByTagName('script')[0];
script.parentNode.insertBefore(phraseapp, script);
})();
</script>
EOS
snippet.respond_to?(:html_safe) ? snippet.html_safe : snippet
end
|