Sha256: 81379fe3053148661eccea2fe9c4cae46007d22a4c8d127f8da96138294ad423

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

Contents

module Locomotive::Steam
  module Middlewares
    class Section < ThreadSafe

      include Concerns::Helpers
      include Concerns::LiquidContext

      def _call
        if section_type = get_section_type
          html = render(section_type)
          render_response(html, 200)
        end
      end

      private

      def get_section_type
        request.get_header('HTTP_LOCOMOTIVE_SECTION_TYPE')
      end

      def render(section_type)
        document = Liquid::Template.parse(liquid_source(section_type))
        document.render(liquid_context)
      end

      def liquid_source(section_type)
        "{% section '#{section_type}' %}"
      end

      def liquid_registers
        super.merge(_section_content: section_content)
      end

      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

      def live_editing?
        true
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/middlewares/section.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/middlewares/section.rb