class Confinement::Rendering::ViewContext

Attributes

assets[R]
contents[R]
frontmatter[R]
layouts[R]
locals[R]
routes[R]

Public Class Methods

new(routes:, layouts:, assets:, contents:, locals:, frontmatter:) click to toggle source
# File lib/confinement.rb, line 557
def initialize(routes:, layouts:, assets:, contents:, locals:, frontmatter:)
  @routes = routes
  @layouts = layouts
  @assets = assets
  @contents = contents

  @locals = locals
  @frontmatter = frontmatter
end

Public Instance Methods

capture() { || ... } click to toggle source
# File lib/confinement.rb, line 574
def capture
  original_buffer = @_buf
  @_buf = +""
  yield
  @_buf
ensure
  @_buf = original_buffer
end
render(blob, layout: nil) { || ... } click to toggle source
# File lib/confinement.rb, line 583
def render(blob, layout: nil, &block)
  render_chain = RenderChain.new(
    body: blob.body,
    path: blob.input_path,
    renderers: blob.renderers,
    view_context: self
  )
  rendered_body =
    if block_given?
      render_chain.call do
        capture { yield }
      end
    else
      render_chain.call
    end

  if layout
    layout_render_chain = RenderChain.new(
      body: layout.body,
      path: layout.input_path,
      renderers: layout.renderers,
      view_context: self
    )

    layout_render_chain.call do
      rendered_body
    end
  else
    rendered_body
  end
end