Sha256: ed228464b9e0c9db151e0eec928dfe25ab3ff963347db61dab7804e767b2188e

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

require 'handlebars'
describe(Handlebars) do

  before {extend Handlebars}

  describe "a simple template" do
    let(:t) {compile("Hello {{name}}")}
    it "allows simple subsitution" do
      t.call(:name => 'World').should eql "Hello World"
    end

    it "allows Ruby blocks as a property" do
      t.call(:name => lambda {|context| ;"Mate"}).should eql "Hello Mate"
    end

    it "can use any Ruby object as a context" do
      t.call(mock(:Object, :name => "Flipper")).should eql "Hello Flipper"
    end
  end

  describe "registering Helpers" do
    Handlebars.register_helper('alsowith') do |context, block|
      block.call(context)
    end
    Handlebars.register_helper(:twice) do |block|
      "#{block.call}#{block.call}"
    end

    it "correctly passes context and implementation" do
      t = compile("it's so {{#alsowith weather}}*{{summary}}*{{/alsowith}}!")
      t.call(:weather => {:summary => "sunny"}).should eql "it's so *sunny*!"
    end

    it "doesn't nee a context or arguments to the call" do
      t = compile("{{#twice}}Hurray!{{/twice}}")
      t.call.should eql "Hurray!Hurray!"
    end
  end

  describe "registering Partials" do
    Handlebars.register_partial('futher_info', 'futher information about {{name}}')
    Handlebars.register_partial(:extra_info, 'more info')

    it "render a simple content" do
      t = compile("I have {{> extra_info}}")
      t.call.should eql "I have more info"
    end

    it "render the content using data in context" do
      t = compile("I also know {{> futher_info}}")
      t.call(:name => "John").should eql "I also know futher information about John"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hbs_plus-0.1.3 spec/handlebars_spec.rb