Class: ActionView::Template::Handlers::MbraoTemplate
- Inherits:
-
Object
- Object
- ActionView::Template::Handlers::MbraoTemplate
- Defined in:
- lib/mbrao/integrations/rails.rb
Overview
Class for rendering mbrao contents in Rails.
Class Method Summary collapse
-
.instance(force = false) ⇒ MbraoTemplate
Returns a unique (singleton) instance of the template handler.
Instance Method Summary collapse
-
#call(template) ⇒ String
Method called to render a template.
-
#render(renderer, template) ⇒ String
Renders a template into a renderer context.
-
#supports_streaming? ⇒ TrueClass
Declares support for streaming.
Class Method Details
.instance(force = false) ⇒ MbraoTemplate
Returns a unique (singleton) instance of the template handler.
15 16 17 18 |
# File 'lib/mbrao/integrations/rails.rb', line 15 def self.instance(force = false) @instance = nil if force @instance ||= ActionView::Template::Handlers::MbraoTemplate.new end |
Instance Method Details
#call(template) ⇒ String
Method called to render a template.
45 46 47 |
# File 'lib/mbrao/integrations/rails.rb', line 45 def call(template) "ActionView::Template::Handlers::MbraoTemplate.instance.render(self, #{template.source.to_json})" end |
#render(renderer, template) ⇒ String
Renders a template into a renderer context.
25 26 27 28 29 30 31 32 |
# File 'lib/mbrao/integrations/rails.rb', line 25 def render(renderer, template) content = ::Mbrao::Parser.parse(template) renderer.controller.instance_variable_set(:@mbrao_content, content) renderer.controller.define_singleton_method(:mbrao_content) { @mbrao_content } renderer.controller.class.send(:helper_method, :mbrao_content) ::Mbrao::Parser.render(content, {engine: content.[:engine], locale: renderer.controller.params[:locale]}) end |
#supports_streaming? ⇒ TrueClass
Declares support for streaming.
37 38 39 |
# File 'lib/mbrao/integrations/rails.rb', line 37 def supports_streaming? true end |