Module: Hanami::View::Rendering

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

Overview

Rendering methods

See Also:

Since:

  • 0.1.0

Defined Under Namespace

Modules: InstanceMethods Classes: LayoutScope, NullLocal, Scope

Instance Method Summary collapse

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

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