Sha256: 4b62af1e7ca109a7c4b7ee19953f3ca781e63323c30af01ba9d1d47ff4e58ad9

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

require 'test_helper'

class BaseTest < ActiveSupport::TestCase

  class NoLogic < ExpressTemplates::Components::Base
    has_markup -> {
      h1 { span "Some stuff" }
    }
  end

  test ".has_markup makes compile return the block passed through express compiled" do
    assert_equal %Q("<h1><span>Some stuff</span></h1>"), NoLogic.new.compile
  end

  test "components register themselves as macros" do
    assert ExpressTemplates::Expander.instance_methods.include?(:no_logic)
  end

  class Context
    def initialize ; @foo = ['bar', 'baz'] ; end
  end

  test "fragments and has_markup are synonyms for emits" do
    assert_equal NoLogic.method(:emits), NoLogic.method(:fragments)
    assert_equal NoLogic.method(:emits), NoLogic.method(:has_markup)
  end

  class Helpers < ECB
    helper :title_helper, &-> { @foo.first }

    emits -> {
      h1 {
        title_helper
      }
    }

  end

  test "helpers defined in component are evaluated in context" do
    compiled = Helpers.new.compile
    assert_equal "<h1>bar</h1>", Context.new.instance_eval(Interpolator.transform(compiled))
  end

end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
express_admin-1.2.1 vendor/gems/express_templates/test/components/base_test.rb
express_admin-1.2.0 vendor/gems/express_templates/test/components/base_test.rb
express_templates-0.5.0 test/components/base_test.rb
express_templates-0.4.2 test/components/base_test.rb
express_templates-0.4.1 test/components/base_test.rb
express_templates-0.4.0 test/components/base_test.rb
express_templates-0.3.6 test/components/base_test.rb
express_templates-0.3.5 test/components/base_test.rb
express_templates-0.3.4 test/components/base_test.rb
express_templates-0.3.2 test/components/base_test.rb
express_templates-0.3.1 test/components/base_test.rb