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)
-
+ (MbraoTemplate) instance(force = false)
Returns a unique (singleton) instance of the template handler.
-
+ (Object) register
Register Mbrao into Rails.
Instance Method Summary (collapse)
-
- (String) call(template)
Method called to render a template.
-
- (String) render(renderer, template)
Renders a template into a renderer context.
-
- (TrueClass) supports_streaming?
Declares support for streaming.
Class Method Details
+ (MbraoTemplate) instance(force = false)
Returns a unique (singleton) instance of the template handler.
19 20 21 22 |
# File 'lib/mbrao/integrations/rails.rb', line 19 def self.instance(force = false) @instance = nil if force @instance ||= ActionView::Template::Handlers::MbraoTemplate.new end |
+ (Object) register
Register Mbrao into Rails.
25 26 27 |
# 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 |
Instance Method Details
- (String) call(template)
Method called to render a template.
56 57 58 |
# File 'lib/mbrao/integrations/rails.rb', line 56 def call(template) "ActionView::Template::Handlers::MbraoTemplate.instance.render(self, #{template.source.to_json})" end |
- (String) render(renderer, template)
Renders a template into a renderer context.
34 35 36 37 38 39 40 41 42 43 |
# 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.[:engine], locale: controller.params[:locale]}) end |
- (TrueClass) supports_streaming?
Declares support for streaming.
48 49 50 |
# File 'lib/mbrao/integrations/rails.rb', line 48 def supports_streaming? true end |