Module: DocsKit::Controller
- Defined in:
- lib/docs_kit/controller.rb
Overview
Controller glue for a docs site. Include in ApplicationController to get the one shared render helper.
class ApplicationController < ActionController::Base
include DocsKit::Controller
def show = render_page(Views::Landings::Show.new)
end
Instance Method Summary collapse
-
#render_page(view) ⇒ Object
Render a Phlex page that is itself a full HTML document (it composes Docs::Shell, which emits /
/).
Instance Method Details
#render_page(view) ⇒ Object
Render a Phlex page that is itself a full HTML document (it composes Docs::Shell, which emits /
/).layout: false prevents the
Rails ERB application layout from double-nesting . phlex-rails still
renders through a real view context, so CSRF, dom_id, url helpers, and the
phlex-reactive token signer all work inside components.
A .md/.text request instead returns the page's Markdown twin, derived
from the SAME render (DocsKit::MarkdownExport walks the rendered HTML). So
GET /docs/x.md is faithful GFM of exactly what /docs/x shows — the
author writes nothing extra, and the two never drift.
The render runs inside the request's DocsKit::Scope (the version resolved
from params, falling back to the current version), so the
sidebar/meta tags/enumeration all see the version the URL asked for.
render renders synchronously inside the action, so this block wrapper is
sufficient — no around_action, no host code changes. On an unversioned
site the scope is nil: today's behavior exactly.
29 30 31 32 33 34 35 |
# File 'lib/docs_kit/controller.rb', line 29 def render_page(view) DocsKit::Scope.with(version: DocsKit.configuration.resolve_version(params[:version])) do return render_markdown(view) if markdown_request? render view, layout: false end end |