Sha256: d24ff7de3a51ebbc8c13aecf799aad7500c1dbeb83974950495056dac3100bd4

Contents?: true

Size: 930 Bytes

Versions: 4

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module Archangel
  ##
  # Template Liquid render service
  #
  class TemplateRenderService < RenderService
    ##
    # Render the Liquid content for template
    #
    # @return [String] the rendered content for template
    #
    def call
      template_content = build_template(template)

      liquid = ::Liquid::Template.parse(template_content)
      liquid.send(liquid_renderer,
                  stringify_assigns,
                  liquid_options).html_safe
    end

    protected

    def build_template(template)
      template_content = current_template_content(template)

      unless /\{\{\s*content_for_layout\s*\}\}/.match?(template_content)
        template_content += "{{ content_for_layout }}"
      end

      template_content
    end

    def current_template_content(template)
      return "{{ content_for_layout }}" if template.blank?

      template.content
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
archangel-0.0.5 app/services/archangel/template_render_service.rb
archangel-0.0.4 app/services/archangel/template_render_service.rb
archangel-0.0.3 app/services/archangel/template_render_service.rb
archangel-0.0.2 app/services/archangel/template_render_service.rb