Sha256: cd71d42e53f149db5c423362360737bbdb98edc04b0b86cd36ada3a323f18f53

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

describe Curly::Compiler do
  include CompilationSupport

  let(:presenter_class) do
    Class.new(Curly::Presenter) do
      def form(&block)
        "<form>".html_safe + block.call("yo") + "</form>".html_safe
      end

      def invalid
        "uh oh!"
      end
    end
  end

  let(:context_presenter_class) do
    Class.new(Curly::Presenter) do
      presents :form

      def text_field(&block)
        block.call(@form)
      end
    end
  end

  let(:inner_context_presenter_class) do
    Class.new(Curly::Presenter) do
      presents :text_field

      def field
        %(<input type="text" value="#{@text_field.upcase}">).html_safe
      end
    end
  end

  let(:context) { double("context") }
  let(:presenter) { presenter_class.new(context, {}) }

  before do
    stub_const("FormPresenter", context_presenter_class)
    stub_const("TextFieldPresenter", inner_context_presenter_class)
  end

  it "compiles context blocks" do
    evaluate('{{@form}}{{@text_field}}{{field}}{{/text_field}}{{/form}}').should == '<form><input type="text" value="YO"></form>'
  end

  it "fails if the component is not a context block" do
    expect { evaluate('{{@invalid}}yo{{/invalid}}') }.to raise_exception(Curly::Error)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
curly-templates-2.3.1 spec/compiler/context_blocks_spec.rb