class ActionView::Template::Handlers::MbraoTemplate

Class for rendering mbrao contents in Rails.

Public Class Methods

instance(force = false) click to toggle source

Returns a unique (singleton) instance of the template handler.

@param force [Boolean] If to force recreation of the instance. @return [MbraoTemplate] The unique (singleton) instance of the template handler.

# File lib/mbrao/integrations/rails.rb, line 19
def self.instance(force = false)
  @instance = nil if force
  @instance ||= ActionView::Template::Handlers::MbraoTemplate.new
end
register() click to toggle source

Register Mbrao into Rails.

# File lib/mbrao/integrations/rails.rb, line 25
def self.register
  ActionView::Template.register_template_handler("emt", instance) if defined?(ActionView) && defined?(Rails) && Rails.version =~ /^[34]/
end

Public Instance Methods

call(template) click to toggle source

Method called to render a template.

@param template [ActionView::Template] The template to render. @return [String] A Ruby snippet to execute to render the template.

# File lib/mbrao/integrations/rails.rb, line 56
def call(template)
  "ActionView::Template::Handlers::MbraoTemplate.instance.render(self, #{template.source.to_json})"
end
render(renderer, template) click to toggle source

Renders a template into a renderer context.

@param renderer [Object] The renderer context. @param template [String] The template to render. @return [String] The rendered template.

# File lib/mbrao/integrations/rails.rb, line 34
def render(renderer, template)
  content = ::Mbrao::Parser.parse(template)
  controller = renderer.controller

  controller.instance_variable_set(:@mbrao_content, content)
  controller.define_singleton_method(:mbrao_content) { @mbrao_content }
  controller.class.send(:helper_method, :mbrao_content)

  ::Mbrao::Parser.render(content, {engine: content.metadata[:engine], locale: controller.params[:locale]})
end
supports_streaming?() click to toggle source

Declares support for streaming.

@return [TrueClass] Declares support for streaming.

# File lib/mbrao/integrations/rails.rb, line 48
def supports_streaming?
  true
end