Class: Lesmok::Railing::ActionViewHandler
- Inherits:
-
Object
- Object
- Lesmok::Railing::ActionViewHandler
- Defined in:
- lib/lesmok/railing/action_view_handler.rb
Class Method Summary collapse
Instance Method Summary collapse
- #compilable? ⇒ Boolean
-
#initialize(view) ⇒ ActionViewHandler
constructor
A new instance of ActionViewHandler.
- #log_any_liquid_errors(errors, type_str = 'error') ⇒ Object
- #render(template, local_assigns = {}) ⇒ Object
Constructor Details
#initialize(view) ⇒ ActionViewHandler
Returns a new instance of ActionViewHandler.
21 22 23 |
# File 'lib/lesmok/railing/action_view_handler.rb', line 21 def initialize(view) @view = view end |
Class Method Details
.call(template) ⇒ Object
17 18 19 |
# File 'lib/lesmok/railing/action_view_handler.rb', line 17 def self.call(template) "#{self}.new(self).render(#{template.source.inspect}, local_assigns)" end |
.lesmok_options ⇒ Object
13 14 15 |
# File 'lib/lesmok/railing/action_view_handler.rb', line 13 def self. @lesmok_options ||= {} end |
Instance Method Details
#compilable? ⇒ Boolean
69 70 71 |
# File 'lib/lesmok/railing/action_view_handler.rb', line 69 def compilable? false end |
#log_any_liquid_errors(errors, type_str = 'error') ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/lesmok/railing/action_view_handler.rb', line 60 def log_any_liquid_errors(errors, type_str = 'error') return if errors.blank? log = ::Rails.logger log.warn "[Lesmok] Template #{type_str}s (#{errors.size}) detected!" errors.each do |err| log.debug " -- Liquid #{type_str}: #{err}" end end |
#render(template, local_assigns = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lesmok/railing/action_view_handler.rb', line 25 def render(template, local_assigns = {}) @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8' assigns = @view.assigns if @view.content_for?(:layout) assigns["content_for_layout"] = @view.content_for(:layout) end assigns.merge!(local_assigns.stringify_keys) controller = @view.controller filters = if controller.respond_to?(:liquid_filters, true) controller.send(:liquid_filters) elsif controller.respond_to?(:master_helper_module) [controller.master_helper_module] else [controller._helpers] end liquid = ::Liquid::Template.parse(template) render_assigns = assigns.with_indifferent_access render_opts = {:filters => filters, :registers => {:action_view => @view, :controller => @view.controller}} if self.class.[:rethrow_errors] text = liquid.render!(render_assigns, render_opts) else text = liquid.render(render_assigns, render_opts) end if ::Lesmok.config.debugging? log_any_liquid_errors(liquid.errors) log_any_liquid_errors(liquid.warnings, 'warning') end text.html_safe end |