Class: RubyUIAdmin::DocsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ruby_ui_admin/docs_controller.rb

Overview

In-app documentation browser. Renders the gem's bundled docs/*.md files as HTML at <mount>/docs. Availability is controlled by config.docs_enabled (default :local, i.e. development/test only). In local environments it's open (no auth) for convenience; in any other environment (e.g. production, when explicitly enabled) it runs behind the admin's authenticate_admin! gate.

Defined Under Namespace

Classes: MissingDocsDependency

Constant Summary collapse

DOCS_ROOT =

Root of the gem's Markdown documentation.

RubyUIAdmin::Engine.root.join("docs").freeze

Instance Method Summary collapse

Instance Method Details

#showObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/ruby_ui_admin/docs_controller.rb', line 17

def show
  rel = resolve_relative_path(params[:path])
  return head(:not_found) unless rel

  abs = File.expand_path(rel, DOCS_ROOT)
  return head(:not_found) unless safe_doc_path?(abs)

  source = File.read(abs)
  html = render_markdown(source, current_dir: File.dirname(rel))

  render Views::Docs.new(
    body_html: html,
    title: doc_title(source) || humanize_slug(slug_for(rel)),
    nav_groups: nav_groups,
    current_slug: slug_for(rel)
  )
rescue MissingDocsDependency => e
  render Views::Docs.new(
    body_html: dependency_help_html(e.message),
    title: "Documentation",
    nav_groups: [],
    current_slug: nil
  )
end