Class: OKF::Server::Graph
- Inherits:
-
Object
- Object
- OKF::Server::Graph
- Defined in:
- lib/okf/server/graph.rb
Overview
Renders an OKF::Bundle::Graph as the interactive graph page served by OKF::Server::App. The markup lives in graph/template.html.erb; #render returns the HTML string.
The page boots from a minimal payload — nodes carry only id + title, plus compact TYPES/TAGS inverted indexes for colouring and filtering. It has two data modes, both driven by one template:
server mode (embed: nil) — the default. Each concept's markdown body,
metadata, catalog, index and log are pulled from OKF::Server::App on
demand via fetch, so the initial payload stays small and bodies read
live from disk (edits show without a restart). Nothing extra embedded.
render mode (embed: payload) — `okf render` bakes the whole bundle in:
the same fetch getters resolve from the injected payload instead, so
the single file needs no server (e.g. hosting on GitHub Pages).
NOTE (trust boundary): the page loads Cytoscape + marked from a CDN, so it needs network for those libraries even in render mode. Fetched/embedded markdown is sanitized client-side (DOMPurify.sanitize(marked.parse(...))) and all inline--escaped by #json_for_script (stdlib ERB does not auto-escape). Still, only serve bundles you trust.
Constant Summary collapse
- TEMPLATE =
File.("graph/template.html.erb", __dir__)
- LAYOUTS =
%w[cose concentric breadthfirst circle grid].freeze
- MIN_SIZE =
Node-diameter range in px; the template scales within it by node degree.
14- MAX_SIZE =
44- LT_ESCAPE =
The 6-character JSON unicode escape for
<(backslash, u, 0, 0, 3, c), built from the backslash code point so no literal escape appears here. (92.chr(Encoding::UTF_8) + "u003c").freeze
Instance Method Summary collapse
-
#initialize(graph, title: nil, link: nil, layout: "cose", node_endpoint: "node", meta_endpoint: "node/meta", embed: nil) ⇒ Graph
constructor
+node_endpoint+/+meta_endpoint+ are the (mount-relative) URLs the page fetches a concept's raw markdown and metadata fragment from — relative so the page works whether served at "/" or mounted under a Rails prefix.
- #render ⇒ Object
Constructor Details
#initialize(graph, title: nil, link: nil, layout: "cose", node_endpoint: "node", meta_endpoint: "node/meta", embed: nil) ⇒ Graph
+node_endpoint+/+meta_endpoint+ are the (mount-relative) URLs the page
fetches a concept's raw markdown and metadata fragment from — relative so
the page works whether served at "/" or mounted under a Rails prefix.
embed is the render-mode payload (nil = server mode); see the class doc.
43 44 45 46 47 48 49 50 51 |
# File 'lib/okf/server/graph.rb', line 43 def initialize(graph, title: nil, link: nil, layout: "cose", node_endpoint: "node", meta_endpoint: "node/meta", embed: nil) @graph = graph @title = title @link = link @layout = layout @node_endpoint = node_endpoint @meta_endpoint = @embed = end |
Instance Method Details
#render ⇒ Object
53 54 55 |
# File 'lib/okf/server/graph.rb', line 53 def render ERB.new(File.read(TEMPLATE, encoding: "UTF-8")).result(binding) end |