Sha256: 57577232da854e54cc92121f5e9aeeeae275ca1e5faf8a273022ded6286d148c

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

module Locomotive
  module Steam
    module Liquid

      module Tags

        class SectionsDropzone < ::Liquid::Tag

          include Concerns::Section

          def parse(tokens)
            notify_on_parsing('_sections_dropzone_', is_dropzone: true)
          end

          def render(context)
            sections_dropzone_content = context['page']&.sections_dropzone_content || []

            html = sections_dropzone_content.each_with_index.map do |content, index|
              # find the liquid source of the section
              section = find_section(context, content['type'])

              next if section.nil? # the section doesn't exist anymore?

              # assign a new dom_id to the section if it doesn't have one
              content['id'] = "dropzone-#{index}"

              # parse the template of the section
              template = build_template(section)

              render_section(context, template, section, content)
            end.join

            %(<div class="locomotive-sections">#{html}</div>)
          end

          private

          def find_section(context, type)
            # TODO: add some cache (useful if there are sections with the same type)
            context.registers[:services].section_finder.find(type)
          end

          def build_template(section)
            # TODO: add some cache here (useful if there are sections with the same type)
            ::Liquid::Template.parse(section.liquid_source, @options)
          end

        end

        ::Liquid::Template.register_tag('sections_dropzone'.freeze, SectionsDropzone)

      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/liquid/tags/sections_dropzone.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/liquid/tags/sections_dropzone.rb