module

Plombir::Renderer::Page

Composes one page: Markdown HTML plus a layout source.

Constants

MAX_CHAIN_DEPTH = 10

Maximum layout nesting (post inside default inside …). Chains this deep are always a cycle — see LayoutChainTooDeep.

Class methods

available_layouts(layouts_dir : String) : Array(String)

Returns sorted layout names (default, post, …) for layouts_dir.

Page.available_layouts("layouts") # => ["default", "post"]
Source
component_sources(components_dir : String) : Components

Loads every components/*.html body as a component source (basename → body without frontmatter), mirroring partial_sources. Callers rendering many pages build this once and pass it to render_file.

Page.component_sources("components") # => {"PostCard" => "<article>…"}
Source
partial_sources(layouts_dir : String) : Partials

Loads every layouts/*.html body as an includable partial (basename → body without frontmatter). A layout's layout: parent is ignored here — includes inline the raw body only. Callers rendering many pages build this once and pass it to render_file instead of re-reading the directory per page.

Page.partial_sources("layouts") # => {"header" => "<header>…"}
Source
render(body_html : String, layout_source : String, vars : Context, file : String = "<input>", includes : Partials = Partials.new, components : Components = Components.new, assets : Hash(String, String) = {} of String => String) : String

Renders body_html inside layout_source.

vars holds page fields (title, description, date, …) and any site.* keys. Every top-level key is also visible as page.<key>, and content / page.content always hold body_html. assets is the fingerprinted-asset manifest for | asset_url.

Page.render("<p>Hi.</p>", "<h1>{{ title }}</h1>{{ content }}", {"title" => "Hi"})
Source
render_file(body_html : String, layout_name : String, layouts_dir : String, vars : Context, file : String = "<input>", line : Int32 | Nil = nil, partials : Partials | Nil = nil, components : Components | Nil = nil, assets : Hash(String, String) = {} of String => String) : String

Loads layouts/<layout_name>.html from layouts_dir and renders it. A layout with a frontmatter layout: parent renders inside that parent first (its {{ content }} receives this layout's output), up to MAX_CHAIN_DEPTH. Raises LayoutNotFound listing available_layouts when a link in the chain is absent.

Page.render_file("<p>Hi.</p>", "post", "layouts", {"title" => "Hi"}, "content/a.md")
Source

Nested types