mustache-1.1.1/0000755000004100000410000000000013574653123013364 5ustar www-datawww-datamustache-1.1.1/test/0000755000004100000410000000000013574653123014343 5ustar www-datawww-datamustache-1.1.1/test/partial_test.rb0000644000004100000410000000772013574653123017371 0ustar www-datawww-datarequire_relative 'helper' class PartialTest < Minitest::Test def test_view_partial assert_equal <<-end_partial.strip, PartialWithModule.render

Welcome

Hello Bob You have just won $100000!

Fair enough, right?

end_partial end def test_partial_with_slashes klass = Class.new(Mustache) klass.template = '{{> test/fixtures/inner_partial}}' view = klass.new view[:title] = 'success' assert_equal "Again, success!", view.render end def test_partial_inlining view = Mustache.new :inline_partials_at_compile_time => true view.template = '{{> test/fixtures/inner_partial}}' view[:title] = 'success' # Test the rendered result first assert_equal "Again, success!", view.render # Now the template should be compiled. # There should be no :partial instruction as the partial has been in-lined. assert_equal false, view.template.tokens.flatten.include?(:partial) end def test_view_partial_inherits_context klass = Class.new(TemplatePartial) view = klass.new view.template_path = File.dirname(__FILE__) + '/fixtures' view[:titles] = [{:title => :One}, {:title => :Two}] view.template = <<-end_template

Context Test

end_template assert_equal <<-end_partial, view.render

Context Test

end_partial end def test_view_partial_inherits_context_of_class_methods klass = Class.new(TemplatePartial) klass.template_path = File.dirname(__FILE__) + '/fixtures' klass.send(:define_method, :titles) do [{:title => :One}, {:title => :Two}] end view = klass.new view.template = <<-end_template

Context Test

end_template assert_equal <<-end_partial, view.render

Context Test

end_partial end def test_template_partial assert_equal <<-end_partial.strip, TemplatePartial.render

Welcome

Again, Welcome! end_partial end def test_template_partial_with_custom_extension partial = Class.new(TemplatePartial) partial.template_extension = 'txt' partial.template_path = File.dirname(__FILE__) + '/fixtures' assert_equal <<-end_partial.strip, partial.render.strip Welcome ------- ## Again, Welcome! ## end_partial end def test_recursive_partials assert_equal <<-end_partial, Recursive.render It works! end_partial end def test_crazy_recursive_partials assert_equal <<-end_partial.strip, CrazyRecursive.render end_partial end def test_partials_use_proper_context assert_equal "OuterThing OuterThing", OuterThing.render('{{name}} {{> p}}') assert_equal "InnerThing InnerThing", InnerThing.render('{{name}} {{> p}}') assert_equal "OuterThing InnerThing InnerThing", OuterThing.render('{{name}} {{#inner}}{{name}} {{> p}}{{/inner}}') end def test_partials_render_returned_strings assert_equal "ok", MiddleThing.render('{{> some_partial }}') end end class InnerThing < Mustache def partial(p) self.class end def name; self.class end end class OuterThing < Mustache def inner InnerThing.new end def partial(p) self.class end def name; self.class end end class MiddleThing < Mustache def partial(name) "{{#{name}}}" end def some_partial; "ok" end end mustache-1.1.1/test/mustache_test.rb0000644000004100000410000004717113574653123017552 0ustar www-datawww-data# -*- coding: utf-8 -*- require_relative 'helper' require 'json' class MustacheTest < Minitest::Test def test_instance_render klass = Class.new(Mustache) klass.template = "Hi {{thing}}!" assert_equal "Hi world!", klass.render(:thing => :world) assert_equal "Nice.", klass.render("{{compliment}}.", :compliment => "Nice") assert_equal <<-end_simple, Simple.new.render(:name => "yo", :in_ca => false) Hello yo You have just won $10000! end_simple end def test_passenger assert_equal <<-end_passenger, Passenger.render ServerName example.com DocumentRoot /var/www/example.com RailsEnv production end_passenger end def test_complex_view assert_equal <<-end_complex, ComplexView.render

Colors

end_complex end def test_nested_objects assert_equal <<-end_complex, NestedObjects.render

Colors

end_complex end def test_single_line_sections html = %(

) instance = Mustache.new instance.template = html instance[:no_flash] = true assert_equal %Q'

{{contact}}
{{/contact}}" assert_equal "
Call 1-888-FLOWERS\nAsk for Johnson.
", instance.render end def test_sassy_single_line_sections instance = Mustache.new instance[:full_time] = true instance.template = "\n {{#full_time}}full time{{/full_time}}\n" assert_equal "\n full time\n", instance.render end def test_sassier_single_line_sections instance = Mustache.new instance.template = "\t{{#list}}\r\n\t{{/list}}" assert_equal "", instance.render end def test_padding_before_section instance = Mustache.new instance.template = "\t{{#list}}a{{/list}}" assert_equal "\taa", instance.render(:list => [1, 2]) end def test_padding_before_section_on_eos instance = Mustache.new instance.template = "{{#list}}\n\t{{/list}}" assert_equal "", instance.render(:list => [1, 2]) end def test_two_line_sections html = %(

) instance = Mustache.new instance.template = html instance[:no_flash] = true assert_equal %Q'