prauga-flexdoc 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/assets/flexdoc.standalone.css +1 -1
- data/assets/flexdoc.standalone.js +81 -72
- data/lib/prauga/flexdoc/config.rb +34 -0
- data/lib/prauga/flexdoc/host.rb +16 -0
- data/lib/prauga/flexdoc/rack_app.rb +6 -0
- data/lib/prauga/flexdoc/rails.rb +9 -0
- data/lib/prauga/flexdoc/response.rb +3 -0
- data/lib/prauga/flexdoc/version.rb +1 -1
- data/lib/prauga/flexdoc.rb +5 -0
- metadata +2 -2
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
module Prauga
|
|
4
4
|
module FlexDoc
|
|
5
|
+
# FlexDoc renderer configuration.
|
|
6
|
+
#
|
|
7
|
+
# @!attribute [r] path
|
|
8
|
+
# Normalized docs mount path.
|
|
9
|
+
# @!attribute [r] spec_url
|
|
10
|
+
# OpenAPI document URL resolved by the browser bootstrap page.
|
|
11
|
+
# @!attribute [r] title
|
|
12
|
+
# Page and renderer title.
|
|
13
|
+
# @!attribute [r] theme
|
|
14
|
+
# Renderer theme preset: `system`, `light`, or `dark`.
|
|
15
|
+
# @!attribute [r] try_it_enabled
|
|
16
|
+
# Whether the Try It client is enabled.
|
|
17
|
+
# @!attribute [r] expand
|
|
18
|
+
# Optional expansion preset or section list.
|
|
19
|
+
# @!attribute [r] try_it_default_server
|
|
20
|
+
# Optional default server URL for Try It requests.
|
|
21
|
+
# @!attribute [r] try_it_credentials
|
|
22
|
+
# Optional fetch credentials mode: `omit`, `same-origin`, or `include`.
|
|
23
|
+
# @!attribute [r] try_it_api_client_persistence_key
|
|
24
|
+
# Optional persistence key, or `false` to disable.
|
|
25
|
+
# @!attribute [r] try_it_host_execution
|
|
26
|
+
# Emits host-execution protocol metadata; execution is not implemented by this adapter.
|
|
5
27
|
Config = Data.define(
|
|
6
28
|
:path,
|
|
7
29
|
:spec_url,
|
|
@@ -14,6 +36,18 @@ module Prauga
|
|
|
14
36
|
:try_it_api_client_persistence_key,
|
|
15
37
|
:try_it_host_execution
|
|
16
38
|
) do
|
|
39
|
+
# Create a validated configuration.
|
|
40
|
+
#
|
|
41
|
+
# @param path [String] docs mount path
|
|
42
|
+
# @param spec_url [String] OpenAPI document URL
|
|
43
|
+
# @param title [String] page and renderer title
|
|
44
|
+
# @param theme [String] renderer theme preset
|
|
45
|
+
# @param try_it_enabled [Boolean] whether Try It is enabled
|
|
46
|
+
# @param expand [String, Array<String>, nil] optional expansion preset or section list
|
|
47
|
+
# @param try_it_default_server [String, nil] optional default server URL for Try It
|
|
48
|
+
# @param try_it_credentials [String, nil] optional fetch credentials mode
|
|
49
|
+
# @param try_it_api_client_persistence_key [String, false, nil] optional persistence key
|
|
50
|
+
# @param try_it_host_execution [Boolean] emit host-execution protocol metadata; execution is not implemented by this adapter
|
|
17
51
|
def initialize(
|
|
18
52
|
path: "/docs",
|
|
19
53
|
spec_url: "/openapi.json",
|
data/lib/prauga/flexdoc/host.rb
CHANGED
|
@@ -6,11 +6,14 @@ require "json"
|
|
|
6
6
|
|
|
7
7
|
module Prauga
|
|
8
8
|
module FlexDoc
|
|
9
|
+
# Framework-neutral FlexDoc host serving the HTML shell and packaged renderer assets.
|
|
9
10
|
class Host
|
|
10
11
|
IMMUTABLE_CACHE = "public, max-age=31536000, immutable"
|
|
11
12
|
|
|
12
13
|
attr_reader :config, :fingerprint
|
|
13
14
|
|
|
15
|
+
# @param config [Config] renderer and route settings
|
|
16
|
+
# @param assets_dir [String, nil] optional directory overriding bundled renderer assets
|
|
14
17
|
def initialize(config = Config.new, assets_dir: nil)
|
|
15
18
|
@config = config
|
|
16
19
|
root = assets_dir || File.expand_path("../../../assets", __dir__)
|
|
@@ -19,6 +22,10 @@ module Prauga
|
|
|
19
22
|
@fingerprint = Digest::SHA256.hexdigest(@javascript + "\0" + @css)[0, 16]
|
|
20
23
|
end
|
|
21
24
|
|
|
25
|
+
# Match a request path and return the docs shell, renderer asset, or 404 response.
|
|
26
|
+
#
|
|
27
|
+
# @param path [String] request path
|
|
28
|
+
# @return [Response]
|
|
22
29
|
def response_for_path(path)
|
|
23
30
|
return documentation if path == config.path || path == "#{config.path}/"
|
|
24
31
|
return renderer_javascript if path == "#{config.path}/__flexdoc/renderer.js"
|
|
@@ -27,6 +34,9 @@ module Prauga
|
|
|
27
34
|
Response.new(status: 404, content_type: "text/plain; charset=utf-8", body: "Not Found", cache_control: nil)
|
|
28
35
|
end
|
|
29
36
|
|
|
37
|
+
# Build the HTML docs shell response.
|
|
38
|
+
#
|
|
39
|
+
# @return [Response]
|
|
30
40
|
def documentation
|
|
31
41
|
try_it = { enabled: config.try_it_enabled }
|
|
32
42
|
try_it[:defaultServer] = config.try_it_default_server unless config.try_it_default_server.nil?
|
|
@@ -57,10 +67,16 @@ module Prauga
|
|
|
57
67
|
Response.new(status: 200, content_type: "text/html; charset=utf-8", body:, cache_control: "no-cache")
|
|
58
68
|
end
|
|
59
69
|
|
|
70
|
+
# Return the packaged renderer JavaScript asset.
|
|
71
|
+
#
|
|
72
|
+
# @return [Response]
|
|
60
73
|
def renderer_javascript
|
|
61
74
|
Response.new(status: 200, content_type: "application/javascript; charset=utf-8", body: @javascript, cache_control: IMMUTABLE_CACHE)
|
|
62
75
|
end
|
|
63
76
|
|
|
77
|
+
# Return the packaged renderer CSS asset.
|
|
78
|
+
#
|
|
79
|
+
# @return [Response]
|
|
64
80
|
def renderer_css
|
|
65
81
|
Response.new(status: 200, content_type: "text/css; charset=utf-8", body: @css, cache_control: IMMUTABLE_CACHE)
|
|
66
82
|
end
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
module Prauga
|
|
4
4
|
module FlexDoc
|
|
5
|
+
# Rack application that serves FlexDoc routes from a {Host}.
|
|
5
6
|
class RackApp
|
|
7
|
+
# @param host [Host] host backing the Rack application
|
|
6
8
|
def initialize(host = Host.new)
|
|
7
9
|
@host = host
|
|
8
10
|
end
|
|
9
11
|
|
|
12
|
+
# Rack entrypoint.
|
|
13
|
+
#
|
|
14
|
+
# @param env [Hash] Rack environment
|
|
15
|
+
# @return [Array]
|
|
10
16
|
def call(env)
|
|
11
17
|
path = "#{env.fetch("SCRIPT_NAME", "")}#{env.fetch("PATH_INFO", "")}"
|
|
12
18
|
@host.response_for_path(path).rack
|
data/lib/prauga/flexdoc/rails.rb
CHANGED
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
module Prauga
|
|
4
4
|
module FlexDoc
|
|
5
|
+
# Rails routing helpers for mounting {RackApp}.
|
|
5
6
|
module Rails
|
|
6
7
|
module_function
|
|
7
8
|
|
|
9
|
+
# Mount FlexDoc beneath a Rails router.
|
|
10
|
+
#
|
|
11
|
+
# @param mapper [#mount] Rails route mapper, typically `self` inside `routes.rb`
|
|
12
|
+
# @param host [Host] configured FlexDoc host
|
|
13
|
+
# @param at [String, nil] mount path; defaults to `host.config.path`
|
|
14
|
+
# @param as [Symbol] Rails mount name
|
|
15
|
+
# @return [Host] the mounted host
|
|
16
|
+
# @raise [ArgumentError] when `at` does not match `host.config.path`
|
|
8
17
|
def mount(mapper, host: Host.new, at: nil, as: :flexdoc)
|
|
9
18
|
mount_path = at || host.config.path
|
|
10
19
|
normalized_mount_path = Config.new(path: mount_path).path
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Prauga
|
|
4
4
|
module FlexDoc
|
|
5
|
+
# HTTP response produced by {Host}.
|
|
5
6
|
Response = Data.define(:status, :content_type, :body, :cache_control) do
|
|
7
|
+
# @return [Hash{String => String}] Rack-compatible response headers.
|
|
6
8
|
def headers
|
|
7
9
|
result = {
|
|
8
10
|
"content-type" => content_type,
|
|
@@ -12,6 +14,7 @@ module Prauga
|
|
|
12
14
|
result
|
|
13
15
|
end
|
|
14
16
|
|
|
17
|
+
# @return [Array(Integer, Hash{String => String}, Array<String>)] Rack triplet.
|
|
15
18
|
def rack
|
|
16
19
|
[status, headers, [body]]
|
|
17
20
|
end
|
data/lib/prauga/flexdoc.rb
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Self-hosted FlexDoc integration for Rack and Rails applications.
|
|
4
|
+
#
|
|
5
|
+
# Require this file to load {Prauga::FlexDoc::Host}, {Prauga::FlexDoc::RackApp},
|
|
6
|
+
# {Prauga::FlexDoc::Config}, and the Rails mount helper.
|
|
7
|
+
|
|
3
8
|
require_relative "flexdoc/version"
|
|
4
9
|
require_relative "flexdoc/config"
|
|
5
10
|
require_relative "flexdoc/response"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: prauga-flexdoc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Prauga
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|