Module: ChiliProject::Liquid::LiquidExt::Context::InstanceMethods

Defined in:
lib/chili_project/liquid/liquid_ext/context.rb

Instance Method Summary collapse

Instance Method Details

#cacheable?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/chili_project/liquid/liquid_ext/context.rb', line 51

def cacheable?
  registers.has_key?(:cachable) ? !!registers[:cachable] : true
end

#handle_error_with_formatting(e) ⇒ Object


27
28
29
30
31
32
33
# File 'lib/chili_project/liquid/liquid_ext/context.rb', line 27

def handle_error_with_formatting(e)
  error = handle_error_without_formatting(e)
  escaped_error = registers[:view].send(:h, error) rescue CGI::escapeHTML(error)

  html = '<div class="flash error">' + escaped_error + '</div>'
  html_result(html)
end

#html_result(html) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chili_project/liquid/liquid_ext/context.rb', line 35

def html_result(html)
  key = nil
  while key.nil? || html_results.has_key?(key)
    random = ActiveSupport::SecureRandom.hex(10)
    # This string must be passed untouched through Liquid and textile
    # It mustn't be changed in any way by any rendering stage.
    key = "!!html_results.#{random}!!"
  end
  html_results[key] = html
  key
end

#html_resultsObject


47
48
49
# File 'lib/chili_project/liquid/liquid_ext/context.rb', line 47

def html_results
  registers[:html_results] ||= {}
end

#not_cachable!Object


55
56
57
# File 'lib/chili_project/liquid/liquid_ext/context.rb', line 55

def not_cachable!
  registers[:cachable] = false
end