Module: Docit::UI::SystemScript

Defined in:
lib/docit/ui/system_script.rb

Overview

JavaScript for the System Map UI. The script lives in assets/system.js so it can be edited and linted as a real file; it is read once and inlined by SystemRenderer. The only per-render value (the graph endpoint URL) is passed through ‘window.DocitSystem`, set by `config_script` before the script runs.

Constant Summary collapse

JAVASCRIPT =
File.read(File.join(__dir__, "assets", "system.js")).freeze

Class Method Summary collapse

Class Method Details

.config_script(graph_url:) ⇒ Object

Inline config the script reads at startup. Kept tiny and JSON-escaped so a crafted URL cannot break out of the <script> context.



20
21
22
# File 'lib/docit/ui/system_script.rb', line 20

def self.config_script(graph_url:)
  "window.DocitSystem = { graphUrl: #{json_escape(JSON.generate(graph_url))} };"
end

.javascriptObject



14
15
16
# File 'lib/docit/ui/system_script.rb', line 14

def self.javascript
  JAVASCRIPT
end

.json_escape(json_string) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/docit/ui/system_script.rb', line 24

def self.json_escape(json_string)
  json_string.to_s.gsub(/[&<>'\u2028\u2029]/, {
                          "&" => '\u0026',
                          "<" => '\u003c',
                          ">" => '\u003e',
                          "'" => '\u0027',
                          "\u2028" => '\u2028',
                          "\u2029" => '\u2029'
                        })
end