Sha256: c950ee847589f49119977f267a564901c1a3c0b449bfe6df20705af085fd41e3

Contents?: true

Size: 1.96 KB

Versions: 13

Compression:

Stored size: 1.96 KB

Contents

def render_template(source, context = nil, options = {})
  context ||= ::Liquid::Context.new
  context.exception_renderer = ->(e) do
    # puts e.message # UN-COMMENT IT FOR DEBUGGING
    raise e
  end
  Locomotive::Steam::Liquid::Template.parse(source, options).render(context)
end

def parse_template(source, options = nil)
  ::Liquid::Template.parse(source, options || {})
end

module Liquid

  class TestDrop < Liquid::Drop
    def initialize(source)
      @_source = source.with_indifferent_access
    end

    def liquid_method_missing(meth)
      @_source[meth.to_sym]
    end

    def as_json(options = nil)
      @_source.as_json(options)
    end
  end

  class SimpleEventsListener
    def initialize
      ActiveSupport::Notifications.subscribe(/^steam\.parse\./) do |name, start, finish, id, payload|
        emit(name, payload)
      end
    end
    def emit(name, options = {})
      (@stack ||= []) << [name, options]
    end
    def event_names
      (@stack || []).map { |(name, _)| name }
    end
    def events
      @stack || []
    end
  end

  class LayoutFileSystem
    def read_template_file(template_path, _)
      case template_path
      when "base"
        "<body>base</body>"

      when "inherited"
        "{% extends base %}"

      when "page_with_title"
        "<body><h1>{% block title %}Hello{% endblock %}</h1><p>Lorem ipsum</p></body>"

      when "product"
        "<body><h1>Our product: {{ name }}</h1>{% block info %}{% endblock %}</body>"

      when "product_with_warranty"
        "{% extends product %}{% block info %}<p>mandatory warranty</p>{% endblock %}"

      when "product_with_static_price"
        "{% extends product %}{% block info %}<h2>Some info</h2>{% block price %}<p>$42.00</p>{% endblock %}{% endblock %}"

      else
        template_path
      end
    end
  end
end

def liquid_instance_double(doubled_class, stubs)
  instance_double(doubled_class, stubs).tap do |double|
    allow(double).to receive(:to_liquid).and_return(double)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 spec/support/liquid.rb
locomotivecms_steam-1.8.0.alpha1 spec/support/liquid.rb
locomotivecms_steam-1.7.1 spec/support/liquid.rb
locomotivecms_steam-1.7.0 spec/support/liquid.rb
locomotivecms_steam-1.6.1 spec/support/liquid.rb
locomotivecms_steam-1.6.0 spec/support/liquid.rb
locomotivecms_steam-1.6.0.rc1 spec/support/liquid.rb
locomotivecms_steam-1.6.0.beta1 spec/support/liquid.rb
locomotivecms_steam-1.5.3 spec/support/liquid.rb
locomotivecms_steam-1.5.2 spec/support/liquid.rb
locomotivecms_steam-1.5.1 spec/support/liquid.rb
locomotivecms_steam-1.5.0 spec/support/liquid.rb
locomotivecms_steam-1.5.0.rc1 spec/support/liquid.rb