class Locomotive::Steam::Middlewares::Section

Public Instance Methods

_call() click to toggle source
# File lib/locomotive/steam/middlewares/section.rb, line 8
def _call
  if section_type = get_section_type
    html = render(section_type)
    render_response(html, 200)
  end
end

Private Instance Methods

get_section_type() click to toggle source
# File lib/locomotive/steam/middlewares/section.rb, line 17
def get_section_type
  request.get_header('HTTP_LOCOMOTIVE_SECTION_TYPE')
end
liquid_registers() click to toggle source
# File lib/locomotive/steam/middlewares/section.rb, line 30
def liquid_registers
  super.merge(_section_content: section_content)
end
liquid_source(section_type) click to toggle source
# File lib/locomotive/steam/middlewares/section.rb, line 26
def liquid_source(section_type)
  "{% section '#{section_type}' %}"
end
live_editing?() click to toggle source
# File lib/locomotive/steam/middlewares/section.rb, line 46
def live_editing?
  true
end
render(section_type) click to toggle source
# File lib/locomotive/steam/middlewares/section.rb, line 21
def render(section_type)
  document = Liquid::Template.parse(liquid_source(section_type))
  document.render(liquid_context)
end
section_content() click to toggle source
# File lib/locomotive/steam/middlewares/section.rb, line 34
def section_content
  # looks like request.body is not always in the right state,
  # the following statement makes sure of it.
  request.body.rewind

  if (data = request.body.read).present?
    JSON.parse(data)['section_content']
  else
    {}
  end
end