Module: Hanami::View::Rendering

Defined in:
lib/hanami/view/rendering.rb,
lib/hanami/view/rendering/scope.rb,
lib/hanami/view/rendering/partial.rb,
lib/hanami/view/rendering/registry.rb,
lib/hanami/view/rendering/template.rb,
lib/hanami/view/rendering/null_local.rb,
lib/hanami/view/rendering/null_layout.rb,
lib/hanami/view/rendering/view_finder.rb,
lib/hanami/view/rendering/layout_scope.rb,
lib/hanami/view/rendering/partial_file.rb,
lib/hanami/view/rendering/layout_finder.rb,
lib/hanami/view/rendering/null_template.rb,
lib/hanami/view/rendering/template_name.rb,
lib/hanami/view/rendering/partial_finder.rb,
lib/hanami/view/rendering/layout_registry.rb,
lib/hanami/view/rendering/template_finder.rb,
lib/hanami/view/rendering/templates_finder.rb,
lib/hanami/view/rendering/partial_templates_finder.rb

Overview

Rendering methods

See Also:

Since:

  • 0.1.0

Defined Under Namespace

Modules: InstanceMethods Classes: LayoutFinder, LayoutRegistry, LayoutScope, NullLayout, NullLocal, NullTemplate, Partial, PartialFile, PartialFinder, PartialTemplatesFinder, Registry, Scope, Template, TemplateFinder, TemplateName, TemplatesFinder, ViewFinder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



15
16
17
18
19
# File 'lib/hanami/view/rendering.rb', line 15

def self.extended(base)
  base.class_eval do
    include InstanceMethods
  end
end

Instance Method Details

#render(context) ⇒ String

Render the given context and locals with the appropriate template. If there are registered subclasses, it choose the right class, according

to the requested format.

Examples:

require 'hanami/view'

article = OpenStruct.new(title: 'Hello')

module Articles
  class Show
    include Hanami::View

    def title
      @title ||= article.title.upcase
    end
  end

  class JsonShow < Show
    format :json

    def title
      super.downcase
    end
  end
end

Hanami::View.root = '/path/to/templates'
Hanami::View.load!

Articles::Show.render(format: :html,  article: article)
  # => renders `articles/show.html.erb`

Articles::Show.render(format: :json, article: article)
  # => renders `articles/show.json.erb`

Articles::Show.render(format: :xml, article: article)
  # => raises Hanami::View::MissingTemplateError

Parameters:

  • context (Hash)

    the context for the rendering process

Options Hash (context):

  • :format (Symbol)

    the requested format

Returns:

  • (String)

    the output of the rendering process

Raises:

See Also:

  • Hanami::View#initialize
  • Hanami::View#render

Since:

  • 0.1.0



257
258
259
# File 'lib/hanami/view/rendering.rb', line 257

def render(context)
  registry.resolve(context).render
end