Sha256: 066b4fb776bb465a5b422c1080cc18cdfc66e4d4425f7007f5f83b8f756e4f56
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
require 'musterb/template_handler' require 'ostruct' describe Musterb::TemplateHandler do def compile_template(template, options = {}) template = OpenStruct.new({:source => template, :locals => []}.merge(options)) "output_buffer = nil; " + Musterb::TemplateHandler::call(template) end def evaluate(template, binding, options = {}) binding.eval compile_template(template, options) end it "is wired up correctly" do foo = "hi" evaluate("{{foo}}", binding, :locals => ["foo"]).should eq "hi" end it "renders partials corrects" do compile_template("{{>foo}}").should include "render :partial => 'foo', :locals => {:initial_context => musterb.context}" end it "escapes things by default" do foo = "<br>" evaluate("{{foo}}", binding, :locals => ["foo"]).should eq "<br>" end it "does not escape things in triple staches" do foo = "<br>" evaluate("{{{foo}}}", binding, :locals => ["foo"]).should eq "<br>" end it "can read from instance variables (likely on the controller)" do @foo = "hello" evaluate("{{foo}}", binding).should eq "hello" end it "can be bootstrapped from an initial_context" do initial_context = Musterb::ObjectExtractor.new(2, nil) evaluate("{{to_s}}", binding, :locals => ["initial_context"]).should eq "2" end it "favors locals over instance variables if passed into locals" do @foo = "hello" foo = "bye" evaluate("{{foo}}", binding, :locals => ["foo"]).should eq "bye" end it "can set the initial context to a hash" do mustache = 2 evaluate("{{to_s}}", binding, :locals => ["mustache"]).should eq "2" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
musterb-1.0.1 | spec/musterb/template_handler_spec.rb |