Class: OKF::Server::App

Inherits:
Object
  • Object
show all
Defined in:
lib/okf/server/app.rb

Overview

HTTP access to a bundle's knowledge graph — a Rack app, so it runs under any Rack server (WEBrick, via okf server) and can be mounted in a Rails app:

mount OKF::Server::App.new(folder) => "/knowledge"

The page (OKF::Server::Graph) boots from a minimal graph (id + title + edges

  • type/tag indexes) and pulls each concept's markdown body and description from here on demand, so the initial payload stays small and bodies are read live from disk (edits show without a restart). Part of the shell — it does I/O.

    GET / the interactive graph page (text/html) GET /node?id=… the concept's raw markdown body (text/markdown) GET /node/meta?id=… its description, as an escaped HTML fragment GET /catalog rich per-concept metadata for the catalog/files/stats views: { concepts: [ title, type, description, tags, timestamp, status, area, dir, links_* ] } (JSON) GET /tags the tag index { tag => [id, …] } (JSON) GET /types the type index { type => [id, …] } (JSON) GET /index the §6 progressive-disclosure map for the Index panel: { directories: [ …okf-index rows… ] } (JSON, from the boot snapshot — authored maps are structure) GET /log the §7 history for the Log panel: { logs: [ dir, content ] } (JSON; content read live from disk, like a body — the log is the file that changes most)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder, title: nil, link: nil, layout: "cose", siblings: nil, self_slug: nil, hub_path: nil) ⇒ App

+siblings+/+self_slug+/+hub_path+ are set only when this app is hosted under a hub (OKF::Server::Hub): the other bundles the in-page switcher offers, this bundle's own mount slug, and the hub root. They stay nil for a standalone server and for okf render, so a static file never advertises a switcher.



38
39
40
41
42
43
44
45
46
# File 'lib/okf/server/app.rb', line 38

def initialize(folder, title: nil, link: nil, layout: "cose", siblings: nil, self_slug: nil, hub_path: nil)
  @folder = folder
  @title = title
  @link = link
  @layout = layout
  @siblings = siblings
  @self_slug = self_slug
  @hub_path = hub_path
end

Class Method Details

.not_foundObject

The 404 both this app and the Hub answer with, so the two cannot drift.



73
74
75
# File 'lib/okf/server/app.rb', line 73

def self.not_found
  [ 404, { "content-type" => "text/plain; charset=utf-8" }, [ "not found\n" ] ]
end

Instance Method Details

#call(env) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/okf/server/app.rb', line 48

def call(env)
  request = Rack::Request.new(env)
  return not_found unless request.get?

  case request.path_info
  when "", "/" then respond("text/html; charset=utf-8", page)
  when "/node" then node_body(request.params["id"])
  when "/node/meta" then node_meta(request.params["id"])
  when "/catalog" then respond_json(catalog)
  when "/tags" then respond_json(graph.tag_index)
  when "/types" then respond_json(graph.type_index)
  when "/index" then respond_json(directory_index)
  when "/log" then respond_json(logs)
  else not_found
  end
end

#render_staticObject

The same interactive page, but with the whole bundle baked in — bodies, catalog, index and logs — so it needs no server. This is what okf render writes: the fetch getters resolve from the embedded payload, not from here.



68
69
70
# File 'lib/okf/server/app.rb', line 68

def render_static
  Graph.new(graph, title: @title || @folder.name, link: @link, layout: @layout, embed: embed_payload).render
end