Method: Lotus::View::Rendering#render

Defined in:
lib/lotus/view/rendering.rb

#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 'lotus/view'

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

module Articles
  class Show
    include Lotus::View

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

  class JsonShow < Show
    format :json

    def title
      super.downcase
    end
  end
end

Lotus::View.root = '/path/to/templates'
Lotus::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 Lotus::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:

  • Lotus::View#initialize
  • Lotus::View#render

Since:

  • 0.1.0



235
236
237
# File 'lib/lotus/view/rendering.rb', line 235

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