From 80e8a620fdf7da2b0250a4bd9cfd779a46a80a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=BCster?= Date: Thu, 14 Apr 2022 08:38:34 +0200 Subject: [PATCH 01/16] fix(view): prevent firing callbacks until members are destroyed --- packages/blaze/view.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/blaze/view.js b/packages/blaze/view.js index dbf5277c1..097167ceb 100644 --- a/packages/blaze/view.js +++ b/packages/blaze/view.js @@ -489,14 +489,19 @@ Blaze._destroyView = function (view, _skipNodes) { return; view.isDestroyed = true; - Blaze._fireCallbacks(view, 'destroyed'); // Destroy views and elements recursively. If _skipNodes, // only recurse up to views, not elements, for the case where // the backend (jQuery) is recursing over the elements already. - if (view._domrange) - view._domrange.destroyMembers(_skipNodes); + if (view._domrange) view._domrange.destroyMembers(_skipNodes); + + // XXX: fire callbacks after potential members are destroyed + // otherwise it's tracker.flush will cause the above line will + // not be called and their views won't be destroyed + // Involved issues: DOMRange "Must be attached" error, mem leak + + Blaze._fireCallbacks(view, 'destroyed'); }; Blaze._destroyNode = function (node) { From 6e42e5768ea0984582b0eb7ed64f1798ef45cc43 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Thu, 14 Apr 2022 17:35:02 +0200 Subject: [PATCH 02/16] Remove tests for removed API in spacebars, fix #369 --- packages/spacebars-tests/old_templates.js | 2058 ----------- .../spacebars-tests/old_templates_tests.js | 3189 ----------------- packages/spacebars-tests/package.js | 3 - 3 files changed, 5250 deletions(-) delete mode 100644 packages/spacebars-tests/old_templates.js delete mode 100644 packages/spacebars-tests/old_templates_tests.js diff --git a/packages/spacebars-tests/old_templates.js b/packages/spacebars-tests/old_templates.js deleted file mode 100644 index e92edcb87..000000000 --- a/packages/spacebars-tests/old_templates.js +++ /dev/null @@ -1,2058 +0,0 @@ -// This file contains templates compiled with a pre-0.9.0 version of -// spacebars-compiler. We run the entire suite of tests as we had on -// 0.9.0 against these compiled template. The test suits is found -// in old_templates_tests.js -// -// Why? Packages are published in built form. With Meteor 0.9.1, we -// didn't bump the major version of the 'templating' package (which -// would force packages that define templates to publish new versions -// of their package). Instead, we decided to keep backcompat with the -// old Blaze runtime APIs. -// -// If these tests ever break in the future, and backcompat is too hard -// to achieve (or undesirable), we can simply bump the major version -// of the 'templating' package, and get rid of these tests. -Template.__define__("old_spacebars_template_test_aaa", (function() { - var view = this; - return "aaa"; -})); - -Template.__define__("old_spacebars_template_test_bbb", (function() { - var view = this; - return "bbb"; -})); - -Template.__define__("old_spacebars_template_test_bracketed_this", (function() { - var view = this; - return [ "[", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "]" ]; -})); - -Template.__define__("old_spacebars_template_test_span_this", (function() { - var view = this; - return HTML.SPAN(Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - })); -})); - -Template.__define__("old_spacebars_template_test_content", (function() { - var view = this; - return Blaze.InOuterTemplateScope(view, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateContentBlock); - }); - }); -})); - -Template.__define__("old_spacebars_template_test_elsecontent", (function() { - var view = this; - return Blaze.InOuterTemplateScope(view, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateElseBlock); - }); - }); -})); - -Template.__define__("old_spacebars_template_test_iftemplate", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("condition")); - }, function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateContentBlock); - }); - }), "\n " ]; - }, function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateElseBlock); - }); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_simple_helper", (function() { - var view = this; - return Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo"), view.lookup("bar")); - }); -})); - -Template.__define__("old_spacebars_template_test_dynamic_template", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("foo")); -})); - -Template.__define__("old_spacebars_template_test_interpolate_attribute", (function() { - var view = this; - return HTML.DIV({ - "class": function() { - return [ "aaa", Spacebars.mustache(view.lookup("foo"), view.lookup("bar")), "zzz" ]; - } - }); -})); - -Template.__define__("old_spacebars_template_test_dynamic_attrs", (function() { - var view = this; - return HTML.SPAN(HTML.Attrs(function() { - return Spacebars.attrMustache(view.lookup("attrsObj")); - }, function() { - return Spacebars.attrMustache(view.lookup("singleAttr")); - }, function() { - return Spacebars.attrMustache(view.lookup("nonexistent")); - }), "hi"); -})); - -Template.__define__("old_spacebars_template_test_triple", (function() { - var view = this; - return Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html"))); - }); -})); - -Template.__define__("old_spacebars_template_test_triple2", (function() { - var view = this; - return [ "x", Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html"))); - }), Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html2"))); - }), Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html3"))); - }), "y" ]; -})); - -Template.__define__("old_spacebars_template_test_inclusion_args", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return Spacebars.call(view.lookup("bar")); - }, function() { - return Spacebars.include(view.lookupTemplate("foo")); - }); -})); - -Template.__define__("old_spacebars_template_test_inclusion_args2", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return Spacebars.dataMustache(view.lookup("bar"), Spacebars.kw({ - q: view.lookup("baz") - })); - }, function() { - return Spacebars.include(view.lookupTemplate("foo")); - }); -})); - -Template.__define__("old_spacebars_template_test_inclusion_dotted_args", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return Spacebars.call(Spacebars.dot(view.lookup("bar"), "baz")); - }, function() { - return Spacebars.include(view.lookupTemplate("foo")); - }); -})); - -Template.__define__("old_spacebars_template_test_inclusion_slashed_args", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return Spacebars.call(Spacebars.dot(view.lookup("bar"), "baz")); - }, function() { - return Spacebars.include(view.lookupTemplate("foo")); - }); -})); - -Template.__define__("old_spacebars_template_test_block_helper", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("foo"), function() { - return "\n bar\n "; - }, function() { - return "\n baz\n "; - }); -})); - -Template.__define__("old_spacebars_template_test_block_helper_function_one_string_arg", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return "bar"; - }, function() { - return Spacebars.include(view.lookupTemplate("foo"), function() { - return "\n content\n "; - }); - }); -})); - -Template.__define__("old_spacebars_template_test_block_helper_function_one_helper_arg", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return Spacebars.call(view.lookup("bar")); - }, function() { - return Spacebars.include(view.lookupTemplate("foo"), function() { - return "\n content\n "; - }); - }); -})); - -Template.__define__("old_spacebars_template_test_block_helper_component_one_helper_arg", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("bar")); - }, function() { - return "\n content\n "; - }); -})); - -Template.__define__("old_spacebars_template_test_block_helper_component_three_helper_args", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.dataMustache(view.lookup("equals"), view.lookup("bar_or_baz"), "bar"); - }, function() { - return "\n content\n "; - }); -})); - -Template.__define__("old_spacebars_template_test_block_helper_dotted_arg", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return Spacebars.dataMustache(Spacebars.dot(view.lookup("bar"), "baz"), view.lookup("qux")); - }, function() { - return Spacebars.include(view.lookupTemplate("foo"), function() { - return null; - }); - }); -})); - -Template.__define__("old_spacebars_template_test_nested_content", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return { - condition: Spacebars.call(view.lookup("flag")) - }; - }, function() { - return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate"), function() { - return "\n hello\n "; - }, function() { - return "\n world\n "; - }); - }); -})); - -Template.__define__("old_spacebars_template_test_iftemplate2", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return { - condition: Spacebars.call(view.lookup("flag")) - }; - }, function() { - return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate"), function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateContentBlock); - }); - }), "\n " ]; - }, function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateElseBlock); - }); - }), "\n " ]; - }); - }); -})); - -Template.__define__("old_spacebars_template_test_nested_content2", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return { - flag: Spacebars.call(view.lookup("x")) - }; - }, function() { - return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate2"), function() { - return "\n hello\n "; - }, function() { - return "\n world\n "; - }); - }); -})); - -Template.__define__("old_spacebars_template_test_if", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }), "\n " ]; - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("baz")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_if_in_with", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }), "\n ", Blaze.If(function() { - return true; - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }), "\n " ]; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_each", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("items")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("text")); - }), "\n " ]; - }, function() { - return "\n else-clause\n "; - }); -})); - -Template.__define__("old_spacebars_template_test_dots", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n A\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("bar")); - }, function() { - return [ "\n B\n \n ", Blaze.If(function() { - return true; - }, function() { - return [ "\n C\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("items")); - }, function() { - return [ "\n D\n \n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_dots_subtemplate")), "\n ", Spacebars.TemplateWith(function() { - return Spacebars.call(view.lookup("..")); - }, function() { - return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_dots_subtemplate")); - }), "\n " ]; - }), "\n " ]; - }), "\n " ]; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_dots_subtemplate", (function() { - var view = this; - return [ "TITLE\n 1", Blaze.View(function() { - return Spacebars.mustache(view.lookup("title")); - }), "\n 2", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("."), "title")); - }), "\n 3", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "title")); - }), "\n 4", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("..."), "title")); - }), "\n\n GETTITLE\n 5", Blaze.View(function() { - return Spacebars.mustache(view.lookup("getTitle"), view.lookup(".")); - }), "\n 6", Blaze.View(function() { - return Spacebars.mustache(view.lookup("getTitle"), view.lookup("..")); - }), "\n 7", Blaze.View(function() { - return Spacebars.mustache(view.lookup("getTitle"), view.lookup("...")); - }) ]; -})); - -Template.__define__("old_spacebars_template_test_select_tag", (function() { - var view = this; - return HTML.SELECT("\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("optgroups")); - }, function() { - return [ "\n ", HTML.OPTGROUP({ - label: function() { - return Spacebars.mustache(view.lookup("label")); - } - }, "\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return [ "\n ", HTML.OPTION(HTML.Attrs({ - value: function() { - return Spacebars.mustache(view.lookup("value")); - } - }, function() { - return Spacebars.attrMustache(view.lookup("selectedAttr")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("label")); - })), "\n " ]; - }), "\n "), "\n " ]; - }), "\n "); -})); - -Template.__define__("old_test_template_issue770", (function() { - var view = this; - return [ Spacebars.With(function() { - return Spacebars.call(view.lookup("value1")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }, function() { - return "\n xxx\n "; - }), "\n\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("value2")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }, function() { - return "\n xxx\n "; - }), "\n\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("value1")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }), "\n\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("value2")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }) ]; -})); - -Template.__define__("old_spacebars_template_test_tricky_attrs", (function() { - var view = this; - return [ HTML.INPUT({ - type: function() { - return Spacebars.mustache(view.lookup("theType")); - } - }), HTML.INPUT({ - type: "checkbox", - "class": function() { - return Spacebars.mustache(view.lookup("theClass")); - } - }) ]; -})); - -Template.__define__("old_spacebars_template_test_no_data", (function() { - var view = this; - return [ Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("."), "foo")); - }), Blaze.Unless(function() { - return Spacebars.call(Spacebars.dot(view.lookup("."), "bar")); - }, function() { - return "asdf"; - }) ]; -})); - -Template.__define__("old_spacebars_template_test_textarea", (function() { - var view = this; - return HTML.TEXTAREA({ - value: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }); -})); - -Template.__define__("old_spacebars_template_test_textarea2", (function() { - var view = this; - return HTML.TEXTAREA({ - value: function() { - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return ""; - }, function() { - return ""; - }); - } - }); -})); - -Template.__define__("old_spacebars_template_test_textarea3", (function() { - var view = this; - return HTML.TEXTAREA({ - id: "myTextarea", - value: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }); -})); - -Template.__define__("old_spacebars_template_test_textarea_each", (function() { - var view = this; - return HTML.TEXTAREA({ - value: function() { - return Blaze.Each(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ ""; - }); - } - }); -})); - -Template.__define__("old_spacebars_template_test_defer_in_rendered", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("items")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_defer_in_rendered_subtemplate")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_defer_in_rendered_subtemplate", (function() { - var view = this; - return ""; -})); - -Template.__define__("old_spacebars_template_test_with_someData", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("someData")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), " ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_each_stops", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("items")); - }, function() { - return "\n x\n "; - }); -})); - -Template.__define__("old_spacebars_template_test_block_helpers_in_attribute", (function() { - var view = this; - return HTML.DIV({ - "class": function() { - return Blaze.Each(function() { - return Spacebars.call(view.lookup("classes")); - }, function() { - return Blaze.If(function() { - return Spacebars.dataMustache(view.lookup("startsLowerCase"), view.lookup("name")); - }, function() { - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("name")); - }), " " ]; - }); - }, function() { - return "none"; - }); - } - }, "Smurf"); -})); - -Template.__define__("old_spacebars_template_test_block_helpers_in_attribute_2", (function() { - var view = this; - return HTML.INPUT({ - value: function() { - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return '"'; - }, function() { - return [ "&", HTML.CharRef({ - html: "<", - str: "<" - }), ">" ]; - }); - } - }); -})); - -Template.__define__("old_spacebars_template_test_constant_each_argument", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("someData")); - }, function() { - return [ "\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("anArray")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("justReturn"), view.lookup(".")); - }), "\n " ]; - }), "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_markdown_basic", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("obj")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("markdown"), function() { - return [ "\n", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "\n/each}}\n\n", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "\n/each}}\n\n* ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "\n* /each}}\n\n* ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "\n* /each}}\n\nsome paragraph to fix showdown's four space parsing below.\n\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "\n /each}}\n\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "\n /each}}\n\n>\n\n* >\n\n`>`\n\n >\n\n>\n\n* >\n\n`>`\n\n >\n\n`", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "`\n`/each}}`\n\n`", Blaze.View(function() { - return Spacebars.mustache(view.lookup("hi")); - }), "`\n`/each}}`\n\n " ]; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_markdown_if", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("markdown"), function() { - return [ "\n\n", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "\n\n", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "\n\n* ", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "\n\n* ", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "\n\nsome paragraph to fix showdown's four space parsing below.\n\n ", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "\n\n ", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "\n\n`", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "`\n\n`", Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return "true"; - }, function() { - return "false"; - }), "`\n\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_markdown_each", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("markdown"), function() { - return [ "\n\n", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "\n\n", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "\n\n* ", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "\n\n* ", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "\n\nsome paragraph to fix showdown's four space parsing below.\n\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "\n\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "\n\n`", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "`\n\n`", Blaze.Each(function() { - return Spacebars.call(view.lookup("seq")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }), "`\n\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_markdown_inclusion", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("markdown"), function() { - return [ "\n", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_markdown_inclusion_subtmpl")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_markdown_inclusion_subtmpl", (function() { - var view = this; - return HTML.SPAN(Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "Foo is ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), "." ]; - })); -})); - -Template.__define__("old_spacebars_template_test_markdown_block_helpers", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("markdown"), function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_just_content"), function() { - return "\nHi there!\n "; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_just_content", (function() { - var view = this; - return Blaze.InOuterTemplateScope(view, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateContentBlock); - }); - }); -})); - -Template.__define__("old_spacebars_template_test_simple_helpers_are_isolated", (function() { - var view = this; - return Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }); -})); - -Template.__define__("old_spacebars_template_test_attr_helpers_are_isolated", (function() { - var view = this; - return HTML.P({ - attr: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }); -})); - -Template.__define__("old_spacebars_template_test_attr_object_helpers_are_isolated", (function() { - var view = this; - return HTML.P(HTML.Attrs(function() { - return Spacebars.attrMustache(view.lookup("attrs")); - })); -})); - -Template.__define__("old_spacebars_template_test_inclusion_helpers_are_isolated", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("foo")); -})); - -Template.__define__("old_spacebars_template_test_inclusion_helpers_are_isolated_subtemplate", (function() { - var view = this; - return ""; -})); - -Template.__define__("old_spacebars_template_test_nully_attributes0", (function() { - var view = this; - return HTML.Raw(''); -})); - -Template.__define__("old_spacebars_template_test_nully_attributes1", (function() { - var view = this; - return HTML.INPUT({ - type: "checkbox", - checked: function() { - return Spacebars.mustache(view.lookup("foo")); - }, - stuff: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }); -})); - -Template.__define__("old_spacebars_template_test_nully_attributes2", (function() { - var view = this; - return HTML.INPUT({ - type: "checkbox", - checked: function() { - return [ Spacebars.mustache(view.lookup("foo")), Spacebars.mustache(view.lookup("bar")) ]; - }, - stuff: function() { - return [ Spacebars.mustache(view.lookup("foo")), Spacebars.mustache(view.lookup("bar")) ]; - } - }); -})); - -Template.__define__("old_spacebars_template_test_nully_attributes3", (function() { - var view = this; - return HTML.INPUT({ - type: "checkbox", - checked: function() { - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return null; - }); - }, - stuff: function() { - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return null; - }); - } - }); -})); - -Template.__define__("old_spacebars_template_test_double", (function() { - var view = this; - return Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }); -})); - -Template.__define__("old_spacebars_template_test_inclusion_lookup", (function() { - var view = this; - return [ Spacebars.include(view.lookupTemplate("old_spacebars_template_test_inclusion_lookup_subtmpl")), "\n ", Spacebars.include(view.lookupTemplate("dataContextSubtmpl")) ]; -})); - -Template.__define__("old_spacebars_template_test_inclusion_lookup_subtmpl", (function() { - var view = this; - return "This is the template."; -})); - -Template.__define__("old_spacebars_template_test_inclusion_lookup_subtmpl2", (function() { - var view = this; - return "This is generated by a helper with the same name."; -})); - -Template.__define__("old_spacebars_template_test_inclusion_lookup_subtmpl3", (function() { - var view = this; - return "This is a template passed in the data context."; -})); - -Template.__define__("old_spacebars_template_test_content_context", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("bar")); - }, function() { - return [ "\n ", Spacebars.TemplateWith(function() { - return { - condition: Spacebars.call(view.lookup("cond")) - }; - }, function() { - return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate"), function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("firstLetter")); - }), Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "secondLetter")); - }), "\n " ]; - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "firstLetter")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("secondLetter")); - }), "\n " ]; - }); - }), "\n " ]; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_control_input", (function() { - var view = this; - return HTML.INPUT({ - type: function() { - return Spacebars.mustache(view.lookup("type")); - }, - value: function() { - return Spacebars.mustache(view.lookup("value")); - } - }); -})); - -Template.__define__("old_spacebars_test_control_textarea", (function() { - var view = this; - return HTML.TEXTAREA({ - value: function() { - return Spacebars.mustache(view.lookup("value")); - } - }); -})); - -Template.__define__("old_spacebars_test_control_select", (function() { - var view = this; - return HTML.SELECT("\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return [ "\n ", HTML.OPTION({ - selected: function() { - return Spacebars.mustache(view.lookup("selected")); - } - }, Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - })), "\n " ]; - }), "\n "); -})); - -Template.__define__("old_spacebars_test_control_radio", (function() { - var view = this; - return [ "Band:\n\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("bands")); - }, function() { - return [ "\n ", HTML.INPUT({ - name: "bands", - type: "radio", - value: function() { - return Spacebars.mustache(view.lookup(".")); - }, - checked: function() { - return Spacebars.mustache(view.lookup("isChecked")); - } - }), "\n " ]; - }), "\n\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("band")); - }) ]; -})); - -Template.__define__("old_spacebars_test_control_checkbox", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("labels")); - }, function() { - return [ "\n ", HTML.INPUT({ - type: "checkbox", - value: function() { - return Spacebars.mustache(view.lookup(".")); - }, - checked: function() { - return Spacebars.mustache(view.lookup("isChecked")); - } - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_nonexistent_template", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("this_template_lives_in_outer_space")); -})); - -Template.__define__("old_spacebars_test_if_helper", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return "\n true\n "; - }, function() { - return "\n false\n "; - }); -})); - -Template.__define__("old_spacebars_test_block_helper_function", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("foo"), function() { - return "\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_onetwo", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("showOne")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("one")), "\n " ]; - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("two")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_onetwo_attribute", (function() { - var view = this; - return HTML.BR({ - "data-stuff": function() { - return Blaze.If(function() { - return Spacebars.call(view.lookup("showOne")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("one")), "\n " ]; - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("two")), "\n " ]; - }); - } - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_with1", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n one\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_with2", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n two\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_each1", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n one\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_each2", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n two\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_with_each1", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_each3")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_with_each2", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_each3")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_with_each3", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup(".")); - }, function() { - return "\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_if1", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n one\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_if2", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n two\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_inclusion1", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("options")); -})); - -Template.__define__("old_spacebars_test_helpers_stop_inclusion2", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("options")); -})); - -Template.__define__("old_spacebars_test_helpers_stop_inclusion3", (function() { - var view = this; - return "blah"; -})); - -Template.__define__("old_spacebars_test_helpers_stop_with_callbacks1", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_callbacks3")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_with_callbacks2", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_callbacks3")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_with_callbacks3", (function() { - var view = this; - return "blah"; -})); - -Template.__define__("old_spacebars_test_helpers_stop_unless1", (function() { - var view = this; - return Blaze.Unless(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n one\n "; - }); -})); - -Template.__define__("old_spacebars_test_helpers_stop_unless2", (function() { - var view = this; - return Blaze.Unless(function() { - return Spacebars.call(view.lookup("options")); - }, function() { - return "\n two\n "; - }); -})); - -Template.__define__("old_spacebars_test_no_data_context", (function() { - var view = this; - return [ HTML.Raw("\n "), Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }) ]; -})); - -Template.__define__("old_spacebars_test_falsy_with", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("obj")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("greekLetter")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_helpers_dont_leak", (function() { - var view = this; - return Spacebars.TemplateWith(function() { - return { - foo: Spacebars.call("correct") - }; - }, function() { - return Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_dont_leak2")); - }); -})); - -Template.__define__("old_spacebars_test_helpers_dont_leak2", (function() { - var view = this; - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }), " ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_content"), function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup("bonus")); - }); - }) ]; -})); - -Template.__define__("old_spacebars_test_event_returns_false", (function() { - var view = this; - return HTML.Raw('click me'); -})); - -Template.__define__("old_spacebars_test_event_selectors1", (function() { - var view = this; - return HTML.DIV(Spacebars.include(view.lookupTemplate("old_spacebars_test_event_selectors2"))); -})); - -Template.__define__("old_spacebars_test_event_selectors2", (function() { - var view = this; - return HTML.Raw('

Not it

\n

It

'); -})); - -Template.__define__("old_spacebars_test_event_selectors_capturing1", (function() { - var view = this; - return HTML.DIV(Spacebars.include(view.lookupTemplate("old_spacebars_test_event_selectors_capturing2"))); -})); - -Template.__define__("old_spacebars_test_event_selectors_capturing2", (function() { - var view = this; - return HTML.Raw('\n
\n \n
'); -})); - -Template.__define__("old_spacebars_test_tables1", (function() { - var view = this; - return HTML.TABLE(HTML.TR(HTML.TD("Foo"))); -})); - -Template.__define__("old_spacebars_test_tables2", (function() { - var view = this; - return HTML.TABLE(HTML.TR(HTML.TD(Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - })))); -})); - -Template.__define__("old_spacebars_test_jquery_events", (function() { - var view = this; - return HTML.Raw(''); -})); - -Template.__define__("old_spacebars_test_tohtml_basic", (function() { - var view = this; - return Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }); -})); - -Template.__define__("old_spacebars_test_tohtml_if", (function() { - var view = this; - return Blaze.If(function() { - return true; - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_tohtml_with", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_tohtml_each", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("foos")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_tohtml_include_with", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("old_spacebars_test_tohtml_with")); -})); - -Template.__define__("old_spacebars_test_tohtml_include_each", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("old_spacebars_test_tohtml_each")); -})); - -Template.__define__("old_spacebars_test_block_comment", (function() { - var view = this; - return "\n "; -})); - -Template.__define__("old_spacebars_test_with_mutated_data_context", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("value")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_url_attribute", (function() { - var view = this; - return [ HTML.A({ - href: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }), "\n ", HTML.A({ - href: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }), "\n ", HTML.FORM({ - action: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }), "\n ", HTML.IMG({ - src: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }), "\n ", HTML.INPUT({ - value: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }) ]; -})); - -Template.__define__("old_spacebars_test_event_handler_cleanup", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_event_handler_cleanup_sub")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_event_handler_cleanup_sub", (function() { - var view = this; - return HTML.Raw("
"); -})); - -Template.__define__("old_spacebars_test_data_context_for_event_handler_in_if", (function() { - var view = this; - return Spacebars.With(function() { - return { - foo: Spacebars.call("bar") - }; - }, function() { - return [ "\n ", Blaze.If(function() { - return true; - }, function() { - return [ "\n ", HTML.SPAN("Click me!"), "\n " ]; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_each_with_autorun_insert", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("items")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("name")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_ui_hooks", (function() { - var view = this; - return HTML.DIV({ - "class": "test-ui-hooks" - }, "\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("items")); - }, function() { - return [ "\n ", HTML.DIV({ - "class": "item" - }, Blaze.View(function() { - return Spacebars.mustache(view.lookup("_id")); - })), "\n " ]; - }), "\n "); -})); - -Template.__define__("old_spacebars_test_ui_hooks_nested", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_ui_hooks_nested_sub")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_ui_hooks_nested_sub", (function() { - var view = this; - return HTML.DIV("\n ", Spacebars.With(function() { - return true; - }, function() { - return [ "\n ", HTML.P("hello"), "\n " ]; - }), "\n "); -})); - -Template.__define__("old_spacebars_test_template_instance_helper", (function() { - var view = this; - return Spacebars.With(function() { - return true; - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }); - }); -})); - -Template.__define__("old_spacebars_test_with_cleanup", (function() { - var view = this; - return HTML.DIV({ - "class": "test-with-cleanup" - }, "\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }), "\n " ]; - }), "\n "); -})); - -Template.__define__("old_spacebars_test_template_parent_data_helper", (function() { - var view = this; - return Spacebars.With(function() { - return "parent"; - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_template_parent_data_helper_child")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_template_parent_data_helper_child", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("a")); - }, function() { - return [ "\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("b")); - }, function() { - return [ "\n ", Blaze.If(function() { - return Spacebars.call(view.lookup("c")); - }, function() { - return [ "\n ", Spacebars.With(function() { - return "d"; - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), "\n " ]; - }), "\n " ]; - }), "\n " ]; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_svg_anchor", (function() { - var view = this; - return HTML.SVG("\n ", HTML.A({ - "xlink:href": "http://www.example.com" - }, "Foo"), "\n "); -})); - -Template.__define__("old_spacebars_test_template_created_rendered_destroyed_each", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("items")); - }, function() { - return [ "\n ", HTML.DIV(Spacebars.TemplateWith(function() { - return Spacebars.call(view.lookup("_id")); - }, function() { - return Spacebars.include(view.lookupTemplate("old_spacebars_test_template_created_rendered_destroyed_each_sub")); - })), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_template_created_rendered_destroyed_each_sub", (function() { - var view = this; - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); -})); - -Template.__define__("old_spacebars_test_ui_getElementData", (function() { - var view = this; - return HTML.Raw(""); -})); - -Template.__define__("old_spacebars_test_ui_render", (function() { - var view = this; - return HTML.SPAN(Blaze.View(function() { - return Spacebars.mustache(view.lookup("greeting")); - }), " ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("r")); - })); -})); - -Template.__define__("old_spacebars_test_parent_removal", (function() { - var view = this; - return HTML.DIV({ - "class": "a" - }, "\n ", HTML.DIV({ - "class": "b" - }, "\n ", HTML.DIV({ - "class": "toremove" - }, "\n ", HTML.DIV({ - "class": "c" - }, "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("A"), 1); - }), "\n ", Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("A"), 2)); - }), "\n ", Spacebars.With(function() { - return Spacebars.dataMustache(view.lookup("A"), 3); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("A"), 4); - }), "\n ", Spacebars.With(function() { - return Spacebars.dataMustache(view.lookup("A"), 5); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("A"), 6); - }), "\n " ]; - }), "\n " ]; - }), "\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("B")); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("A"), 7); - }), "\n " ]; - }), "\n ", Blaze.If(function() { - return Spacebars.dataMustache(view.lookup("A"), 8); - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("A"), 9); - }), "\n " ]; - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("A"), "a"); - }), "\n " ]; - }), "\n "), "\n "), "\n "), "\n "); -})); - -Template.__define__("old_spacebars_test_focus_blur_outer", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return [ "\n a ", Spacebars.include(view.lookupTemplate("old_spacebars_test_focus_blur_inner")), "\n " ]; - }, function() { - return [ "\n b ", Spacebars.include(view.lookupTemplate("old_spacebars_test_focus_blur_inner")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_focus_blur_inner", (function() { - var view = this; - return HTML.Raw(''); -})); - -Template.__define__("old_spacebars_test_event_cleanup_on_destroyed_outer", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("cond")); - }, function() { - return [ "\n ", HTML.DIV("a ", Spacebars.include(view.lookupTemplate("old_spacebars_test_event_cleanup_on_destroyed_inner"))), "\n " ]; - }, function() { - return [ "\n ", HTML.DIV("b ", Spacebars.include(view.lookupTemplate("old_spacebars_test_event_cleanup_on_destroyed_inner"))), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_event_cleanup_on_destroyed_inner", (function() { - var view = this; - return HTML.Raw("foo"); -})); - -Template.__define__("old_spacebars_test_isolated_lookup_inclusion", (function() { - var view = this; - return "x"; -})); - -Template.__define__("old_spacebars_test_isolated_lookup1", (function() { - var view = this; - return [ Spacebars.include(view.lookupTemplate("foo")), "--", Spacebars.include(view.lookupTemplate("old_spacebars_test_isolated_lookup_inclusion")) ]; -})); - -Template.__define__("old_spacebars_test_isolated_lookup2", (function() { - var view = this; - return Spacebars.With(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", Spacebars.With(function() { - return { - z: Spacebars.call(1) - }; - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("..")), "--", Spacebars.include(view.lookupTemplate("old_spacebars_test_isolated_lookup_inclusion")), "\n " ]; - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_isolated_lookup3", (function() { - var view = this; - return [ Spacebars.include(view.lookupTemplate("bar")), "--", Spacebars.include(view.lookupTemplate("old_spacebars_test_isolated_lookup_inclusion")) ]; -})); - -Template.__define__("old_spacebars_test_current_view_in_event", (function() { - var view = this; - return HTML.SPAN(Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - })); -})); - -Template.__define__("old_spacebars_test_textarea_attrs", (function() { - var view = this; - return HTML.TEXTAREA(HTML.Attrs(function() { - return Spacebars.attrMustache(view.lookup("attrs")); - })); -})); - -Template.__define__("old_spacebars_test_textarea_attrs_contents", (function() { - var view = this; - return HTML.TEXTAREA(HTML.Attrs(function() { - return Spacebars.attrMustache(view.lookup("attrs")); - }, { - value: function() { - return [ "Hello ", Spacebars.mustache(view.lookup("name")) ]; - } - })); -})); - -Template.__define__("old_spacebars_test_textarea_attrs_array_contents", (function() { - var view = this; - return HTML.TEXTAREA(HTML.Attrs({ - "class": "bar" - }, function() { - return Spacebars.attrMustache(view.lookup("attrs")); - }, { - value: function() { - return [ "Hello ", Spacebars.mustache(view.lookup("name")) ]; - } - })); -})); - -Template.__define__("old_spacebars_test_autorun", (function() { - var view = this; - return Blaze.If(function() { - return Spacebars.call(view.lookup("show")); - }, function() { - return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_autorun_inner")), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_autorun_inner", (function() { - var view = this; - return "Hello"; -})); - -Template.__define__("old_spacebars_test_contentBlock_arg", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("old_spacebars_test_contentBlock_arg_inner"), function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("."), "bar")); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_test_contentBlock_arg_inner", (function() { - var view = this; - return Spacebars.With(function() { - return { - foo: Spacebars.call("AAA"), - bar: Spacebars.call("BBB") - }; - }, function() { - return [ "\n ", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("."), "foo")); - }), " ", Blaze.InOuterTemplateScope(view, function() { - return Spacebars.TemplateWith(function() { - return Spacebars.call(view.lookup(".")); - }, function() { - return Spacebars.include(function() { - return Spacebars.call(view.templateContentBlock); - }); - }); - }), "\n " ]; - }); -})); - -Template.__define__("old_spacebars_template_test_input_field_to_same_value", (function() { - var view = this; - return HTML.INPUT({ - type: "text", - value: function() { - return Spacebars.mustache(view.lookup("foo")); - } - }); -})); - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -Template.__define__("old_test_assembly_a0", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("test_assembly_a1")); -})); - -Template.__define__("old_test_assembly_a1", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("test_assembly_a2")); -})); - -Template.__define__("old_test_assembly_a2", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("test_assembly_a3")); -})); - -Template.__define__("old_test_assembly_a3", (function() { - var view = this; - return "Hi"; -})); - -Template.__define__("old_test_assembly_b0", (function() { - var view = this; - return Spacebars.include(view.lookupTemplate("test_assembly_b1")); -})); - -Template.__define__("old_test_assembly_b1", (function() { - var view = this; - return [ "x", Blaze.If(function() { - return Spacebars.call(view.lookup("stuff")); - }, function() { - return "y"; - }), Spacebars.include(view.lookupTemplate("test_assembly_b2")) ]; -})); - -Template.__define__("old_test_assembly_b2", (function() { - var view = this; - return "hi"; -})); - -Template.__define__("old_test_table_b0", (function() { - var view = this; - return HTML.TABLE("\n ", HTML.TBODY("\n ", Spacebars.include(view.lookupTemplate("test_table_b1")), "\n ", Spacebars.include(view.lookupTemplate("test_table_b1")), "\n ", Spacebars.include(view.lookupTemplate("test_table_b1")), "\n "), "\n "); -})); - -Template.__define__("old_test_table_b1", (function() { - var view = this; - return HTML.TR("\n ", Spacebars.include(view.lookupTemplate("test_table_b2")), "\n "); -})); - -Template.__define__("old_test_table_b2", (function() { - var view = this; - return HTML.TD("\n ", Spacebars.include(view.lookupTemplate("test_table_b3")), "\n "); -})); - -Template.__define__("old_test_table_b3", (function() { - var view = this; - return "Foo."; -})); - -Template.__define__("old_test_table_each", (function() { - var view = this; - return HTML.TABLE("\n ", HTML.TBODY("\n ", Blaze.Each(function() { - return Spacebars.call(view.lookup("foo")); - }, function() { - return [ "\n ", HTML.TR(HTML.TD(Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }))), "\n " ]; - }), "\n "), "\n "); -})); - -Template.__define__("old_test_event_data_with", (function() { - var view = this; - return HTML.DIV("\n xxx\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("TWO")); - }, function() { - return [ "\n ", HTML.DIV("\n xxx\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("THREE")); - }, function() { - return [ "\n ", HTML.DIV("\n xxx\n "), "\n " ]; - }), "\n "), "\n " ]; - }), "\n"); -})); - -Template.__define__("old_test_capture_events", (function() { - var view = this; - return HTML.Raw('\n \n '); -})); - -Template.__define__("old_test_safestring_a", (function() { - var view = this; - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), " ", Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("foo"))); - }), " ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }), " ", Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("bar"))); - }), "\n ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("fooprop")); - }), " ", Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("fooprop"))); - }), " ", Blaze.View(function() { - return Spacebars.mustache(view.lookup("barprop")); - }), " ", Blaze.View(function() { - return Spacebars.makeRaw(Spacebars.mustache(view.lookup("barprop"))); - }) ]; -})); - -Template.__define__("old_test_helpers_a", (function() { - var view = this; - return [ "platypus=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("platypus")); - }), "\n watermelon=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("watermelon")); - }), "\n daisy=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("daisy")); - }), "\n tree=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("tree")); - }), "\n warthog=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("warthog")); - }) ]; -})); - -Template.__define__("old_test_helpers_b", (function() { - var view = this; - return [ "unknown=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("unknown")); - }), "\n zero=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("zero")); - }) ]; -})); - -Template.__define__("old_test_helpers_c", (function() { - var view = this; - return [ "platypus.X=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("platypus"), "X")); - }), "\n watermelon.X=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("watermelon"), "X")); - }), "\n daisy.X=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("daisy"), "X")); - }), "\n tree.X=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("tree"), "X")); - }), "\n warthog.X=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("warthog"), "X")); - }), "\n getNull.X=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("getNull"), "X")); - }), "\n getUndefined.X=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("getUndefined"), "X")); - }), "\n getUndefined.X.Y=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("getUndefined"), "X", "Y")); - }) ]; -})); - -Template.__define__("old_test_helpers_d", (function() { - var view = this; - return [ "daisygetter=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("daisygetter")); - }), "\n thisTest=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("thisTest")); - }), "\n ", Spacebars.With(function() { - return Spacebars.call(view.lookup("fancy")); - }, function() { - return [ "\n ../thisTest=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "thisTest")); - }), "\n " ]; - }), "\n ", Spacebars.With(function() { - return "foo"; - }, function() { - return [ "\n ../fancy.currentFruit=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "fancy", "currentFruit")); - }), "\n " ]; - }) ]; -})); - -Template.__define__("old_test_helpers_e", (function() { - var view = this; - return [ "fancy.foo=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "foo")); - }), "\n fancy.apple.banana=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "apple", "banana")); - }), "\n fancy.currentFruit=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentFruit")); - }), "\n fancy.currentCountry.name=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentCountry", "name")); - }), "\n fancy.currentCountry.population=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentCountry", "population")); - }), "\n fancy.currentCountry.unicorns=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentCountry", "unicorns")); - }) ]; -})); - -Template.__define__("old_test_helpers_f", (function() { - var view = this; - return [ "fancyhelper.foo=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "foo")); - }), "\n fancyhelper.apple.banana=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "apple", "banana")); - }), "\n fancyhelper.currentFruit=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentFruit")); - }), "\n fancyhelper.currentCountry.name=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "name")); - }), "\n fancyhelper.currentCountry.population=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "population")); - }), "\n fancyhelper.currentCountry.unicorns=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns")); - }) ]; -})); - -Template.__define__("old_test_helpers_g", (function() { - var view = this; - return [ "platypus=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("platypus")); - }), "\n this.platypus=", Blaze.View(function() { - return Spacebars.mustache(Spacebars.dot(view.lookup("."), "platypus")); - }) ]; -})); - -Template.__define__("old_test_helpers_h", (function() { - var view = this; - return [ "(methodListFour 6 7 8 9=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("methodListFour"), 6, 7, 8, 9); - }), ")\n (methodListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("methodListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns")); - }), ")\n (methodListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns a=platypus b=thisTest c=fancyhelper.currentFruit d=fancyhelper.currentCountry.unicorns=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("methodListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns"), Spacebars.kw({ - a: view.lookup("platypus"), - b: view.lookup("thisTest"), - c: Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), - d: Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns") - })); - }), ")\n (helperListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("helperListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns")); - }), ")\n (helperListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns a=platypus b=thisTest c=fancyhelper.currentFruit d=fancyhelper.currentCountry.unicorns=", Blaze.View(function() { - return Spacebars.mustache(view.lookup("helperListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns"), Spacebars.kw({ - a: view.lookup("platypus"), - b: view.lookup("thisTest"), - c: Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), - d: Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns") - })); - }), ")" ]; -})); - -Template.__define__("old_test_render_a", (function() { - var view = this; - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), HTML.Raw("

") ]; -})); - -Template.__define__("old_test_render_b", (function() { - var view = this; - return Spacebars.With(function() { - return 200; - }, function() { - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), HTML.BR(), HTML.HR() ]; - }); -})); - -Template.__define__("old_test_render_c", (function() { - var view = this; - return HTML.Raw("

"); -})); - -Template.__define__("old_test_template_arg_a", (function() { - var view = this; - return HTML.Raw("Foo Bar Baz"); -})); - -Template.__define__("old_test_template_helpers_a", (function() { - var view = this; - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("foo")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("bar")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("baz")); - }) ]; -})); - -Template.__define__("old_test_template_helpers_b", (function() { - var view = this; - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("name")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("arity")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("toString")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("length")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("var")); - }) ]; -})); - -Template.__define__("old_test_template_helpers_c", (function() { - var view = this; - return [ Blaze.View(function() { - return Spacebars.mustache(view.lookup("name")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("arity")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("length")); - }), Blaze.View(function() { - return Spacebars.mustache(view.lookup("var")); - }), "x" ]; -})); - -Template.__define__("old_test_template_events_a", (function() { - var view = this; - return HTML.Raw("foobarbaz"); -})); - -Template.__define__("old_test_template_events_b", (function() { - var view = this; - return HTML.Raw("foobarbaz"); -})); - -Template.__define__("old_test_template_events_c", (function() { - var view = this; - return HTML.Raw("foobarbaz"); -})); - -Template.__define__("old_test_type_casting", (function() { - var view = this; - return Blaze.View(function() { - return Spacebars.mustache(view.lookup("testTypeCasting"), "true", "false", true, false, 0, 1, -1, 10, -10); - }); -})); - -Template.__define__("old_test_template_issue801", (function() { - var view = this; - return Blaze.Each(function() { - return Spacebars.call(view.lookup("values")); - }, function() { - return Blaze.View(function() { - return Spacebars.mustache(view.lookup(".")); - }); - }); -})); - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/packages/spacebars-tests/old_templates_tests.js b/packages/spacebars-tests/old_templates_tests.js deleted file mode 100644 index aa0afc8ec..000000000 --- a/packages/spacebars-tests/old_templates_tests.js +++ /dev/null @@ -1,3189 +0,0 @@ -// -// This file is used to ensure old built templates still work with the -// new Blaze APIs. More in a comment at the top of old_templates.js -// - -var divRendersTo = function (test, div, html) { - Tracker.flush({ _throwFirstError: true }); - var actual = canonicalizeHtml(div.innerHTML); - test.equal(actual, html); -}; - -var nodesToArray = function (array) { - return Array.from(array); -}; - -Tinytest.add( - 'spacebars-tests - old - template_tests - simple helper', - function (test) { - var tmpl = Template.old_spacebars_template_test_simple_helper; - var R = ReactiveVar(1); - tmpl.foo = function (x) { - return x + R.get(); - }; - tmpl.bar = function () { - return 123; - }; - var div = renderToDiv(tmpl); - - test.equal(canonicalizeHtml(div.innerHTML), '124'); - R.set(2); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '125'); - - // Test that `{{foo bar}}` throws if `foo` is missing or not a function. - tmpl.foo = 3; - test.throws(function () { - renderToDiv(tmpl); - }, /Can't call non-function/); - - delete tmpl.foo; - test.throws(function () { - renderToDiv(tmpl); - }, /No such function/); - - tmpl.foo = function () {}; - // doesn't throw - div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), ''); - - // now "foo" is a function in the data context - delete tmpl.foo; - - R = ReactiveVar(1); - div = renderToDiv(tmpl, { - foo: function (x) { - return x + R.get(); - }, - }); - test.equal(canonicalizeHtml(div.innerHTML), '124'); - R.set(2); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '125'); - - test.throws(function () { - renderToDiv(tmpl, { foo: 3 }); - }, /Can't call non-function/); - - test.throws(function () { - renderToDiv(tmpl, { foo: null }); - }, /No such function/); - - test.throws(function () { - renderToDiv(tmpl, {}); - }, /No such function/); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - dynamic template', - function (test) { - var tmpl = Template.old_spacebars_template_test_dynamic_template; - var aaa = Template.old_spacebars_template_test_aaa; - var bbb = Template.old_spacebars_template_test_bbb; - var R = ReactiveVar('aaa'); - tmpl.foo = function () { - return R.get() === 'aaa' ? aaa : bbb; - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'aaa'); - - R.set('bbb'); - Tracker.flush(); - - test.equal(canonicalizeHtml(div.innerHTML), 'bbb'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - interpolate attribute', - function (test) { - var tmpl = Template.old_spacebars_template_test_interpolate_attribute; - tmpl.foo = function (x) { - return x + 1; - }; - tmpl.bar = function () { - return 123; - }; - var div = renderToDiv(tmpl); - - test.equal($(div).find('div')[0].className, 'aaa124zzz'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - dynamic attrs', - function (test) { - var tmpl = Template.old_spacebars_template_test_dynamic_attrs; - - var R2 = ReactiveVar({ x: 'X' }); - var R3 = ReactiveVar('selected'); - tmpl.attrsObj = function () { - return R2.get(); - }; - tmpl.singleAttr = function () { - return R3.get(); - }; - - var div = renderToDiv(tmpl); - var span = $(div).find('span')[0]; - test.equal(span.innerHTML, 'hi'); - test.isTrue(span.hasAttribute('selected')); - test.equal(span.getAttribute('x'), 'X'); - - R2.set({ y: 'Y', z: 'Z' }); - R3.set(''); - Tracker.flush(); - test.equal(canonicalizeHtml(span.innerHTML), 'hi'); - test.isFalse(span.hasAttribute('selected')); - test.isFalse(span.hasAttribute('x')); - test.equal(span.getAttribute('y'), 'Y'); - test.equal(span.getAttribute('z'), 'Z'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - triple', - function (test) { - var tmpl = Template.old_spacebars_template_test_triple; - - var R = ReactiveVar('blah'); - tmpl.html = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - var elems = $(div).find('> *'); - test.equal(elems.length, 1); - test.equal(elems[0].nodeName, 'SPAN'); - var span = elems[0]; - test.equal(span.className, 'hi'); - test.equal(span.innerHTML, 'blah'); - - R.set('asdf'); - Tracker.flush(); - elems = $(div).find('> *'); - test.equal(elems.length, 0); - test.equal(canonicalizeHtml(div.innerHTML), 'asdf'); - - R.set('blah'); - Tracker.flush(); - elems = $(div).find('> *'); - test.equal(elems.length, 1); - test.equal(elems[0].nodeName, 'SPAN'); - span = elems[0]; - test.equal(span.className, 'hi'); - test.equal(canonicalizeHtml(span.innerHTML), 'blah'); - - var tmpl = Template.old_spacebars_template_test_triple2; - tmpl.html = function () {}; - tmpl.html2 = function () { - return null; - }; - // no tmpl.html3 - div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'xy'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - inclusion args', - function (test) { - var tmpl = Template.old_spacebars_template_test_inclusion_args; - - var R = ReactiveVar(Template.old_spacebars_template_test_aaa); - tmpl.foo = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - // `{{> foo bar}}`, with `foo` resolving to Template.aaa, - // which consists of "aaa" - test.equal(canonicalizeHtml(div.innerHTML), 'aaa'); - R.set(Template.old_spacebars_template_test_bbb); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'bbb'); - - ////// Ok, now `foo` *is* Template.aaa - tmpl.foo = Template.old_spacebars_template_test_aaa; - div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'aaa'); - - ////// Ok, now `foo` is a template that takes an argument; bar is a string. - tmpl.foo = Template.old_spacebars_template_test_bracketed_this; - tmpl.bar = 'david'; - div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), '[david]'); - - ////// Now `foo` is a template that takes an arg; bar is a function. - tmpl.foo = Template.old_spacebars_template_test_span_this; - R = ReactiveVar('david'); - tmpl.bar = function () { - return R.get(); - }; - div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'david'); - var span1 = div.querySelector('span'); - R.set('avi'); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'avi'); - var span2 = div.querySelector('span'); - test.isTrue(span1 === span2); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - inclusion args 2', - function (test) { - // `{{> foo bar q=baz}}` - var tmpl = Template.old_spacebars_template_test_inclusion_args2; - - tmpl.foo = Template.old_spacebars_template_test_span_this; - tmpl.bar = function (options) { - return options.hash.q; - }; - - var R = ReactiveVar('david!'); - tmpl.baz = function () { - return R.get().slice(0, 5); - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'david'); - var span1 = div.querySelector('span'); - R.set('brillo'); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'brill'); - var span2 = div.querySelector('span'); - test.isTrue(span1 === span2); - } -); - -// maybe use created callback on the template instead of this? -var extendTemplateWithInit = function (template, initFunc) { - var tmpl = new Template( - template.viewName + '-extended', - template.renderFunction - ); - tmpl.constructView = function (/*args*/) { - var view = Template.prototype.constructView.apply(this, arguments); - initFunc(view); - return view; - }; - return tmpl; -}; - -Tinytest.add( - 'spacebars-tests - old - template_tests - inclusion dotted args', - function (test) { - // `{{> foo bar.baz}}` - var tmpl = Template.old_spacebars_template_test_inclusion_dotted_args; - - var initCount = 0; - tmpl.foo = extendTemplateWithInit( - Template.old_spacebars_template_test_bracketed_this, - function () { - initCount++; - } - ); - - var R = ReactiveVar('david'); - tmpl.bar = function () { - // make sure `this` is bound correctly - return { baz: this.symbol + R.get() }; - }; - - var div = renderToDiv(tmpl, { symbol: '%' }); - test.equal(initCount, 1); - test.equal(canonicalizeHtml(div.innerHTML), '[%david]'); - - R.set('avi'); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '[%avi]'); - // check that invalidating the argument to `foo` doesn't require - // creating a new `foo`. - test.equal(initCount, 1); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - inclusion slashed args', - function (test) { - // `{{> foo bar/baz}}` - var tmpl = Template.old_spacebars_template_test_inclusion_dotted_args; - - var initCount = 0; - tmpl.foo = extendTemplateWithInit( - Template.old_spacebars_template_test_bracketed_this, - function () { - initCount++; - } - ); - var R = ReactiveVar('david'); - tmpl.bar = function () { - // make sure `this` is bound correctly - return { baz: this.symbol + R.get() }; - }; - - var div = renderToDiv(tmpl, { symbol: '%' }); - test.equal(initCount, 1); - test.equal(canonicalizeHtml(div.innerHTML), '[%david]'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block helper', - function (test) { - // test the case where `foo` is a calculated template that changes - // reactively. - // `{{#foo}}bar{{else}}baz{{/foo}}` - var tmpl = Template.old_spacebars_template_test_block_helper; - var R = ReactiveVar(Template.old_spacebars_template_test_content); - tmpl.foo = function () { - return R.get(); - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'bar'); - - R.set(Template.old_spacebars_template_test_elsecontent); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'baz'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block helper function with one string arg', - function (test) { - // `{{#foo "bar"}}content{{/foo}}` - var tmpl = - Template.old_spacebars_template_test_block_helper_function_one_string_arg; - tmpl.foo = function () { - if (String(this) === 'bar') - return Template.old_spacebars_template_test_content; - else return null; - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'content'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block helper function with one helper arg', - function (test) { - var tmpl = - Template.old_spacebars_template_test_block_helper_function_one_helper_arg; - var R = ReactiveVar('bar'); - tmpl.bar = function () { - return R.get(); - }; - tmpl.foo = function () { - if (String(this) === 'bar') - return Template.old_spacebars_template_test_content; - else return null; - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'content'); - - R.set('baz'); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), ''); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block helper component with one helper arg', - function (test) { - var tmpl = - Template.old_spacebars_template_test_block_helper_component_one_helper_arg; - var R = ReactiveVar(true); - tmpl.bar = function () { - return R.get(); - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'content'); - - R.set(false); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), ''); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block helper component with three helper args', - function (test) { - var tmpl = - Template.old_spacebars_template_test_block_helper_component_three_helper_args; - var R = ReactiveVar('bar'); - tmpl.bar_or_baz = function () { - return R.get(); - }; - tmpl.equals = function (x, y) { - return x === y; - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'content'); - - R.set('baz'); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), ''); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block helper with dotted arg', - function (test) { - var tmpl = Template.old_spacebars_template_test_block_helper_dotted_arg; - var R1 = ReactiveVar(1); - var R2 = ReactiveVar(10); - var R3 = ReactiveVar(100); - - var initCount = 0; - tmpl.foo = extendTemplateWithInit( - Template.old_spacebars_template_test_bracketed_this, - function () { - initCount++; - } - ); - tmpl.bar = function () { - return { - r1: R1.get(), - baz: function (r3) { - return this.r1 + R2.get() + r3; - }, - }; - }; - tmpl.qux = function () { - return R3.get(); - }; - - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), '[111]'); - test.equal(initCount, 1); - - R1.set(2); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '[112]'); - test.equal(initCount, 1); - - R2.set(20); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '[122]'); - test.equal(initCount, 1); - - R3.set(200); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '[222]'); - test.equal(initCount, 1); - - R2.set(30); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '[232]'); - test.equal(initCount, 1); - - R1.set(3); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '[233]'); - test.equal(initCount, 1); - - R3.set(300); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '[333]'); - test.equal(initCount, 1); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - nested content', - function (test) { - // Test that `{{> UI.contentBlock}}` in an `{{#if}}` works. - - // ``` - // - // ``` - - // ``` - // {{#spacebars_template_test_iftemplate flag}} - // hello - // {{else}} - // world - // {{/spacebars_template_test_iftemplate}} - // ``` - - var tmpl = Template.old_spacebars_template_test_nested_content; - var R = ReactiveVar(true); - tmpl.flag = function () { - return R.get(); - }; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'hello'); - R.set(false); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'world'); - R.set(true); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'hello'); - - // Also test that `{{> UI.contentBlock}}` in a custom block helper works. - tmpl = Template.old_spacebars_template_test_nested_content2; - R = ReactiveVar(true); - tmpl.x = function () { - return R.get(); - }; - div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'hello'); - R.set(false); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'world'); - R.set(true); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'hello'); - } -); - -Tinytest.add('spacebars-tests - old - template_tests - if', function (test) { - var tmpl = Template.old_spacebars_template_test_if; - var R = ReactiveVar(true); - tmpl.foo = function () { - return R.get(); - }; - tmpl.bar = 1; - tmpl.baz = 2; - - var div = renderToDiv(tmpl); - var rendersTo = function (html) { - divRendersTo(test, div, html); - }; - - rendersTo('1'); - R.set(false); - rendersTo('2'); -}); - -Tinytest.add( - 'spacebars-tests - old - template_tests - if in with', - function (test) { - var tmpl = Template.old_spacebars_template_test_if_in_with; - tmpl.foo = { bar: 'bar' }; - - var div = renderToDiv(tmpl); - divRendersTo(test, div, 'bar bar'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - each on cursor', - function (test) { - var tmpl = Template.old_spacebars_template_test_each; - var coll = new Mongo.Collection(null); - tmpl.items = function () { - return coll.find({}, { sort: { pos: 1 } }); - }; - - var div = renderToDiv(tmpl); - var rendersTo = function (html) { - divRendersTo(test, div, html); - }; - - rendersTo('else-clause'); - coll.insert({ text: 'one', pos: 1 }); - rendersTo('one'); - coll.insert({ text: 'two', pos: 2 }); - rendersTo('one two'); - coll.update({ text: 'two' }, { $set: { text: 'three' } }); - rendersTo('one three'); - coll.update({ text: 'three' }, { $set: { pos: 0 } }); - rendersTo('three one'); - coll.remove({}); - rendersTo('else-clause'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - each on array', - function (test) { - var tmpl = Template.old_spacebars_template_test_each; - var R = new ReactiveVar([]); - tmpl.items = function () { - return R.get(); - }; - tmpl.text = function () { - return this; - }; - - var div = renderToDiv(tmpl); - var rendersTo = function (html) { - divRendersTo(test, div, html); - }; - - rendersTo('else-clause'); - R.set(['']); - rendersTo(''); - R.set(['x', '', 'toString']); - rendersTo('x toString'); - R.set(['toString']); - rendersTo('toString'); - R.set([]); - rendersTo('else-clause'); - R.set([0, 1, 2]); - rendersTo('0 1 2'); - R.set([]); - rendersTo('else-clause'); - } -); - -Tinytest.add('spacebars-tests - old - template_tests - ..', function (test) { - var tmpl = Template.old_spacebars_template_test_dots; - Template.old_spacebars_template_test_dots_subtemplate.getTitle = function ( - from - ) { - return from.title; - }; - - tmpl.foo = { title: 'foo' }; - tmpl.foo.bar = { title: 'bar' }; - tmpl.foo.bar.items = [{ title: 'item' }]; - var div = renderToDiv(tmpl); - - test.equal( - canonicalizeHtml(div.innerHTML), - [ - 'A', - 'B', - 'C', - 'D', - // {{> spacebars_template_test_dots_subtemplate}} - 'TITLE', - '1item', - '2item', - '3bar', - '4foo', - 'GETTITLE', - '5item', - '6bar', - '7foo', - // {{> spacebars_template_test_dots_subtemplate ..}} - 'TITLE', - '1bar', - '2bar', - '3item', - '4bar', - 'GETTITLE', - '5bar', - '6item', - '7bar', - ].join(' ') - ); -}); - -Tinytest.add( - 'spacebars-tests - old - template_tests - select tags', - function (test) { - var tmpl = Template.old_spacebars_template_test_select_tag; - - // {label: (string)} - var optgroups = new Mongo.Collection(null); - - // {optgroup: (id), value: (string), selected: (boolean), label: (string)} - var options = new Mongo.Collection(null); - - tmpl.optgroups = function () { - return optgroups.find(); - }; - tmpl.options = function () { - return options.find({ optgroup: this._id }); - }; - tmpl.selectedAttr = function () { - return this.selected ? { selected: true } : {}; - }; - - var div = renderToDiv(tmpl); - var selectEl = $(div).find('select')[0]; - - // returns canonicalized contents of `div` in the form eg - // [""]. strip out selected attributes -- we - // verify correctness by observing the `selected` property - var divContent = function () { - return canonicalizeHtml( - div.innerHTML.replace(/selected="[^"]*"/g, '').replace(/selected/g, '') - ) - .replace(/\>\s*\\n<') - .split('\n'); - }; - - test.equal(divContent(), ['']); - - var optgroup1 = optgroups.insert({ label: 'one' }); - var optgroup2 = optgroups.insert({ label: 'two' }); - test.equal(divContent(), [ - '', - ]); - - options.insert({ - optgroup: optgroup1, - value: 'value1', - selected: false, - label: 'label1', - }); - options.insert({ - optgroup: optgroup1, - value: 'value2', - selected: true, - label: 'label2', - }); - test.equal(divContent(), [ - '', - ]); - test.equal(selectEl.value, 'value2'); - test.equal($(selectEl).find('option')[0].selected, false); - test.equal($(selectEl).find('option')[1].selected, true); - - // swap selection - options.update({ value: 'value1' }, { $set: { selected: true } }); - options.update({ value: 'value2' }, { $set: { selected: false } }); - Tracker.flush(); - - test.equal(divContent(), [ - '', - ]); - test.equal(selectEl.value, 'value1'); - test.equal($(selectEl).find('option')[0].selected, true); - test.equal($(selectEl).find('option')[1].selected, false); - - // change value and label - options.update({ value: 'value1' }, { $set: { value: 'value1.0' } }); - options.update({ value: 'value2' }, { $set: { label: 'label2.0' } }); - Tracker.flush(); - - test.equal(divContent(), [ - '', - ]); - test.equal(selectEl.value, 'value1.0'); - test.equal($(selectEl).find('option')[0].selected, true); - test.equal($(selectEl).find('option')[1].selected, false); - - // unselect and then select both options. normally, the second is - // selected (since it got selected later). then switch to '.slice(0, 30) - ); - - R.set('bar'); - Tracker.flush(); - test.equal( - canonicalizeHtml(div.innerHTML), - '' - ); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - no data context', - function (test) { - var tmpl = Template.old_spacebars_template_test_no_data; - - // failure is if an exception is thrown here - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'asdf'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - textarea', - function (test) { - var tmpl = Template.old_spacebars_template_test_textarea; - - var R = ReactiveVar('hello'); - - tmpl.foo = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - var textarea = div.querySelector('textarea'); - test.equal(textarea.value, 'hello'); - - R.set('world'); - Tracker.flush(); - test.equal(textarea.value, 'world'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - textarea 2', - function (test) { - var tmpl = Template.old_spacebars_template_test_textarea2; - - var R = ReactiveVar(true); - - tmpl.foo = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - var textarea = div.querySelector('textarea'); - test.equal(textarea.value, '
'); - - R.set(false); - Tracker.flush(); - test.equal(textarea.value, ''); - - R.set(true); - Tracker.flush(); - test.equal(textarea.value, ''); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - textarea 3', - function (test) { - var tmpl = Template.old_spacebars_template_test_textarea3; - - var R = ReactiveVar('hello'); - - tmpl.foo = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - var textarea = div.querySelector('textarea'); - test.equal(textarea.id, 'myTextarea'); - test.equal(textarea.value, 'hello'); - - R.set('world'); - Tracker.flush(); - test.equal(textarea.value, 'world'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - textarea each', - function (test) { - var tmpl = Template.old_spacebars_template_test_textarea_each; - - var R = ReactiveVar(['APPLE', 'BANANA']); - - tmpl.foo = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - var textarea = div.querySelector('textarea'); - test.equal(textarea.value, ''); - - R.set(['CUCUMBER']); - Tracker.flush(); - test.equal(textarea.value, 'Smurf') result = '
Smurf
'; // e.g. IE 9 and 10 - test.equal(result, '
Smurf
'); - }; - - shouldBe('donut frankfurter noodle'); - coll.remove({ name: 'frankfurter' }); // (it was kind of a mouthful) - shouldBe('donut noodle'); - coll.remove({ name: 'donut' }); - shouldBe('noodle'); - coll.remove({ name: 'noodle' }); - shouldBe(''); // 'David' and 'Steve' appear in the #each but fail the #if - coll.remove({}); - shouldBe('none'); // now the `{{else}}` case kicks in - coll.insert({ name: 'bubblegum' }); - shouldBe('bubblegum'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block helpers in attribute 2', - function (test) { - var tmpl = - Template.old_spacebars_template_test_block_helpers_in_attribute_2; - - var R = ReactiveVar(true); - - tmpl.foo = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - var input = div.querySelector('input'); - - test.equal(input.value, '"'); - R.set(false); - Tracker.flush(); - test.equal(input.value, '&<>'); - } -); - -// Test that if the argument to #each is a constant, it doesn't establish a -// dependency on the data context, so when the context changes, items of -// the #each are not "changed" and helpers do not rerun. -Tinytest.add( - 'spacebars-tests - old - template_tests - constant #each argument', - function (test) { - var tmpl = Template.old_spacebars_template_test_constant_each_argument; - - var justReturnRuns = 0; // how many times `justReturn` is called - var R = ReactiveVar(1); - - tmpl.someData = function () { - return R.get(); - }; - tmpl.anArray = ['foo', 'bar']; - tmpl.justReturn = function (x) { - justReturnRuns++; - return String(x); - }; - - var div = renderToDiv(tmpl); - - test.equal(justReturnRuns, 2); - test.equal( - canonicalizeHtml(div.innerHTML).replace(/\s+/g, ' '), - 'foo bar 1' - ); - - R.set(2); - Tracker.flush(); - - test.equal(justReturnRuns, 2); // still 2, no new runs! - test.equal( - canonicalizeHtml(div.innerHTML).replace(/\s+/g, ' '), - 'foo bar 2' - ); - } -); - -Tinytest.addAsync( - 'spacebars-tests - old - template_tests - #markdown - basic', - function (test, onComplete) { - var tmpl = Template.old_spacebars_template_test_markdown_basic; - tmpl.obj = { snippet: 'hi' }; - tmpl.hi = function () { - return this.snippet; - }; - var div = renderToDiv(tmpl); - - Meteor.call('getAsset', 'markdown_basic.html', function (err, html) { - test.isFalse(err); - test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(html)); - onComplete(); - }); - } -); - -testAsyncMulti('spacebars-tests - old - template_tests - #markdown - if', [ - function (test, expect) { - var self = this; - Meteor.call( - 'getAsset', - 'markdown_if1.html', - expect(function (err, html) { - test.isFalse(err); - self.html1 = html; - }) - ); - Meteor.call( - 'getAsset', - 'markdown_if2.html', - expect(function (err, html) { - test.isFalse(err); - self.html2 = html; - }) - ); - }, - - function (test, expect) { - var self = this; - var tmpl = Template.old_spacebars_template_test_markdown_if; - var R = new ReactiveVar(false); - tmpl.cond = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html1)); - R.set(true); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html2)); - }, -]); - -testAsyncMulti('spacebars-tests - old - template_tests - #markdown - each', [ - function (test, expect) { - var self = this; - Meteor.call( - 'getAsset', - 'markdown_each1.html', - expect(function (err, html) { - test.isFalse(err); - self.html1 = html; - }) - ); - Meteor.call( - 'getAsset', - 'markdown_each2.html', - expect(function (err, html) { - test.isFalse(err); - self.html2 = html; - }) - ); - }, - - function (test, expect) { - var self = this; - var tmpl = Template.old_spacebars_template_test_markdown_each; - var R = new ReactiveVar([]); - tmpl.seq = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html1)); - - R.set(['item']); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html2)); - }, -]); - -Tinytest.add( - 'spacebars-tests - old - template_tests - #markdown - inclusion', - function (test) { - var tmpl = Template.old_spacebars_template_test_markdown_inclusion; - var subtmpl = - Template.old_spacebars_template_test_markdown_inclusion_subtmpl; - subtmpl.foo = 'bar'; - var div = renderToDiv(tmpl); - test.equal( - canonicalizeHtml(div.innerHTML), - '

Foo is bar.

' - ); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - #markdown - block helpers', - function (test) { - var tmpl = Template.old_spacebars_template_test_markdown_block_helpers; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), '

Hi there!

'); - } -); - -// Test that when a simple helper re-runs due to a dependency changing -// but the return value is the same, the DOM text node is not -// re-rendered. -Tinytest.add( - 'spacebars-tests - old - template_tests - simple helpers are isolated', - function (test) { - var runs = [ - { - helper: function () { - return 'foo'; - }, - nodeValue: 'foo', - }, - { - helper: function () { - return new Spacebars.SafeString('bar'); - }, - nodeValue: 'bar', - }, - ]; - - runs.forEach(function (run) { - var tmpl = - Template.old_spacebars_template_test_simple_helpers_are_isolated; - var dep = new Tracker.Dependency(); - tmpl.foo = function () { - dep.depend(); - return run.helper(); - }; - var div = renderToDiv(tmpl); - var fooTextNode = Array.from(div.childNodes).find(function (node) { - return node.nodeValue === run.nodeValue; - }); - - test.isTrue(fooTextNode); - - dep.changed(); - Tracker.flush(); - var newFooTextNode = Array.from(div.childNodes).find(function (node) { - return node.nodeValue === run.nodeValue; - }); - - test.equal(fooTextNode, newFooTextNode); - }); - } -); - -// Test that when a helper in an element attribute re-runs due to a -// dependency changing but the return value is the same, the attribute -// value is not set. -Tinytest.add( - 'spacebars-tests - old - template_tests - attribute helpers are isolated', - function (test) { - var tmpl = Template.old_spacebars_template_test_attr_helpers_are_isolated; - var dep = new Tracker.Dependency(); - tmpl.foo = function () { - dep.depend(); - return 'foo'; - }; - var div = renderToDiv(tmpl); - var pElement = div.querySelector('p'); - - test.equal(pElement.getAttribute('attr'), 'foo'); - - // set the attribute to something else, afterwards check that it - // hasn't been updated back to the correct value. - pElement.setAttribute('attr', 'not-foo'); - dep.changed(); - Tracker.flush(); - test.equal(pElement.getAttribute('attr'), 'not-foo'); - } -); - -// A helper can return an object with a set of element attributes via -// `

`. When it re-runs due to a dependency changing the -// value for a given attribute might stay the same. Test that the -// attribute is not set on the DOM element. -Tinytest.add( - 'spacebars-tests - old - template_tests - attribute object helpers are isolated', - function (test) { - var tmpl = - Template.old_spacebars_template_test_attr_object_helpers_are_isolated; - var dep = new Tracker.Dependency(); - tmpl.attrs = function () { - dep.depend(); - return { foo: 'bar' }; - }; - var div = renderToDiv(tmpl); - var pElement = div.querySelector('p'); - - test.equal(pElement.getAttribute('foo'), 'bar'); - - // set the attribute to something else, afterwards check that it - // hasn't been updated back to the correct value. - pElement.setAttribute('foo', 'not-bar'); - dep.changed(); - Tracker.flush(); - test.equal(pElement.getAttribute('foo'), 'not-bar'); - } -); - -// Test that when a helper in an inclusion directive (`{{> foo }}`) -// re-runs due to a dependency changing but the return value is the -// same, the template is not re-rendered. -// -// Also, verify that an error is thrown if the return value from such -// a helper is not a component. -Tinytest.add( - 'spacebars-tests - old - template_tests - inclusion helpers are isolated', - function (test) { - var tmpl = - Template.old_spacebars_template_test_inclusion_helpers_are_isolated; - var dep = new Tracker.Dependency(); - var subtmpl = - Template.old_spacebars_template_test_inclusion_helpers_are_isolated_subtemplate; - // make a copy so we can set "rendered" without mutating the original - var subtmplCopy = new Template(subtmpl.viewName, subtmpl.renderFunction); - - var R = new ReactiveVar(subtmplCopy); - tmpl.foo = function () { - dep.depend(); - return R.get(); - }; - - var div = renderToDiv(tmpl); - subtmplCopy.rendered = function () { - test.fail("shouldn't re-render when same value returned from helper"); - }; - - dep.changed(); - Tracker.flush({ _throwFirstError: true }); // `subtmplCopy.rendered` not called - - R.set(null); - Tracker.flush({ _throwFirstError: true }); // no error thrown - - R.set('neither a component nor null'); - - test.throws(function () { - Tracker.flush({ _throwFirstError: true }); - }, /Expected template or null/); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - nully attributes', - function (test) { - var tmpls = { - 0: Template.old_spacebars_template_test_nully_attributes0, - 1: Template.old_spacebars_template_test_nully_attributes1, - 2: Template.old_spacebars_template_test_nully_attributes2, - 3: Template.old_spacebars_template_test_nully_attributes3, - 4: Template.old_spacebars_template_test_nully_attributes4, - 5: Template.old_spacebars_template_test_nully_attributes5, - 6: Template.old_spacebars_template_test_nully_attributes6, - }; - - var run = function (whichTemplate, data, expectTrue) { - var div = renderToDiv(tmpls[whichTemplate], data); - var input = div.querySelector('input'); - var descr = JSON.stringify([whichTemplate, data, expectTrue]); - if (expectTrue) { - test.isTrue(input.checked, descr); - test.equal(typeof input.getAttribute('stuff'), 'string', descr); - } else { - test.isFalse(input.checked); - test.equal(JSON.stringify(input.getAttribute('stuff')), 'null', descr); - } - - var html = Blaze.toHTML( - Blaze.With(data, function () { - return tmpls[whichTemplate]; - }) - ); - - test.equal(/ checked="[^"]*"/.test(html), !!expectTrue); - test.equal(/ stuff="[^"]*"/.test(html), !!expectTrue); - }; - - run(0, {}, true); - - var truthies = [true, '']; - var falsies = [false, null, undefined]; - - truthies.forEach(function (x) { - run(1, { foo: x }, true); - }); - falsies.forEach(function (x) { - run(1, { foo: x }, false); - }); - - truthies.forEach(function (x) { - truthies.forEach(function (y) { - run(2, { foo: x, bar: y }, true); - }); - falsies.forEach(function (y) { - run(2, { foo: x, bar: y }, true); - }); - }); - falsies.forEach(function (x) { - truthies.forEach(function (y) { - run(2, { foo: x, bar: y }, true); - }); - falsies.forEach(function (y) { - run(2, { foo: x, bar: y }, false); - }); - }); - - run(3, { foo: true }, false); - run(3, { foo: false }, false); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - double', - function (test) { - var tmpl = Template.old_spacebars_template_test_double; - - var run = function (foo, expectedResult) { - tmpl.foo = foo; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), expectedResult); - }; - - run('asdf', 'asdf'); - run(1.23, '1.23'); - run(0, '0'); - run(true, 'true'); - run(false, ''); - run(null, ''); - run(undefined, ''); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - inclusion lookup order', - function (test) { - // test that {{> foo}} looks for a helper named 'foo', then a - // template named 'foo', then a 'foo' field in the data context. - var tmpl = Template.old_spacebars_template_test_inclusion_lookup; - var tmplData = function () { - return { - // shouldn't have an effect since we define a helper with the - // same name. - old_spacebars_template_test_inclusion_lookup_subtmpl: - Template.old_spacebars_template_test_inclusion_lookup_subtmpl3, - dataContextSubtmpl: - Template.old_spacebars_template_test_inclusion_lookup_subtmpl3, - }; - }; - - tmpl.old_spacebars_template_test_inclusion_lookup_subtmpl = - Template.old_spacebars_template_test_inclusion_lookup_subtmpl2; - - test.equal( - canonicalizeHtml(renderToDiv(tmpl, tmplData).innerHTML), - [ - 'This is generated by a helper with the same name.', - 'This is a template passed in the data context.', - ].join(' ') - ); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - content context', - function (test) { - var tmpl = Template.old_spacebars_template_test_content_context; - var R = ReactiveVar(true); - tmpl.foo = { - firstLetter: 'F', - secondLetter: 'O', - bar: { - cond: function () { - return R.get(); - }, - firstLetter: 'B', - secondLetter: 'A', - }, - }; - - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'BO'); - R.set(false); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'FA'); - } -); - -[ - 'textarea', - 'text', - 'password', - 'submit', - 'button', - 'reset', - 'select', - 'hidden', -].forEach(function (type) { - Tinytest.add( - 'spacebars-tests - old - template_tests - controls - ' + type, - function (test) { - var R = ReactiveVar({ x: 'test' }); - var R2 = ReactiveVar(''); - var tmpl; - - if (type === 'select') { - tmpl = Template.old_spacebars_test_control_select; - tmpl.options = [ - 'This is a test', - 'This is a fridge', - 'This is a frog', - 'This is a new frog', - 'foobar', - 'This is a photograph', - 'This is a monkey', - 'This is a donkey', - ]; - tmpl.selected = function () { - R2.get(); // Re-render when R2 is changed, even though it - // doesn't affect HTML. - return 'This is a ' + R.get().x === this.toString(); - }; - } else if (type === 'textarea') { - tmpl = Template.old_spacebars_test_control_textarea; - tmpl.value = function () { - R2.get(); // Re-render when R2 is changed, even though it - // doesn't affect HTML. - return 'This is a ' + R.get().x; - }; - } else { - tmpl = Template.old_spacebars_test_control_input; - tmpl.value = function () { - R2.get(); // Re-render when R2 is changed, even though it - // doesn't affect HTML. - return 'This is a ' + R.get().x; - }; - tmpl.type = type; - } - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - var canFocus = type !== 'hidden'; - - // find first element child, ignoring any marker nodes - var input = div.firstChild; - while (input.nodeType !== 1) input = input.nextSibling; - - if (type === 'textarea' || type === 'select') { - test.equal(input.nodeName, type.toUpperCase()); - } else { - test.equal(input.nodeName, 'INPUT'); - test.equal(input.type, type); - } - test.equal(DomUtils.getElementValue(input), 'This is a test'); - - // value updates reactively - R.set({ x: 'fridge' }); - Tracker.flush(); - test.equal(DomUtils.getElementValue(input), 'This is a fridge'); - - if (canFocus) { - // ...if focused, it still updates but focus isn't lost. - focusElement(input); - DomUtils.setElementValue(input, 'something else'); - R.set({ x: 'frog' }); - - Tracker.flush(); - test.equal(DomUtils.getElementValue(input), 'This is a frog'); - test.equal(document.activeElement, input); - } - - // Setting a value (similar to user typing) should prevent value from being - // reverted if the div is re-rendered but the rendered value (ie, R) does - // not change. - DomUtils.setElementValue(input, 'foobar'); - R2.set('change'); - Tracker.flush(); - test.equal(DomUtils.getElementValue(input), 'foobar'); - - // ... but if the actual rendered value changes, that should take effect. - R.set({ x: 'photograph' }); - Tracker.flush(); - test.equal(DomUtils.getElementValue(input), 'This is a photograph'); - - document.body.removeChild(div); - } - ); -}); - -Tinytest.add('spacebars-tests - old - template_tests - radio', function (test) { - var R = ReactiveVar(''); - var R2 = ReactiveVar(''); - var change_buf = []; - var tmpl = Template.old_spacebars_test_control_radio; - tmpl.bands = ['AM', 'FM', 'XM']; - tmpl.isChecked = function () { - return R.get() === this.toString(); - }; - tmpl.band = function () { - return R.get(); - }; - tmpl.events({ - 'change input': function (event) { - var btn = event.target; - var band = btn.value; - change_buf.push(band); - R.set(band); - }, - }); - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - - // get the three buttons; they should not change identities! - var btns = nodesToArray(div.getElementsByTagName('INPUT')); - var text = function () { - var text = div.innerText || div.textContent; - return text.replace(/[ \n\r]+/g, ' ').replace(/^\s+|\s+$/g, ''); - }; - - test.equal(btns.map(x => x.checked), [false, false, false]); - test.equal(text(), 'Band:'); - - clickIt(btns[0]); - test.equal(change_buf, ['AM']); - change_buf.length = 0; - Tracker.flush(); - test.equal(btns.map(x => x.checked), [true, false, false]); - test.equal(text(), 'Band: AM'); - - R2.set('change'); - Tracker.flush(); - test.length(change_buf, 0); - test.equal(btns.map(x => x.checked), [true, false, false]); - test.equal(text(), 'Band: AM'); - - clickIt(btns[1]); - test.equal(change_buf, ['FM']); - change_buf.length = 0; - Tracker.flush(); - test.equal(btns.map(x => x.checked), [false, true, false]); - test.equal(text(), 'Band: FM'); - - clickIt(btns[2]); - test.equal(change_buf, ['XM']); - change_buf.length = 0; - Tracker.flush(); - test.equal(btns.map(x => x.checked), [false, false, true]); - test.equal(text(), 'Band: XM'); - - clickIt(btns[1]); - test.equal(change_buf, ['FM']); - change_buf.length = 0; - Tracker.flush(); - test.equal(btns.map(x => x.checked), [false, true, false]); - test.equal(text(), 'Band: FM'); - - document.body.removeChild(div); -}); - -Tinytest.add( - 'spacebars-tests - old - template_tests - checkbox', - function (test) { - var tmpl = Template.old_spacebars_test_control_checkbox; - tmpl.labels = ['Foo', 'Bar', 'Baz']; - var Rs = {}; - tmpl.labels.forEach(function (label) { - Rs[label] = ReactiveVar(false); - }); - tmpl.isChecked = function () { - return Rs[this.toString()].get(); - }; - var changeBuf = []; - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - - var boxes = nodesToArray(div.getElementsByTagName('INPUT')); - - test.equal(boxes.map(x => x.checked), [false, false, false]); - - // Re-render with first one checked. - Rs.Foo.set(true); - Tracker.flush(); - test.equal(boxes.map(x => x.checked), [true, false, false]); - - // Re-render with first one unchecked again. - Rs.Foo.set(false); - Tracker.flush(); - test.equal(boxes.map(x => x.checked), [false, false, false]); - - // User clicks the second one. - clickElement(boxes[1]); - test.equal(boxes.map(x => x.checked), [false, true, false]); - Tracker.flush(); - test.equal(boxes.map(x => x.checked), [false, true, false]); - - // Re-render with third one checked. Second one should stay checked because - // it's a user update! - Rs.Baz.set(true); - Tracker.flush(); - test.equal(boxes.map(x => x.checked), [false, true, true]); - - // User turns second and third off. - clickElement(boxes[1]); - clickElement(boxes[2]); - test.equal(boxes.map(x => x.checked), [false, false, false]); - Tracker.flush(); - test.equal(boxes.map(x => x.checked), [false, false, false]); - - // Re-render with first one checked. Third should stay off because it's a user - // update! - Rs.Foo.set(true); - Tracker.flush(); - test.equal(boxes.map(x => x.checked), [true, false, false]); - - // Re-render with first one unchecked. Third should still stay off. - Rs.Foo.set(false); - Tracker.flush(); - test.equal(boxes.map(x => x.checked), [false, false, false]); - - document.body.removeChild(div); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - unfound template', - function (test) { - test.throws(function () { - renderToDiv(Template.old_spacebars_test_nonexistent_template); - }, /No such template/); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - helper passed to #if called exactly once when invalidated', - function (test) { - var tmpl = Template.old_spacebars_test_if_helper; - - var count = 0; - var d = new Tracker.Dependency(); - tmpl.foo = function () { - d.depend(); - count++; - return foo; - }; - - foo = false; - var div = renderToDiv(tmpl); - divRendersTo(test, div, 'false'); - test.equal(count, 1); - - foo = true; - d.changed(); - divRendersTo(test, div, 'true'); - test.equal(count, 2); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - custom block helper functions called exactly once when invalidated', - function (test) { - var tmpl = Template.old_spacebars_test_block_helper_function; - - var count = 0; - var d = new Tracker.Dependency(); - tmpl.foo = function () { - d.depend(); - count++; - return Template.old_spacebars_template_test_aaa; - }; - - foo = false; - renderToDiv(tmpl); - Tracker.flush(); - test.equal(count, 1); - - foo = true; - d.changed(); - Tracker.flush(); - test.equal(count, 2); - } -); - -var runOneTwoTest = function (test, subTemplateName, optionsData) { - [ - Template.old_spacebars_test_helpers_stop_onetwo, - Template.old_spacebars_test_helpers_stop_onetwo_attribute, - ].forEach(function (tmpl) { - tmpl.one = Template[subTemplateName + '1']; - tmpl.two = Template[subTemplateName + '2']; - - var buf = ''; - - var showOne = ReactiveVar(true); - var dummy = ReactiveVar(0); - - tmpl.showOne = function () { - return showOne.get(); - }; - tmpl.one.options = function () { - var x = dummy.get(); - buf += '1'; - if (optionsData) return optionsData[x]; - else return ['something']; - }; - tmpl.two.options = function () { - var x = dummy.get(); - buf += '2'; - if (optionsData) return optionsData[x]; - else return ['something']; - }; - - var div = renderToDiv(tmpl); - Tracker.flush(); - test.equal(buf, '1'); - - showOne.set(false); - dummy.set(1); - Tracker.flush(); - test.equal(buf, '12'); - - showOne.set(true); - dummy.set(2); - Tracker.flush(); - test.equal(buf, '121'); - - // clean up the div - $(div).remove(); - test.equal(showOne._numListeners(), 0); - test.equal(dummy._numListeners(), 0); - }); -}; - -Tinytest.add( - 'spacebars-tests - old - template_tests - with stops without re-running helper', - function (test) { - runOneTwoTest(test, 'old_spacebars_test_helpers_stop_with'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - each stops without re-running helper', - function (test) { - runOneTwoTest(test, 'old_spacebars_test_helpers_stop_each'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - each inside with stops without re-running helper', - function (test) { - runOneTwoTest(test, 'old_spacebars_test_helpers_stop_with_each'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - if stops without re-running helper', - function (test) { - runOneTwoTest(test, 'old_spacebars_test_helpers_stop_if', ['a', 'b', 'a']); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - unless stops without re-running helper', - function (test) { - runOneTwoTest(test, 'old_spacebars_test_helpers_stop_unless', [ - 'a', - 'b', - 'a', - ]); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - inclusion stops without re-running function', - function (test) { - var t = Template.old_spacebars_test_helpers_stop_inclusion3; - runOneTwoTest(test, 'old_spacebars_test_helpers_stop_inclusion', [t, t, t]); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - template with callbacks inside with stops without recalculating data', - function (test) { - var tmpl = Template.old_spacebars_test_helpers_stop_with_callbacks3; - tmpl.created = function () {}; - tmpl.rendered = function () {}; - tmpl.destroyed = function () {}; - runOneTwoTest(test, 'old_spacebars_test_helpers_stop_with_callbacks'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - no data context is seen as an empty object', - function (test) { - var tmpl = Template.old_spacebars_test_no_data_context; - - var dataInHelper = 'UNSET'; - var dataInRendered = 'UNSET'; - var dataInCreated = 'UNSET'; - var dataInDestroyed = 'UNSET'; - var dataInEvent = 'UNSET'; - - tmpl.foo = function () { - dataInHelper = this; - }; - tmpl.created = function () { - dataInCreated = this.data; - }; - tmpl.rendered = function () { - dataInRendered = this.data; - }; - tmpl.destroyed = function () { - dataInDestroyed = this.data; - }; - tmpl.events({ - click: function () { - dataInEvent = this; - }, - }); - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - clickElement(div.querySelector('button')); - Tracker.flush(); // rendered gets called afterFlush - $(div).remove(); - - test.isFalse(dataInHelper === window); - test.equal(dataInHelper, {}); - test.equal(dataInCreated, null); - test.equal(dataInRendered, null); - test.equal(dataInDestroyed, null); - test.isFalse(dataInEvent === window); - test.equal(dataInEvent, {}); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - falsy with', - function (test) { - var tmpl = Template.old_spacebars_test_falsy_with; - var R = ReactiveVar(null); - tmpl.obj = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl); - divRendersTo(test, div, ''); - - R.set({ greekLetter: 'alpha' }); - divRendersTo(test, div, 'alpha'); - - R.set(null); - divRendersTo(test, div, ''); - - R.set({ greekLetter: 'alpha' }); - divRendersTo(test, div, 'alpha'); - } -); - -Tinytest.add( - "spacebars-tests - old - template_tests - helpers don't leak", - function (test) { - var tmpl = Template.old_spacebars_test_helpers_dont_leak; - tmpl.foo = 'wrong'; - tmpl.bar = function () { - return 'WRONG'; - }; - - // Also test that custom block helpers (implemented as templates) do NOT - // interfere with helper lookup in the current template - Template.old_spacebars_test_helpers_dont_leak2.bonus = function () { - return 'BONUS'; - }; - - var div = renderToDiv(tmpl); - divRendersTo(test, div, 'correct BONUS'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - event handler returns false', - function (test) { - var tmpl = Template.old_spacebars_test_event_returns_false; - var elemId = 'spacebars_test_event_returns_false_link'; - tmpl.events({ - 'click a': function (evt) { - return false; - }, - }); - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - clickIt(document.getElementById(elemId)); - // NOTE: This failure can stick across test runs! Try - // removing '#bad-url' from the location bar and run - // the tests again. :) - test.isFalse(/#bad-url/.test(window.location.hash)); - document.body.removeChild(div); - } -); - -// Make sure that if you bind an event on "div p", for example, -// both the div and the p need to be in the template. jQuery's -// `$(elem).find(...)` works this way, but the browser's -// querySelector doesn't. -Tinytest.add( - 'spacebars-tests - old - template_tests - event map selector scope', - function (test) { - var tmpl = Template.old_spacebars_test_event_selectors1; - var tmpl2 = Template.old_spacebars_test_event_selectors2; - var buf = []; - tmpl2.events({ - 'click div p': function (evt) { - buf.push(evt.currentTarget.className); - }, - }); - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - test.equal(buf.join(), ''); - clickIt(div.querySelector('.p1')); - test.equal(buf.join(), ''); - clickIt(div.querySelector('.p2')); - test.equal(buf.join(), 'p2'); - document.body.removeChild(div); - } -); - -if (document.addEventListener) { - // see note about non-bubbling events in the "capuring events" - // templating test for why we use the VIDEO tag. (It would be - // nice to get rid of the network dependency, though.) - // We skip this test in IE 8. - Tinytest.add( - 'spacebars-tests - old - template_tests - event map selector scope (capturing)', - function (test) { - var tmpl = Template.old_spacebars_test_event_selectors_capturing1; - var tmpl2 = Template.old_spacebars_test_event_selectors_capturing2; - var buf = []; - tmpl2.events({ - 'play div video': function (evt) { - buf.push(evt.currentTarget.className); - }, - }); - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - test.equal(buf.join(), ''); - simulateEvent( - div.querySelector('.video1'), - 'play', - {}, - { bubbles: false } - ); - test.equal(buf.join(), ''); - simulateEvent( - div.querySelector('.video2'), - 'play', - {}, - { bubbles: false } - ); - test.equal(buf.join(), 'video2'); - document.body.removeChild(div); - } - ); -} - -Tinytest.add( - 'spacebars-tests - old - template_tests - tables', - function (test) { - var tmpl1 = Template.old_spacebars_test_tables1; - - var div = renderToDiv(tmpl1); - test.equal(Array.from(div.querySelectorAll('*')).map(x => x.tagName), [ - 'TABLE', - 'TR', - 'TD', - ]); - divRendersTo(test, div, '
Foo
'); - - var tmpl2 = Template.old_spacebars_test_tables2; - tmpl2.foo = 'Foo'; - div = renderToDiv(tmpl2); - test.equal(Array.from(div.querySelectorAll('*')).map(x => x.tagName), [ - 'TABLE', - 'TR', - 'TD', - ]); - divRendersTo(test, div, '
Foo
'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - jQuery.trigger extraParameters are passed to the event callback', - function (test) { - var tmpl = Template.old_spacebars_test_jquery_events; - var captured = false; - var args = ['param1', 'param2', { option: 1 }, 1, 2, 3]; - - tmpl.events({ - someCustomEvent: function (event, template) { - var i; - for (i = 0; i < args.length; i++) { - // expect the arguments to be just after template - test.equal(arguments[i + 2], args[i]); - } - captured = true; - }, - }); - - tmpl.rendered = function () { - $(this.find('button')).trigger('someCustomEvent', args); - }; - - renderToDiv(tmpl); - Tracker.flush(); - test.equal(captured, true); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - toHTML', - function (test) { - // run once, verifying that autoruns are stopped - var once = function (tmplToRender, tmplForHelper, helper, val) { - var count = 0; - var R = new ReactiveVar(); - var getR = function () { - count++; - return R.get(); - }; - - R.set(val); - tmplForHelper[helper] = getR; - test.equal(canonicalizeHtml(Blaze.toHTML(tmplToRender)), 'bar'); - test.equal(count, 1); - R.set(''); - Tracker.flush(); - test.equal(count, 1); // all autoruns stopped - }; - - once( - Template.old_spacebars_test_tohtml_basic, - Template.old_spacebars_test_tohtml_basic, - 'foo', - 'bar' - ); - once( - Template.old_spacebars_test_tohtml_if, - Template.old_spacebars_test_tohtml_if, - 'foo', - 'bar' - ); - once( - Template.old_spacebars_test_tohtml_with, - Template.old_spacebars_test_tohtml_with, - 'foo', - 'bar' - ); - once( - Template.old_spacebars_test_tohtml_each, - Template.old_spacebars_test_tohtml_each, - 'foos', - ['bar'] - ); - - once( - Template.old_spacebars_test_tohtml_include_with, - Template.old_spacebars_test_tohtml_with, - 'foo', - 'bar' - ); - once( - Template.old_spacebars_test_tohtml_include_each, - Template.old_spacebars_test_tohtml_each, - 'foos', - ['bar'] - ); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - block comments should not be displayed', - function (test) { - var tmpl = Template.old_spacebars_test_block_comment; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), ''); - } -); - -// Originally reported at https://github.com/meteor/meteor/issues/2046 -Tinytest.add( - 'spacebars-tests - old - template_tests - {{#with}} with mutated data context', - function (test) { - var tmpl = Template.old_spacebars_test_with_mutated_data_context; - var foo = { value: 0 }; - var dep = new Tracker.Dependency(); - tmpl.foo = function () { - dep.depend(); - return foo; - }; - - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), '0'); - - foo.value = 1; - dep.changed(); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), '1'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - event handlers get cleaned up when template is removed', - function (test) { - var tmpl = Template.old_spacebars_test_event_handler_cleanup; - var subtmpl = Template.old_spacebars_test_event_handler_cleanup_sub; - - var rv = new ReactiveVar(true); - tmpl.foo = function () { - return rv.get(); - }; - - subtmpl.events({ - 'click/mouseover': function () {}, - }); - - var div = renderToDiv(tmpl); - - test.equal(div.$blaze_events['click'].handlers.length, 1); - test.equal(div.$blaze_events['mouseover'].handlers.length, 1); - - rv.set(false); - Tracker.flush(); - - test.equal(div.$blaze_events['click'].handlers.length, 0); - test.equal(div.$blaze_events['mouseover'].handlers.length, 0); - } -); - -// This test makes sure that Blaze correctly finds the controller -// heirarchy surrounding an element that itself doesn't have a -// controller. -Tinytest.add( - 'spacebars-tests - old - template_tests - data context in event handlers on elements inside {{#if}}', - function (test) { - var tmpl = Template.old_spacebars_test_data_context_for_event_handler_in_if; - var data = null; - tmpl.events({ - 'click span': function () { - data = this; - }, - }); - var div = renderToDiv(tmpl); - document.body.appendChild(div); - clickIt(div.querySelector('span')); - test.equal(data, { foo: 'bar' }); - document.body.removeChild(div); - } -); - -// https://github.com/meteor/meteor/issues/2156 -Tinytest.add( - 'spacebars-tests - old - template_tests - each with inserts inside autorun', - function (test) { - var tmpl = Template.old_spacebars_test_each_with_autorun_insert; - var coll = new Mongo.Collection(null); - var rv = new ReactiveVar(); - - tmpl.items = function () { - return coll.find(); - }; - - var div = renderToDiv(tmpl); - - Tracker.autorun(function () { - if (rv.get()) { - coll.insert({ name: rv.get() }); - } - }); - - rv.set('foo1'); - Tracker.flush(); - var firstId = coll.findOne()._id; - - rv.set('foo2'); - Tracker.flush(); - - test.equal(canonicalizeHtml(div.innerHTML), 'foo1 foo2'); - - coll.update(firstId, { $set: { name: 'foo3' } }); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'foo3 foo2'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - ui hooks', - function (test) { - var tmpl = Template.old_spacebars_test_ui_hooks; - var rv = new ReactiveVar([]); - tmpl.items = function () { - return rv.get(); - }; - - var div = renderToDiv(tmpl); - - var hooks = []; - var container = div.querySelector('.test-ui-hooks'); - - // Before we attach the ui hooks, put two items in the DOM. - var origVal = [{ _id: 'foo1' }, { _id: 'foo2' }]; - rv.set(origVal); - Tracker.flush(); - - container._uihooks = { - insertElement: function (n, next) { - hooks.push('insert'); - - // check that the element hasn't actually been added yet - test.isTrue( - !n.parentNode || - n.parentNode.nodeType === 11 /*DOCUMENT_FRAGMENT_NODE*/ - ); - }, - removeElement: function (n) { - hooks.push('remove'); - // check that the element hasn't actually been removed yet - test.isTrue(n.parentNode === container); - }, - moveElement: function (n, next) { - hooks.push('move'); - // check that the element hasn't actually been moved yet - test.isFalse(n.nextNode === next); - }, - }; - - var testDomUnchanged = function () { - var items = div.querySelectorAll('.item'); - test.equal(items.length, 2); - test.equal(canonicalizeHtml(items[0].innerHTML), 'foo1'); - test.equal(canonicalizeHtml(items[1].innerHTML), 'foo2'); - }; - - var newVal = [...origVal]; - newVal.push({ _id: 'foo3' }); - rv.set(newVal); - Tracker.flush(); - test.equal(hooks, ['insert']); - testDomUnchanged(); - - newVal.reverse(); - rv.set(newVal); - Tracker.flush(); - test.equal(hooks, ['insert', 'move']); - testDomUnchanged(); - - newVal = [origVal[0]]; - rv.set(newVal); - Tracker.flush(); - test.equal(hooks, ['insert', 'move', 'remove']); - testDomUnchanged(); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - ui hooks - nested domranges', - function (test) { - var tmpl = Template.old_spacebars_test_ui_hooks_nested; - var rv = new ReactiveVar(true); - - tmpl.foo = function () { - return rv.get(); - }; - - var subtmpl = Template.old_spacebars_test_ui_hooks_nested_sub; - var uiHookCalled = false; - subtmpl.rendered = function () { - this.firstNode.parentNode._uihooks = { - removeElement: function (node) { - uiHookCalled = true; - }, - }; - }; - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - Tracker.flush(); - - var htmlBeforeRemove = canonicalizeHtml(div.innerHTML); - rv.set(false); - Tracker.flush(); - test.isTrue(uiHookCalled); - var htmlAfterRemove = canonicalizeHtml(div.innerHTML); - test.equal(htmlBeforeRemove, htmlAfterRemove); - document.body.removeChild(div); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - Template.instance from helper', - function (test) { - // Set a property on the template instance; check that it's still - // there from a helper. - - var tmpl = Template.old_spacebars_test_template_instance_helper; - var value = Random.id(); - var instanceFromHelper; - - tmpl.created = function () { - this.value = value; - }; - tmpl.foo = function () { - instanceFromHelper = Template.instance(); - }; - - var div = renderToDiv(tmpl); - test.equal(instanceFromHelper.value, value); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - Template.instance from helper, ' + - 'template instance is kept up-to-date', - function (test) { - var tmpl = Template.old_spacebars_test_template_instance_helper; - var rv = new ReactiveVar(''); - var instanceFromHelper; - - tmpl.foo = function () { - return Template.instance().data; - }; - - var div = renderToDiv(tmpl, function () { - return rv.get(); - }); - rv.set('first'); - divRendersTo(test, div, 'first'); - - rv.set('second'); - Tracker.flush(); - divRendersTo(test, div, 'second'); - - // Template.instance() returns null when no template instance - test.isTrue(Template.instance() === null); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - {{#with}} autorun is cleaned up', - function (test) { - var tmpl = Template.old_spacebars_test_with_cleanup; - var rv = new ReactiveVar(''); - var helperCalled = false; - tmpl.foo = function () { - helperCalled = true; - return rv.get(); - }; - - var div = renderToDiv(tmpl); - rv.set('first'); - Tracker.flush(); - test.equal(helperCalled, true); - - helperCalled = false; - $(div).find('.test-with-cleanup').remove(); - - rv.set('second'); - Tracker.flush(); - test.equal(helperCalled, false); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - UI.parentData from helpers', - function (test) { - var childTmpl = - Template.old_spacebars_test_template_parent_data_helper_child; - var parentTmpl = Template.old_spacebars_test_template_parent_data_helper; - - var height = new ReactiveVar(0); - var bar = new ReactiveVar('bar'); - - childTmpl.a = ['a']; - childTmpl.b = function () { - return bar.get(); - }; - childTmpl.c = ['c']; - - childTmpl.foo = function () { - var a = Template.parentData(height.get()); - var b = UI._parentData(height.get()); // back-compat - test.equal(a, b); - return a; - }; - - var div = renderToDiv(parentTmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'd'); - - height.set(1); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'bar'); - - // Test UI.parentData() reactivity - - bar.set('baz'); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'baz'); - - height.set(2); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'a'); - - height.set(3); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'parent'); - } -); - -Tinytest.add('spacebars - old - SVG elements', function (test) { - if (!document.createElementNS) { - // IE 8 - return; - } - - var tmpl = Template.old_spacebars_test_svg_anchor; - var div = renderToDiv(tmpl); - - var anchNamespace = $(div).find('a').get(0).namespaceURI; - test.equal(anchNamespace, 'http://www.w3.org/2000/svg'); -}); - -Tinytest.add( - 'spacebars-tests - old - template_tests - created/rendered/destroyed by each', - function (test) { - var outerTmpl = - Template.old_spacebars_test_template_created_rendered_destroyed_each; - var innerTmpl = - Template.old_spacebars_test_template_created_rendered_destroyed_each_sub; - - var buf = ''; - - innerTmpl.created = function () { - buf += 'C' + String(this.data).toLowerCase(); - }; - innerTmpl.rendered = function () { - buf += 'R' + String(this.data).toLowerCase(); - }; - innerTmpl.destroyed = function () { - buf += 'D' + String(this.data).toLowerCase(); - }; - - var R = ReactiveVar([{ _id: 'A' }]); - - outerTmpl.items = function () { - return R.get(); - }; - - var div = renderToDiv(outerTmpl); - divRendersTo(test, div, '

'); - test.equal(buf, 'CaRa'); - - R.set([{ _id: 'B' }]); - divRendersTo(test, div, '
B
'); - test.equal(buf, 'CaRaDaCbRb'); - - R.set([{ _id: 'C' }]); - divRendersTo(test, div, '
C
'); - test.equal(buf, 'CaRaDaCbRbDbCcRc'); - - $(div).remove(); - test.equal(buf, 'CaRaDaCbRbDbCcRcDc'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - UI.render/UI.remove', - function (test) { - var div = document.createElement('DIV'); - document.body.appendChild(div); - - var created = false, - rendered = false, - destroyed = false; - var R = ReactiveVar('aaa'); - - var tmpl = Template.old_spacebars_test_ui_render; - tmpl.greeting = function () { - return this.greeting || 'Hello'; - }; - tmpl.r = function () { - return R.get(); - }; - tmpl.created = function () { - created = true; - }; - tmpl.rendered = function () { - rendered = true; - }; - tmpl.destroyed = function () { - destroyed = true; - }; - - test.equal([created, rendered, destroyed], [false, false, false]); - - var renderedTmpl = UI.render(tmpl, div); - test.equal([created, rendered, destroyed], [true, false, false]); - - // Flush now. We fire the rendered callback in an afterFlush block, - // to ensure that the DOM is completely updated. - Tracker.flush(); - test.equal([created, rendered, destroyed], [true, true, false]); - - var otherDiv = document.createElement('DIV'); - // can run a second time without throwing - var x = UI.render(tmpl, otherDiv); - // note: we'll have clean up `x` below - - var renderedTmpl2 = UI.renderWithData(tmpl, { greeting: 'Bye' }, div); - test.equal( - canonicalizeHtml(div.innerHTML), - 'Hello aaaBye aaa' - ); - R.set('bbb'); - Tracker.flush(); - test.equal( - canonicalizeHtml(div.innerHTML), - 'Hello bbbBye bbb' - ); - test.equal([created, rendered, destroyed], [true, true, false]); - test.equal(R._numListeners(), 3); - UI.remove(renderedTmpl); - UI.remove(renderedTmpl); // test that double-remove doesn't throw - UI.remove(renderedTmpl2); - UI.remove(x); - test.equal([created, rendered, destroyed], [true, true, true]); - test.equal(R._numListeners(), 0); - test.equal(canonicalizeHtml(div.innerHTML), ''); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - UI.render fails on jQuery objects', - function (test) { - var tmpl = Template.old_spacebars_test_ui_render; - test.throws(function () { - UI.render(tmpl, $('body')); - }, /'parentElement' must be a DOM node/); - test.throws(function () { - UI.render(tmpl, document.body, $('body')); - }, /'nextNode' must be a DOM node/); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - UI.getElementData', - function (test) { - var div = document.createElement('DIV'); - var tmpl = Template.old_spacebars_test_ui_getElementData; - UI.renderWithData(tmpl, { foo: 'bar' }, div); - - var span = div.querySelector('SPAN'); - test.isTrue(span); - test.equal(UI.getElementData(span), { foo: 'bar' }); - test.equal(Blaze.getData(span), { foo: 'bar' }); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - autorun cleanup', - function (test) { - var tmpl = Template.old_spacebars_test_parent_removal; - - var Acalls = ''; - var A = ReactiveVar('hi'); - tmpl.A = function (chr) { - Acalls += chr; - return A.get(); - }; - var Bcalls = 0; - var B = ReactiveVar(['one', 'two']); - tmpl.B = function () { - Bcalls++; - return B.get(); - }; - - // Assert how many times A and B were accessed (since last time) - // and how many autoruns are listening to them. - var assertCallsAndListeners = function ( - a_calls, - b_calls, - a_listeners, - b_listeners - ) { - test.equal('A calls: ' + Acalls.length, 'A calls: ' + a_calls, Acalls); - test.equal('B calls: ' + Bcalls, 'B calls: ' + b_calls); - test.equal( - 'A listeners: ' + A._numListeners(), - 'A listeners: ' + a_listeners - ); - test.equal( - 'B listeners: ' + B._numListeners(), - 'B listeners: ' + b_listeners - ); - Acalls = ''; - Bcalls = 0; - }; - - var div = renderToDiv(tmpl); - assertCallsAndListeners(10, 1, 10, 1); - A.set(''); - Tracker.flush(); - // Confirm that #4, #5, #6, and #9 are not re-run. - // #a is newly run, for a total of 10 - 4 + 1 = 7, - assertCallsAndListeners(7, 0, 7, 1); - A.set('hi'); - Tracker.flush(); - assertCallsAndListeners(10, 0, 10, 1); - - // Now see that removing the DOM with jQuery, below - // the level of the entire template, stops everything. - $(div.querySelector('.toremove')).remove(); - assertCallsAndListeners(0, 0, 0, 0); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - focus/blur with clean-up', - function (test) { - var tmpl = Template.old_spacebars_test_focus_blur_outer; - var cond = ReactiveVar(true); - tmpl.cond = function () { - return cond.get(); - }; - var buf = []; - Template.old_spacebars_test_focus_blur_inner.events({ - 'focus input': function () { - buf.push('FOCUS'); - }, - 'blur input': function () { - buf.push('BLUR'); - }, - }); - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - - // check basic focus and blur to make sure - // everything is sane - test.equal(div.querySelectorAll('input').length, 1); - var input; - focusElement((input = div.querySelector('input'))); - // We don't get focus events when the Chrome Dev Tools are focused, - // unfortunately, as of Chrome 35. I think this is a regression in - // Chrome 34. So, the goal is to work whether or not focus is - // "borken," where "working" means always failing if DOMBackend isn't - // correctly unbinding the old event handlers when we switch the IF, - // and always passing if it is. To cause the problem in DOMBackend, - // delete the '**' argument to jQuery#off in - // DOMBackend.Events.undelegateEvents. The only compromise we are - // making here is that if some unrelated bug in Blaze makes - // focus/blur not work, the failure might be masked while the Dev - // Tools are open. - var borken = false; - if (buf.length === 0 && document.activeElement === input) { - test.ok({ - note: - 'You might need to defocus the Chrome Dev Tools to get a more accurate run of this test!', - }); - borken = true; - $(input).trigger('focus'); - } - test.equal(buf.join(), 'FOCUS'); - blurElement(div.querySelector('input')); - if (buf.length === 1) $(input).trigger('blur'); - test.equal(buf.join(), 'FOCUS,BLUR'); - - // now switch the IF and check again. The failure mode - // we observed was that DOMBackend would not correctly - // unbind the old event listener at the jQuery level, - // so the old event listener would fire and cause an - // exception inside Blaze ("Must be attached" in - // DOMRange#containsElement), which would show up in - // the console and cause our handler not to fire. - cond.set(false); - buf.length = 0; - Tracker.flush(); - test.equal(div.querySelectorAll('input').length, 1); - focusElement((input = div.querySelector('input'))); - if (borken) $(input).trigger('focus'); - test.equal(buf.join(), 'FOCUS'); - blurElement(div.querySelector('input')); - if (!borken) test.equal(buf.join(), 'FOCUS,BLUR'); - - document.body.removeChild(div); - } -); - -// We used to remove event handlers on DOMRange detached, but when -// tearing down a view, we don't "detach" all the DOMRanges recursively. -// Mainly, we destroy the View. Destroying a View should remove its -// event listeners. (In practice, however, it's hard to think of -// consequences to not removing event handlers on removed DOM nodes, -// which will probably be GCed anyway.) -Tinytest.add( - 'spacebars-tests - old - template_tests - event cleanup on destroyed', - function (test) { - var tmpl = Template.old_spacebars_test_event_cleanup_on_destroyed_outer; - var cond = ReactiveVar(true); - tmpl.cond = function () { - return cond.get(); - }; - - Template.old_spacebars_test_event_cleanup_on_destroyed_inner.events({ - 'click span': function () {}, - }); - - var div = renderToDiv(tmpl); - document.body.appendChild(div); - - var eventDiv = div.querySelector('div'); - test.equal(eventDiv.$blaze_events.click.handlers.length, 1); - - cond.set(false); - Tracker.flush(); - test.equal(eventDiv.$blaze_events.click.handlers.length, 0); - - document.body.removeChild(div); - } -); - -[1, 2, 3].forEach(function (n) { - Tinytest.add( - 'spacebars-tests - old - template_tests - lookup is isolated ' + n, - function (test) { - var buf = ''; - var inclusion = Template.old_spacebars_test_isolated_lookup_inclusion; - inclusion.created = function () { - buf += 'C'; - }; - inclusion.destroyed = function () { - buf += 'D'; - }; - - var tmpl = Template['old_spacebars_test_isolated_lookup' + n]; - var R = ReactiveVar(Template.old_spacebars_template_test_aaa); - - tmpl.bar = function () { - return R.get(); - }; - - var div = renderToDiv(tmpl, function () { - return { foo: R.get() }; - }); - - test.equal(canonicalizeHtml(div.innerHTML), 'aaa--x'); - test.equal(buf, 'C'); - R.set(Template.old_spacebars_template_test_bbb); - Tracker.flush(); - test.equal(canonicalizeHtml(div.innerHTML), 'bbb--x'); - test.equal(buf, 'C'); - } - ); -}); - -Tinytest.add( - 'spacebars-tests - old - template_tests - current view in event handler', - function (test) { - var tmpl = Template.old_spacebars_test_current_view_in_event; - - var currentView; - var currentData; - - tmpl.events({ - 'click span': function () { - currentView = Blaze.getView(); - currentData = Blaze.getData(); - }, - }); - - var div = renderToDiv(tmpl, 'blah'); - test.equal(canonicalizeHtml(div.innerHTML), 'blah'); - document.body.appendChild(div); - clickElement(div.querySelector('span')); - $(div).remove(); - - test.isTrue(currentView); - test.equal(currentData, 'blah'); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - textarea attrs', - function (test) { - var tmplNoContents = { - tmpl: Template.old_spacebars_test_textarea_attrs, - hasTextAreaContents: false, - }; - var tmplWithContents = { - tmpl: Template.old_spacebars_test_textarea_attrs_contents, - hasTextAreaContents: true, - }; - var tmplWithContentsAndMoreAttrs = { - tmpl: Template.old_spacebars_test_textarea_attrs_array_contents, - hasTextAreaContents: true, - }; - - [tmplNoContents, tmplWithContents, tmplWithContentsAndMoreAttrs].forEach( - function (tmplInfo) { - var id = new ReactiveVar('textarea-' + Random.id()); - var name = new ReactiveVar('one'); - var attrs = new ReactiveVar({ - id: 'textarea-' + Random.id(), - }); - - var div = renderToDiv(tmplInfo.tmpl, { - attrs: function () { - return attrs.get(); - }, - name: function () { - return name.get(); - }, - }); - - // Check that the id and value attribute are as we expect. - // We can't check div.innerHTML because Chrome at least doesn't - // appear to put textarea value attributes in innerHTML. - var textarea = div.querySelector('textarea'); - test.equal(textarea.id, attrs.get().id); - test.equal( - textarea.value, - tmplInfo.hasTextAreaContents ? 'Hello one' : '' - ); - // One of the templates has a separate attribute in addition to - // an attributes dictionary. - if (tmplInfo === tmplWithContentsAndMoreAttrs) { - test.equal($(textarea).attr('class'), 'bar'); - } - - // Change the id, check that the attribute updates reactively. - attrs.set({ id: 'textarea-' + Random.id() }); - Tracker.flush(); - test.equal(textarea.id, attrs.get().id); - - // Change the name variable, check that the textarea value - // updates reactively. - name.set('two'); - Tracker.flush(); - test.equal( - textarea.value, - tmplInfo.hasTextAreaContents ? 'Hello two' : '' - ); - - if (tmplInfo === tmplWithContentsAndMoreAttrs) { - test.equal($(textarea).attr('class'), 'bar'); - } - } - ); - } -); - -Tinytest.add( - 'spacebars-tests - old - template_tests - this.autorun', - function (test) { - var tmpl = Template.old_spacebars_test_autorun; - var tmplInner = Template.old_spacebars_test_autorun_inner; - - // Keep track of the value of `Template.instance()` inside the - // autorun each time it runs. - var autorunTemplateInstances = []; - var actualTemplateInstance; - var returnedComputation; - var computationArg; - - var show = new ReactiveVar(true); - var rv = new ReactiveVar('foo'); - - tmplInner.created = function () { - actualTemplateInstance = this; - returnedComputation = this.autorun(function (c) { - computationArg = c; - rv.get(); - autorunTemplateInstances.push(Template.instance()); - }); - }; - - tmpl.helpers({ - show: function () { - return show.get(); - }, - }); - - var div = renderToDiv(tmpl); - test.equal(autorunTemplateInstances.length, 1); - test.equal(autorunTemplateInstances[0], actualTemplateInstance); - - // Test that the autorun returned a computation and received a - // computation as an argument. - test.isTrue(returnedComputation instanceof Tracker.Computation); - test.equal(returnedComputation, computationArg); - - // Make sure the autorun re-runs when `rv` changes, and that it has - // the correct current view. - rv.set('bar'); - Tracker.flush(); - test.equal(autorunTemplateInstances.length, 2); - test.equal(autorunTemplateInstances[1], actualTemplateInstance); - - // If the inner template is destroyed, the autorun should be stopped. - show.set(false); - Tracker.flush(); - rv.set('baz'); - Tracker.flush(); - - test.equal(autorunTemplateInstances.length, 2); - test.equal(rv._numListeners(), 0); - } -); - -// Test that argument in {{> UI.contentBlock arg}} is evaluated in -// the proper data context. -Tinytest.add( - 'spacebars-tests - old - template_tests - contentBlock argument', - function (test) { - var tmpl = Template.old_spacebars_test_contentBlock_arg; - var div = renderToDiv(tmpl); - test.equal(canonicalizeHtml(div.innerHTML), 'AAA BBB'); - } -); - -// Test that when Blaze sets an input field to the same value, -// we don't lose the insertion point position. -Tinytest.add( - 'spacebars-tests - old - template_tests - input field to same value', - function (test) { - var tmpl = Template.old_spacebars_template_test_input_field_to_same_value; - var R = ReactiveVar('BLAH'); - tmpl.foo = function () { - return R.get(); - }; - var div = renderToDiv(tmpl); - - document.body.appendChild(div); - - var input = div.querySelector('input'); - test.equal(input.value, 'BLAH'); - - var setSelection = function (startEnd) { - startEnd = startEnd.split(' '); - if (typeof input.selectionStart === 'number') { - // all but IE < 9 - input.selectionStart = startEnd[0]; - input.selectionEnd = startEnd[1]; - } else { - // IE 8 - input.focus(); - var r = input.createTextRange(); - // move the start and end of the range to the beginning - // of the input field - r.moveStart('textedit', -1); - r.moveEnd('textedit', -1); - // move the start and end a certain number of characters - // (relative to their current position) - r.moveEnd('character', startEnd[1]); - r.moveStart('character', startEnd[0]); - r.select(); - } - }; - var getSelection = function () { - if (typeof input.selectionStart === 'number') { - // all but IE < 9 - return input.selectionStart + ' ' + input.selectionEnd; - } else { - // IE 8 - input.focus(); - var r = document.selection.createRange(); - var fullText = input.value; - var start, end; - if (r.text) { - // one or more characters are selected. - // this is kind of hacky! Relies on fullText - // not having duplicate letters, for example. - start = fullText.indexOf(r.text); - end = start + r.text.length; - } else { - r.moveStart('textedit', -1); - start = end = r.text.length; - } - return start + ' ' + end; - } - }; - - setSelection('2 3'); - test.equal(getSelection(), '2 3'); - // At this point, we COULD confirm that setting input.value to - // the same thing as before ("BLAH") loses the insertion - // point (per browser behavior). However, it doesn't on Firefox. - // So we set it to something different, which verifies that our - // test machinery is correct. - input.value = 'BLAN'; - // test that insertion point is lost - var selectionAfterSet = getSelection(); - if (selectionAfterSet !== '0 0') - // IE 8 - test.equal(getSelection(), '4 4'); - - // now make the input say "BLAH" but the AttributeHandler - // says "OTHER" (so we can make it do the no-op update) - R.set('OTHER'); - Tracker.flush(); - test.equal(input.value, 'OTHER'); - input.value = 'BLAH'; - setSelection('2 2'); - - R.set('BLAH'); - Tracker.flush(); - test.equal(input.value, 'BLAH'); - // test that didn't lose insertion point! - test.equal(getSelection(), '2 2'); - - // clean up after ourselves - document.body.removeChild(div); - } -); diff --git a/packages/spacebars-tests/package.js b/packages/spacebars-tests/package.js index d9a52c1fa..dcc068c26 100644 --- a/packages/spacebars-tests/package.js +++ b/packages/spacebars-tests/package.js @@ -33,9 +33,6 @@ Package.onTest(function (api) { 'template_tests.js', 'templating_tests.html', 'templating_tests.js', - - 'old_templates.js', // backcompat for packages built with old Blaze APIs. - 'old_templates_tests.js' ], 'client'); api.addFiles('template_tests_server.js', 'server'); From 933d8f0259e0d61a91daf93c44f0972f8b40201f Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Thu, 14 Apr 2022 17:35:02 +0200 Subject: [PATCH 03/16] Revert "Remove tests for removed API in spacebars, fix #369" This reverts commit 6e42e5768ea0984582b0eb7ed64f1798ef45cc43. --- packages/spacebars-tests/old_templates.js | 2058 +++++++++++ .../spacebars-tests/old_templates_tests.js | 3189 +++++++++++++++++ packages/spacebars-tests/package.js | 3 + 3 files changed, 5250 insertions(+) create mode 100644 packages/spacebars-tests/old_templates.js create mode 100644 packages/spacebars-tests/old_templates_tests.js diff --git a/packages/spacebars-tests/old_templates.js b/packages/spacebars-tests/old_templates.js new file mode 100644 index 000000000..e92edcb87 --- /dev/null +++ b/packages/spacebars-tests/old_templates.js @@ -0,0 +1,2058 @@ +// This file contains templates compiled with a pre-0.9.0 version of +// spacebars-compiler. We run the entire suite of tests as we had on +// 0.9.0 against these compiled template. The test suits is found +// in old_templates_tests.js +// +// Why? Packages are published in built form. With Meteor 0.9.1, we +// didn't bump the major version of the 'templating' package (which +// would force packages that define templates to publish new versions +// of their package). Instead, we decided to keep backcompat with the +// old Blaze runtime APIs. +// +// If these tests ever break in the future, and backcompat is too hard +// to achieve (or undesirable), we can simply bump the major version +// of the 'templating' package, and get rid of these tests. +Template.__define__("old_spacebars_template_test_aaa", (function() { + var view = this; + return "aaa"; +})); + +Template.__define__("old_spacebars_template_test_bbb", (function() { + var view = this; + return "bbb"; +})); + +Template.__define__("old_spacebars_template_test_bracketed_this", (function() { + var view = this; + return [ "[", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "]" ]; +})); + +Template.__define__("old_spacebars_template_test_span_this", (function() { + var view = this; + return HTML.SPAN(Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + })); +})); + +Template.__define__("old_spacebars_template_test_content", (function() { + var view = this; + return Blaze.InOuterTemplateScope(view, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateContentBlock); + }); + }); +})); + +Template.__define__("old_spacebars_template_test_elsecontent", (function() { + var view = this; + return Blaze.InOuterTemplateScope(view, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateElseBlock); + }); + }); +})); + +Template.__define__("old_spacebars_template_test_iftemplate", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("condition")); + }, function() { + return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateContentBlock); + }); + }), "\n " ]; + }, function() { + return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateElseBlock); + }); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_simple_helper", (function() { + var view = this; + return Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo"), view.lookup("bar")); + }); +})); + +Template.__define__("old_spacebars_template_test_dynamic_template", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("foo")); +})); + +Template.__define__("old_spacebars_template_test_interpolate_attribute", (function() { + var view = this; + return HTML.DIV({ + "class": function() { + return [ "aaa", Spacebars.mustache(view.lookup("foo"), view.lookup("bar")), "zzz" ]; + } + }); +})); + +Template.__define__("old_spacebars_template_test_dynamic_attrs", (function() { + var view = this; + return HTML.SPAN(HTML.Attrs(function() { + return Spacebars.attrMustache(view.lookup("attrsObj")); + }, function() { + return Spacebars.attrMustache(view.lookup("singleAttr")); + }, function() { + return Spacebars.attrMustache(view.lookup("nonexistent")); + }), "hi"); +})); + +Template.__define__("old_spacebars_template_test_triple", (function() { + var view = this; + return Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html"))); + }); +})); + +Template.__define__("old_spacebars_template_test_triple2", (function() { + var view = this; + return [ "x", Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html"))); + }), Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html2"))); + }), Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("html3"))); + }), "y" ]; +})); + +Template.__define__("old_spacebars_template_test_inclusion_args", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return Spacebars.call(view.lookup("bar")); + }, function() { + return Spacebars.include(view.lookupTemplate("foo")); + }); +})); + +Template.__define__("old_spacebars_template_test_inclusion_args2", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return Spacebars.dataMustache(view.lookup("bar"), Spacebars.kw({ + q: view.lookup("baz") + })); + }, function() { + return Spacebars.include(view.lookupTemplate("foo")); + }); +})); + +Template.__define__("old_spacebars_template_test_inclusion_dotted_args", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return Spacebars.call(Spacebars.dot(view.lookup("bar"), "baz")); + }, function() { + return Spacebars.include(view.lookupTemplate("foo")); + }); +})); + +Template.__define__("old_spacebars_template_test_inclusion_slashed_args", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return Spacebars.call(Spacebars.dot(view.lookup("bar"), "baz")); + }, function() { + return Spacebars.include(view.lookupTemplate("foo")); + }); +})); + +Template.__define__("old_spacebars_template_test_block_helper", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("foo"), function() { + return "\n bar\n "; + }, function() { + return "\n baz\n "; + }); +})); + +Template.__define__("old_spacebars_template_test_block_helper_function_one_string_arg", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return "bar"; + }, function() { + return Spacebars.include(view.lookupTemplate("foo"), function() { + return "\n content\n "; + }); + }); +})); + +Template.__define__("old_spacebars_template_test_block_helper_function_one_helper_arg", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return Spacebars.call(view.lookup("bar")); + }, function() { + return Spacebars.include(view.lookupTemplate("foo"), function() { + return "\n content\n "; + }); + }); +})); + +Template.__define__("old_spacebars_template_test_block_helper_component_one_helper_arg", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("bar")); + }, function() { + return "\n content\n "; + }); +})); + +Template.__define__("old_spacebars_template_test_block_helper_component_three_helper_args", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.dataMustache(view.lookup("equals"), view.lookup("bar_or_baz"), "bar"); + }, function() { + return "\n content\n "; + }); +})); + +Template.__define__("old_spacebars_template_test_block_helper_dotted_arg", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return Spacebars.dataMustache(Spacebars.dot(view.lookup("bar"), "baz"), view.lookup("qux")); + }, function() { + return Spacebars.include(view.lookupTemplate("foo"), function() { + return null; + }); + }); +})); + +Template.__define__("old_spacebars_template_test_nested_content", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return { + condition: Spacebars.call(view.lookup("flag")) + }; + }, function() { + return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate"), function() { + return "\n hello\n "; + }, function() { + return "\n world\n "; + }); + }); +})); + +Template.__define__("old_spacebars_template_test_iftemplate2", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return { + condition: Spacebars.call(view.lookup("flag")) + }; + }, function() { + return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate"), function() { + return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateContentBlock); + }); + }), "\n " ]; + }, function() { + return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateElseBlock); + }); + }), "\n " ]; + }); + }); +})); + +Template.__define__("old_spacebars_template_test_nested_content2", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return { + flag: Spacebars.call(view.lookup("x")) + }; + }, function() { + return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate2"), function() { + return "\n hello\n "; + }, function() { + return "\n world\n "; + }); + }); +})); + +Template.__define__("old_spacebars_template_test_if", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }), "\n " ]; + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("baz")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_if_in_with", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }), "\n ", Blaze.If(function() { + return true; + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }), "\n " ]; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_each", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("items")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("text")); + }), "\n " ]; + }, function() { + return "\n else-clause\n "; + }); +})); + +Template.__define__("old_spacebars_template_test_dots", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n A\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("bar")); + }, function() { + return [ "\n B\n \n ", Blaze.If(function() { + return true; + }, function() { + return [ "\n C\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("items")); + }, function() { + return [ "\n D\n \n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_dots_subtemplate")), "\n ", Spacebars.TemplateWith(function() { + return Spacebars.call(view.lookup("..")); + }, function() { + return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_dots_subtemplate")); + }), "\n " ]; + }), "\n " ]; + }), "\n " ]; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_dots_subtemplate", (function() { + var view = this; + return [ "TITLE\n 1", Blaze.View(function() { + return Spacebars.mustache(view.lookup("title")); + }), "\n 2", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("."), "title")); + }), "\n 3", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "title")); + }), "\n 4", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("..."), "title")); + }), "\n\n GETTITLE\n 5", Blaze.View(function() { + return Spacebars.mustache(view.lookup("getTitle"), view.lookup(".")); + }), "\n 6", Blaze.View(function() { + return Spacebars.mustache(view.lookup("getTitle"), view.lookup("..")); + }), "\n 7", Blaze.View(function() { + return Spacebars.mustache(view.lookup("getTitle"), view.lookup("...")); + }) ]; +})); + +Template.__define__("old_spacebars_template_test_select_tag", (function() { + var view = this; + return HTML.SELECT("\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("optgroups")); + }, function() { + return [ "\n ", HTML.OPTGROUP({ + label: function() { + return Spacebars.mustache(view.lookup("label")); + } + }, "\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return [ "\n ", HTML.OPTION(HTML.Attrs({ + value: function() { + return Spacebars.mustache(view.lookup("value")); + } + }, function() { + return Spacebars.attrMustache(view.lookup("selectedAttr")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("label")); + })), "\n " ]; + }), "\n "), "\n " ]; + }), "\n "); +})); + +Template.__define__("old_test_template_issue770", (function() { + var view = this; + return [ Spacebars.With(function() { + return Spacebars.call(view.lookup("value1")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }, function() { + return "\n xxx\n "; + }), "\n\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("value2")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }, function() { + return "\n xxx\n "; + }), "\n\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("value1")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }), "\n\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("value2")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }) ]; +})); + +Template.__define__("old_spacebars_template_test_tricky_attrs", (function() { + var view = this; + return [ HTML.INPUT({ + type: function() { + return Spacebars.mustache(view.lookup("theType")); + } + }), HTML.INPUT({ + type: "checkbox", + "class": function() { + return Spacebars.mustache(view.lookup("theClass")); + } + }) ]; +})); + +Template.__define__("old_spacebars_template_test_no_data", (function() { + var view = this; + return [ Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("."), "foo")); + }), Blaze.Unless(function() { + return Spacebars.call(Spacebars.dot(view.lookup("."), "bar")); + }, function() { + return "asdf"; + }) ]; +})); + +Template.__define__("old_spacebars_template_test_textarea", (function() { + var view = this; + return HTML.TEXTAREA({ + value: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }); +})); + +Template.__define__("old_spacebars_template_test_textarea2", (function() { + var view = this; + return HTML.TEXTAREA({ + value: function() { + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return "
"; + }, function() { + return ""; + }); + } + }); +})); + +Template.__define__("old_spacebars_template_test_textarea3", (function() { + var view = this; + return HTML.TEXTAREA({ + id: "myTextarea", + value: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }); +})); + +Template.__define__("old_spacebars_template_test_textarea_each", (function() { + var view = this; + return HTML.TEXTAREA({ + value: function() { + return Blaze.Each(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ ""; + }); + } + }); +})); + +Template.__define__("old_spacebars_template_test_defer_in_rendered", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("items")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_defer_in_rendered_subtemplate")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_defer_in_rendered_subtemplate", (function() { + var view = this; + return ""; +})); + +Template.__define__("old_spacebars_template_test_with_someData", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("someData")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), " ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_each_stops", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("items")); + }, function() { + return "\n x\n "; + }); +})); + +Template.__define__("old_spacebars_template_test_block_helpers_in_attribute", (function() { + var view = this; + return HTML.DIV({ + "class": function() { + return Blaze.Each(function() { + return Spacebars.call(view.lookup("classes")); + }, function() { + return Blaze.If(function() { + return Spacebars.dataMustache(view.lookup("startsLowerCase"), view.lookup("name")); + }, function() { + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("name")); + }), " " ]; + }); + }, function() { + return "none"; + }); + } + }, "Smurf"); +})); + +Template.__define__("old_spacebars_template_test_block_helpers_in_attribute_2", (function() { + var view = this; + return HTML.INPUT({ + value: function() { + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return '"'; + }, function() { + return [ "&", HTML.CharRef({ + html: "<", + str: "<" + }), ">" ]; + }); + } + }); +})); + +Template.__define__("old_spacebars_template_test_constant_each_argument", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("someData")); + }, function() { + return [ "\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("anArray")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("justReturn"), view.lookup(".")); + }), "\n " ]; + }), "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_markdown_basic", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("obj")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("markdown"), function() { + return [ "\n", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "\n/each}}\n\n", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "\n/each}}\n\n* ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "\n* /each}}\n\n* ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "\n* /each}}\n\nsome paragraph to fix showdown's four space parsing below.\n\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "\n /each}}\n\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "\n /each}}\n\n>\n\n* >\n\n`>`\n\n >\n\n>\n\n* >\n\n`>`\n\n >\n\n`", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "`\n`/each}}`\n\n`", Blaze.View(function() { + return Spacebars.mustache(view.lookup("hi")); + }), "`\n`/each}}`\n\n " ]; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_markdown_if", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("markdown"), function() { + return [ "\n\n", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "\n\n", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "\n\n* ", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "\n\n* ", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "\n\nsome paragraph to fix showdown's four space parsing below.\n\n ", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "\n\n ", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "\n\n`", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "`\n\n`", Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return "true"; + }, function() { + return "false"; + }), "`\n\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_markdown_each", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("markdown"), function() { + return [ "\n\n", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "\n\n", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "\n\n* ", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "\n\n* ", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "\n\nsome paragraph to fix showdown's four space parsing below.\n\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "\n\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "\n\n`", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "`\n\n`", Blaze.Each(function() { + return Spacebars.call(view.lookup("seq")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }), "`\n\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_markdown_inclusion", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("markdown"), function() { + return [ "\n", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_markdown_inclusion_subtmpl")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_markdown_inclusion_subtmpl", (function() { + var view = this; + return HTML.SPAN(Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "Foo is ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), "." ]; + })); +})); + +Template.__define__("old_spacebars_template_test_markdown_block_helpers", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("markdown"), function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_just_content"), function() { + return "\nHi there!\n "; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_just_content", (function() { + var view = this; + return Blaze.InOuterTemplateScope(view, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateContentBlock); + }); + }); +})); + +Template.__define__("old_spacebars_template_test_simple_helpers_are_isolated", (function() { + var view = this; + return Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }); +})); + +Template.__define__("old_spacebars_template_test_attr_helpers_are_isolated", (function() { + var view = this; + return HTML.P({ + attr: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }); +})); + +Template.__define__("old_spacebars_template_test_attr_object_helpers_are_isolated", (function() { + var view = this; + return HTML.P(HTML.Attrs(function() { + return Spacebars.attrMustache(view.lookup("attrs")); + })); +})); + +Template.__define__("old_spacebars_template_test_inclusion_helpers_are_isolated", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("foo")); +})); + +Template.__define__("old_spacebars_template_test_inclusion_helpers_are_isolated_subtemplate", (function() { + var view = this; + return ""; +})); + +Template.__define__("old_spacebars_template_test_nully_attributes0", (function() { + var view = this; + return HTML.Raw(''); +})); + +Template.__define__("old_spacebars_template_test_nully_attributes1", (function() { + var view = this; + return HTML.INPUT({ + type: "checkbox", + checked: function() { + return Spacebars.mustache(view.lookup("foo")); + }, + stuff: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }); +})); + +Template.__define__("old_spacebars_template_test_nully_attributes2", (function() { + var view = this; + return HTML.INPUT({ + type: "checkbox", + checked: function() { + return [ Spacebars.mustache(view.lookup("foo")), Spacebars.mustache(view.lookup("bar")) ]; + }, + stuff: function() { + return [ Spacebars.mustache(view.lookup("foo")), Spacebars.mustache(view.lookup("bar")) ]; + } + }); +})); + +Template.__define__("old_spacebars_template_test_nully_attributes3", (function() { + var view = this; + return HTML.INPUT({ + type: "checkbox", + checked: function() { + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return null; + }); + }, + stuff: function() { + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return null; + }); + } + }); +})); + +Template.__define__("old_spacebars_template_test_double", (function() { + var view = this; + return Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }); +})); + +Template.__define__("old_spacebars_template_test_inclusion_lookup", (function() { + var view = this; + return [ Spacebars.include(view.lookupTemplate("old_spacebars_template_test_inclusion_lookup_subtmpl")), "\n ", Spacebars.include(view.lookupTemplate("dataContextSubtmpl")) ]; +})); + +Template.__define__("old_spacebars_template_test_inclusion_lookup_subtmpl", (function() { + var view = this; + return "This is the template."; +})); + +Template.__define__("old_spacebars_template_test_inclusion_lookup_subtmpl2", (function() { + var view = this; + return "This is generated by a helper with the same name."; +})); + +Template.__define__("old_spacebars_template_test_inclusion_lookup_subtmpl3", (function() { + var view = this; + return "This is a template passed in the data context."; +})); + +Template.__define__("old_spacebars_template_test_content_context", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("bar")); + }, function() { + return [ "\n ", Spacebars.TemplateWith(function() { + return { + condition: Spacebars.call(view.lookup("cond")) + }; + }, function() { + return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate"), function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("firstLetter")); + }), Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "secondLetter")); + }), "\n " ]; + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "firstLetter")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("secondLetter")); + }), "\n " ]; + }); + }), "\n " ]; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_control_input", (function() { + var view = this; + return HTML.INPUT({ + type: function() { + return Spacebars.mustache(view.lookup("type")); + }, + value: function() { + return Spacebars.mustache(view.lookup("value")); + } + }); +})); + +Template.__define__("old_spacebars_test_control_textarea", (function() { + var view = this; + return HTML.TEXTAREA({ + value: function() { + return Spacebars.mustache(view.lookup("value")); + } + }); +})); + +Template.__define__("old_spacebars_test_control_select", (function() { + var view = this; + return HTML.SELECT("\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return [ "\n ", HTML.OPTION({ + selected: function() { + return Spacebars.mustache(view.lookup("selected")); + } + }, Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + })), "\n " ]; + }), "\n "); +})); + +Template.__define__("old_spacebars_test_control_radio", (function() { + var view = this; + return [ "Band:\n\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("bands")); + }, function() { + return [ "\n ", HTML.INPUT({ + name: "bands", + type: "radio", + value: function() { + return Spacebars.mustache(view.lookup(".")); + }, + checked: function() { + return Spacebars.mustache(view.lookup("isChecked")); + } + }), "\n " ]; + }), "\n\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("band")); + }) ]; +})); + +Template.__define__("old_spacebars_test_control_checkbox", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("labels")); + }, function() { + return [ "\n ", HTML.INPUT({ + type: "checkbox", + value: function() { + return Spacebars.mustache(view.lookup(".")); + }, + checked: function() { + return Spacebars.mustache(view.lookup("isChecked")); + } + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_nonexistent_template", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("this_template_lives_in_outer_space")); +})); + +Template.__define__("old_spacebars_test_if_helper", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return "\n true\n "; + }, function() { + return "\n false\n "; + }); +})); + +Template.__define__("old_spacebars_test_block_helper_function", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("foo"), function() { + return "\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_onetwo", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("showOne")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("one")), "\n " ]; + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("two")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_onetwo_attribute", (function() { + var view = this; + return HTML.BR({ + "data-stuff": function() { + return Blaze.If(function() { + return Spacebars.call(view.lookup("showOne")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("one")), "\n " ]; + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("two")), "\n " ]; + }); + } + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_with1", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n one\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_with2", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n two\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_each1", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n one\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_each2", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n two\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_with_each1", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_each3")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_with_each2", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_each3")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_with_each3", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup(".")); + }, function() { + return "\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_if1", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n one\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_if2", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n two\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_inclusion1", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("options")); +})); + +Template.__define__("old_spacebars_test_helpers_stop_inclusion2", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("options")); +})); + +Template.__define__("old_spacebars_test_helpers_stop_inclusion3", (function() { + var view = this; + return "blah"; +})); + +Template.__define__("old_spacebars_test_helpers_stop_with_callbacks1", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_callbacks3")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_with_callbacks2", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_stop_with_callbacks3")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_with_callbacks3", (function() { + var view = this; + return "blah"; +})); + +Template.__define__("old_spacebars_test_helpers_stop_unless1", (function() { + var view = this; + return Blaze.Unless(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n one\n "; + }); +})); + +Template.__define__("old_spacebars_test_helpers_stop_unless2", (function() { + var view = this; + return Blaze.Unless(function() { + return Spacebars.call(view.lookup("options")); + }, function() { + return "\n two\n "; + }); +})); + +Template.__define__("old_spacebars_test_no_data_context", (function() { + var view = this; + return [ HTML.Raw("\n "), Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }) ]; +})); + +Template.__define__("old_spacebars_test_falsy_with", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("obj")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("greekLetter")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_helpers_dont_leak", (function() { + var view = this; + return Spacebars.TemplateWith(function() { + return { + foo: Spacebars.call("correct") + }; + }, function() { + return Spacebars.include(view.lookupTemplate("old_spacebars_test_helpers_dont_leak2")); + }); +})); + +Template.__define__("old_spacebars_test_helpers_dont_leak2", (function() { + var view = this; + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }), " ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_content"), function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup("bonus")); + }); + }) ]; +})); + +Template.__define__("old_spacebars_test_event_returns_false", (function() { + var view = this; + return HTML.Raw('click me'); +})); + +Template.__define__("old_spacebars_test_event_selectors1", (function() { + var view = this; + return HTML.DIV(Spacebars.include(view.lookupTemplate("old_spacebars_test_event_selectors2"))); +})); + +Template.__define__("old_spacebars_test_event_selectors2", (function() { + var view = this; + return HTML.Raw('

Not it

\n

It

'); +})); + +Template.__define__("old_spacebars_test_event_selectors_capturing1", (function() { + var view = this; + return HTML.DIV(Spacebars.include(view.lookupTemplate("old_spacebars_test_event_selectors_capturing2"))); +})); + +Template.__define__("old_spacebars_test_event_selectors_capturing2", (function() { + var view = this; + return HTML.Raw('\n
\n \n
'); +})); + +Template.__define__("old_spacebars_test_tables1", (function() { + var view = this; + return HTML.TABLE(HTML.TR(HTML.TD("Foo"))); +})); + +Template.__define__("old_spacebars_test_tables2", (function() { + var view = this; + return HTML.TABLE(HTML.TR(HTML.TD(Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + })))); +})); + +Template.__define__("old_spacebars_test_jquery_events", (function() { + var view = this; + return HTML.Raw(''); +})); + +Template.__define__("old_spacebars_test_tohtml_basic", (function() { + var view = this; + return Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }); +})); + +Template.__define__("old_spacebars_test_tohtml_if", (function() { + var view = this; + return Blaze.If(function() { + return true; + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_tohtml_with", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_tohtml_each", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("foos")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_tohtml_include_with", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("old_spacebars_test_tohtml_with")); +})); + +Template.__define__("old_spacebars_test_tohtml_include_each", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("old_spacebars_test_tohtml_each")); +})); + +Template.__define__("old_spacebars_test_block_comment", (function() { + var view = this; + return "\n "; +})); + +Template.__define__("old_spacebars_test_with_mutated_data_context", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("value")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_url_attribute", (function() { + var view = this; + return [ HTML.A({ + href: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }), "\n ", HTML.A({ + href: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }), "\n ", HTML.FORM({ + action: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }), "\n ", HTML.IMG({ + src: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }), "\n ", HTML.INPUT({ + value: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }) ]; +})); + +Template.__define__("old_spacebars_test_event_handler_cleanup", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_event_handler_cleanup_sub")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_event_handler_cleanup_sub", (function() { + var view = this; + return HTML.Raw("
"); +})); + +Template.__define__("old_spacebars_test_data_context_for_event_handler_in_if", (function() { + var view = this; + return Spacebars.With(function() { + return { + foo: Spacebars.call("bar") + }; + }, function() { + return [ "\n ", Blaze.If(function() { + return true; + }, function() { + return [ "\n ", HTML.SPAN("Click me!"), "\n " ]; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_each_with_autorun_insert", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("items")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("name")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_ui_hooks", (function() { + var view = this; + return HTML.DIV({ + "class": "test-ui-hooks" + }, "\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("items")); + }, function() { + return [ "\n ", HTML.DIV({ + "class": "item" + }, Blaze.View(function() { + return Spacebars.mustache(view.lookup("_id")); + })), "\n " ]; + }), "\n "); +})); + +Template.__define__("old_spacebars_test_ui_hooks_nested", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_ui_hooks_nested_sub")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_ui_hooks_nested_sub", (function() { + var view = this; + return HTML.DIV("\n ", Spacebars.With(function() { + return true; + }, function() { + return [ "\n ", HTML.P("hello"), "\n " ]; + }), "\n "); +})); + +Template.__define__("old_spacebars_test_template_instance_helper", (function() { + var view = this; + return Spacebars.With(function() { + return true; + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }); + }); +})); + +Template.__define__("old_spacebars_test_with_cleanup", (function() { + var view = this; + return HTML.DIV({ + "class": "test-with-cleanup" + }, "\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }), "\n " ]; + }), "\n "); +})); + +Template.__define__("old_spacebars_test_template_parent_data_helper", (function() { + var view = this; + return Spacebars.With(function() { + return "parent"; + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_template_parent_data_helper_child")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_template_parent_data_helper_child", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("a")); + }, function() { + return [ "\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("b")); + }, function() { + return [ "\n ", Blaze.If(function() { + return Spacebars.call(view.lookup("c")); + }, function() { + return [ "\n ", Spacebars.With(function() { + return "d"; + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), "\n " ]; + }), "\n " ]; + }), "\n " ]; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_svg_anchor", (function() { + var view = this; + return HTML.SVG("\n ", HTML.A({ + "xlink:href": "http://www.example.com" + }, "Foo"), "\n "); +})); + +Template.__define__("old_spacebars_test_template_created_rendered_destroyed_each", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("items")); + }, function() { + return [ "\n ", HTML.DIV(Spacebars.TemplateWith(function() { + return Spacebars.call(view.lookup("_id")); + }, function() { + return Spacebars.include(view.lookupTemplate("old_spacebars_test_template_created_rendered_destroyed_each_sub")); + })), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_template_created_rendered_destroyed_each_sub", (function() { + var view = this; + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); +})); + +Template.__define__("old_spacebars_test_ui_getElementData", (function() { + var view = this; + return HTML.Raw(""); +})); + +Template.__define__("old_spacebars_test_ui_render", (function() { + var view = this; + return HTML.SPAN(Blaze.View(function() { + return Spacebars.mustache(view.lookup("greeting")); + }), " ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("r")); + })); +})); + +Template.__define__("old_spacebars_test_parent_removal", (function() { + var view = this; + return HTML.DIV({ + "class": "a" + }, "\n ", HTML.DIV({ + "class": "b" + }, "\n ", HTML.DIV({ + "class": "toremove" + }, "\n ", HTML.DIV({ + "class": "c" + }, "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("A"), 1); + }), "\n ", Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("A"), 2)); + }), "\n ", Spacebars.With(function() { + return Spacebars.dataMustache(view.lookup("A"), 3); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("A"), 4); + }), "\n ", Spacebars.With(function() { + return Spacebars.dataMustache(view.lookup("A"), 5); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("A"), 6); + }), "\n " ]; + }), "\n " ]; + }), "\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("B")); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("A"), 7); + }), "\n " ]; + }), "\n ", Blaze.If(function() { + return Spacebars.dataMustache(view.lookup("A"), 8); + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("A"), 9); + }), "\n " ]; + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("A"), "a"); + }), "\n " ]; + }), "\n "), "\n "), "\n "), "\n "); +})); + +Template.__define__("old_spacebars_test_focus_blur_outer", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return [ "\n a ", Spacebars.include(view.lookupTemplate("old_spacebars_test_focus_blur_inner")), "\n " ]; + }, function() { + return [ "\n b ", Spacebars.include(view.lookupTemplate("old_spacebars_test_focus_blur_inner")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_focus_blur_inner", (function() { + var view = this; + return HTML.Raw(''); +})); + +Template.__define__("old_spacebars_test_event_cleanup_on_destroyed_outer", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("cond")); + }, function() { + return [ "\n ", HTML.DIV("a ", Spacebars.include(view.lookupTemplate("old_spacebars_test_event_cleanup_on_destroyed_inner"))), "\n " ]; + }, function() { + return [ "\n ", HTML.DIV("b ", Spacebars.include(view.lookupTemplate("old_spacebars_test_event_cleanup_on_destroyed_inner"))), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_event_cleanup_on_destroyed_inner", (function() { + var view = this; + return HTML.Raw("foo"); +})); + +Template.__define__("old_spacebars_test_isolated_lookup_inclusion", (function() { + var view = this; + return "x"; +})); + +Template.__define__("old_spacebars_test_isolated_lookup1", (function() { + var view = this; + return [ Spacebars.include(view.lookupTemplate("foo")), "--", Spacebars.include(view.lookupTemplate("old_spacebars_test_isolated_lookup_inclusion")) ]; +})); + +Template.__define__("old_spacebars_test_isolated_lookup2", (function() { + var view = this; + return Spacebars.With(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", Spacebars.With(function() { + return { + z: Spacebars.call(1) + }; + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("..")), "--", Spacebars.include(view.lookupTemplate("old_spacebars_test_isolated_lookup_inclusion")), "\n " ]; + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_isolated_lookup3", (function() { + var view = this; + return [ Spacebars.include(view.lookupTemplate("bar")), "--", Spacebars.include(view.lookupTemplate("old_spacebars_test_isolated_lookup_inclusion")) ]; +})); + +Template.__define__("old_spacebars_test_current_view_in_event", (function() { + var view = this; + return HTML.SPAN(Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + })); +})); + +Template.__define__("old_spacebars_test_textarea_attrs", (function() { + var view = this; + return HTML.TEXTAREA(HTML.Attrs(function() { + return Spacebars.attrMustache(view.lookup("attrs")); + })); +})); + +Template.__define__("old_spacebars_test_textarea_attrs_contents", (function() { + var view = this; + return HTML.TEXTAREA(HTML.Attrs(function() { + return Spacebars.attrMustache(view.lookup("attrs")); + }, { + value: function() { + return [ "Hello ", Spacebars.mustache(view.lookup("name")) ]; + } + })); +})); + +Template.__define__("old_spacebars_test_textarea_attrs_array_contents", (function() { + var view = this; + return HTML.TEXTAREA(HTML.Attrs({ + "class": "bar" + }, function() { + return Spacebars.attrMustache(view.lookup("attrs")); + }, { + value: function() { + return [ "Hello ", Spacebars.mustache(view.lookup("name")) ]; + } + })); +})); + +Template.__define__("old_spacebars_test_autorun", (function() { + var view = this; + return Blaze.If(function() { + return Spacebars.call(view.lookup("show")); + }, function() { + return [ "\n ", Spacebars.include(view.lookupTemplate("old_spacebars_test_autorun_inner")), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_autorun_inner", (function() { + var view = this; + return "Hello"; +})); + +Template.__define__("old_spacebars_test_contentBlock_arg", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("old_spacebars_test_contentBlock_arg_inner"), function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("."), "bar")); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_test_contentBlock_arg_inner", (function() { + var view = this; + return Spacebars.With(function() { + return { + foo: Spacebars.call("AAA"), + bar: Spacebars.call("BBB") + }; + }, function() { + return [ "\n ", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("."), "foo")); + }), " ", Blaze.InOuterTemplateScope(view, function() { + return Spacebars.TemplateWith(function() { + return Spacebars.call(view.lookup(".")); + }, function() { + return Spacebars.include(function() { + return Spacebars.call(view.templateContentBlock); + }); + }); + }), "\n " ]; + }); +})); + +Template.__define__("old_spacebars_template_test_input_field_to_same_value", (function() { + var view = this; + return HTML.INPUT({ + type: "text", + value: function() { + return Spacebars.mustache(view.lookup("foo")); + } + }); +})); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +Template.__define__("old_test_assembly_a0", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("test_assembly_a1")); +})); + +Template.__define__("old_test_assembly_a1", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("test_assembly_a2")); +})); + +Template.__define__("old_test_assembly_a2", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("test_assembly_a3")); +})); + +Template.__define__("old_test_assembly_a3", (function() { + var view = this; + return "Hi"; +})); + +Template.__define__("old_test_assembly_b0", (function() { + var view = this; + return Spacebars.include(view.lookupTemplate("test_assembly_b1")); +})); + +Template.__define__("old_test_assembly_b1", (function() { + var view = this; + return [ "x", Blaze.If(function() { + return Spacebars.call(view.lookup("stuff")); + }, function() { + return "y"; + }), Spacebars.include(view.lookupTemplate("test_assembly_b2")) ]; +})); + +Template.__define__("old_test_assembly_b2", (function() { + var view = this; + return "hi"; +})); + +Template.__define__("old_test_table_b0", (function() { + var view = this; + return HTML.TABLE("\n ", HTML.TBODY("\n ", Spacebars.include(view.lookupTemplate("test_table_b1")), "\n ", Spacebars.include(view.lookupTemplate("test_table_b1")), "\n ", Spacebars.include(view.lookupTemplate("test_table_b1")), "\n "), "\n "); +})); + +Template.__define__("old_test_table_b1", (function() { + var view = this; + return HTML.TR("\n ", Spacebars.include(view.lookupTemplate("test_table_b2")), "\n "); +})); + +Template.__define__("old_test_table_b2", (function() { + var view = this; + return HTML.TD("\n ", Spacebars.include(view.lookupTemplate("test_table_b3")), "\n "); +})); + +Template.__define__("old_test_table_b3", (function() { + var view = this; + return "Foo."; +})); + +Template.__define__("old_test_table_each", (function() { + var view = this; + return HTML.TABLE("\n ", HTML.TBODY("\n ", Blaze.Each(function() { + return Spacebars.call(view.lookup("foo")); + }, function() { + return [ "\n ", HTML.TR(HTML.TD(Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }))), "\n " ]; + }), "\n "), "\n "); +})); + +Template.__define__("old_test_event_data_with", (function() { + var view = this; + return HTML.DIV("\n xxx\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("TWO")); + }, function() { + return [ "\n ", HTML.DIV("\n xxx\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("THREE")); + }, function() { + return [ "\n ", HTML.DIV("\n xxx\n "), "\n " ]; + }), "\n "), "\n " ]; + }), "\n"); +})); + +Template.__define__("old_test_capture_events", (function() { + var view = this; + return HTML.Raw('\n \n '); +})); + +Template.__define__("old_test_safestring_a", (function() { + var view = this; + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), " ", Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("foo"))); + }), " ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }), " ", Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("bar"))); + }), "\n ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("fooprop")); + }), " ", Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("fooprop"))); + }), " ", Blaze.View(function() { + return Spacebars.mustache(view.lookup("barprop")); + }), " ", Blaze.View(function() { + return Spacebars.makeRaw(Spacebars.mustache(view.lookup("barprop"))); + }) ]; +})); + +Template.__define__("old_test_helpers_a", (function() { + var view = this; + return [ "platypus=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("platypus")); + }), "\n watermelon=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("watermelon")); + }), "\n daisy=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("daisy")); + }), "\n tree=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("tree")); + }), "\n warthog=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("warthog")); + }) ]; +})); + +Template.__define__("old_test_helpers_b", (function() { + var view = this; + return [ "unknown=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("unknown")); + }), "\n zero=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("zero")); + }) ]; +})); + +Template.__define__("old_test_helpers_c", (function() { + var view = this; + return [ "platypus.X=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("platypus"), "X")); + }), "\n watermelon.X=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("watermelon"), "X")); + }), "\n daisy.X=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("daisy"), "X")); + }), "\n tree.X=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("tree"), "X")); + }), "\n warthog.X=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("warthog"), "X")); + }), "\n getNull.X=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("getNull"), "X")); + }), "\n getUndefined.X=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("getUndefined"), "X")); + }), "\n getUndefined.X.Y=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("getUndefined"), "X", "Y")); + }) ]; +})); + +Template.__define__("old_test_helpers_d", (function() { + var view = this; + return [ "daisygetter=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("daisygetter")); + }), "\n thisTest=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("thisTest")); + }), "\n ", Spacebars.With(function() { + return Spacebars.call(view.lookup("fancy")); + }, function() { + return [ "\n ../thisTest=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "thisTest")); + }), "\n " ]; + }), "\n ", Spacebars.With(function() { + return "foo"; + }, function() { + return [ "\n ../fancy.currentFruit=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup(".."), "fancy", "currentFruit")); + }), "\n " ]; + }) ]; +})); + +Template.__define__("old_test_helpers_e", (function() { + var view = this; + return [ "fancy.foo=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "foo")); + }), "\n fancy.apple.banana=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "apple", "banana")); + }), "\n fancy.currentFruit=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentFruit")); + }), "\n fancy.currentCountry.name=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentCountry", "name")); + }), "\n fancy.currentCountry.population=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentCountry", "population")); + }), "\n fancy.currentCountry.unicorns=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancy"), "currentCountry", "unicorns")); + }) ]; +})); + +Template.__define__("old_test_helpers_f", (function() { + var view = this; + return [ "fancyhelper.foo=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "foo")); + }), "\n fancyhelper.apple.banana=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "apple", "banana")); + }), "\n fancyhelper.currentFruit=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentFruit")); + }), "\n fancyhelper.currentCountry.name=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "name")); + }), "\n fancyhelper.currentCountry.population=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "population")); + }), "\n fancyhelper.currentCountry.unicorns=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns")); + }) ]; +})); + +Template.__define__("old_test_helpers_g", (function() { + var view = this; + return [ "platypus=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("platypus")); + }), "\n this.platypus=", Blaze.View(function() { + return Spacebars.mustache(Spacebars.dot(view.lookup("."), "platypus")); + }) ]; +})); + +Template.__define__("old_test_helpers_h", (function() { + var view = this; + return [ "(methodListFour 6 7 8 9=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("methodListFour"), 6, 7, 8, 9); + }), ")\n (methodListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("methodListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns")); + }), ")\n (methodListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns a=platypus b=thisTest c=fancyhelper.currentFruit d=fancyhelper.currentCountry.unicorns=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("methodListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns"), Spacebars.kw({ + a: view.lookup("platypus"), + b: view.lookup("thisTest"), + c: Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), + d: Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns") + })); + }), ")\n (helperListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("helperListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns")); + }), ")\n (helperListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns a=platypus b=thisTest c=fancyhelper.currentFruit d=fancyhelper.currentCountry.unicorns=", Blaze.View(function() { + return Spacebars.mustache(view.lookup("helperListFour"), view.lookup("platypus"), view.lookup("thisTest"), Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns"), Spacebars.kw({ + a: view.lookup("platypus"), + b: view.lookup("thisTest"), + c: Spacebars.dot(view.lookup("fancyhelper"), "currentFruit"), + d: Spacebars.dot(view.lookup("fancyhelper"), "currentCountry", "unicorns") + })); + }), ")" ]; +})); + +Template.__define__("old_test_render_a", (function() { + var view = this; + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), HTML.Raw("

") ]; +})); + +Template.__define__("old_test_render_b", (function() { + var view = this; + return Spacebars.With(function() { + return 200; + }, function() { + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), HTML.BR(), HTML.HR() ]; + }); +})); + +Template.__define__("old_test_render_c", (function() { + var view = this; + return HTML.Raw("

"); +})); + +Template.__define__("old_test_template_arg_a", (function() { + var view = this; + return HTML.Raw("Foo Bar Baz"); +})); + +Template.__define__("old_test_template_helpers_a", (function() { + var view = this; + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("foo")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("bar")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("baz")); + }) ]; +})); + +Template.__define__("old_test_template_helpers_b", (function() { + var view = this; + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("name")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("arity")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("toString")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("length")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("var")); + }) ]; +})); + +Template.__define__("old_test_template_helpers_c", (function() { + var view = this; + return [ Blaze.View(function() { + return Spacebars.mustache(view.lookup("name")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("arity")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("length")); + }), Blaze.View(function() { + return Spacebars.mustache(view.lookup("var")); + }), "x" ]; +})); + +Template.__define__("old_test_template_events_a", (function() { + var view = this; + return HTML.Raw("foobarbaz"); +})); + +Template.__define__("old_test_template_events_b", (function() { + var view = this; + return HTML.Raw("foobarbaz"); +})); + +Template.__define__("old_test_template_events_c", (function() { + var view = this; + return HTML.Raw("foobarbaz"); +})); + +Template.__define__("old_test_type_casting", (function() { + var view = this; + return Blaze.View(function() { + return Spacebars.mustache(view.lookup("testTypeCasting"), "true", "false", true, false, 0, 1, -1, 10, -10); + }); +})); + +Template.__define__("old_test_template_issue801", (function() { + var view = this; + return Blaze.Each(function() { + return Spacebars.call(view.lookup("values")); + }, function() { + return Blaze.View(function() { + return Spacebars.mustache(view.lookup(".")); + }); + }); +})); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/packages/spacebars-tests/old_templates_tests.js b/packages/spacebars-tests/old_templates_tests.js new file mode 100644 index 000000000..aa0afc8ec --- /dev/null +++ b/packages/spacebars-tests/old_templates_tests.js @@ -0,0 +1,3189 @@ +// +// This file is used to ensure old built templates still work with the +// new Blaze APIs. More in a comment at the top of old_templates.js +// + +var divRendersTo = function (test, div, html) { + Tracker.flush({ _throwFirstError: true }); + var actual = canonicalizeHtml(div.innerHTML); + test.equal(actual, html); +}; + +var nodesToArray = function (array) { + return Array.from(array); +}; + +Tinytest.add( + 'spacebars-tests - old - template_tests - simple helper', + function (test) { + var tmpl = Template.old_spacebars_template_test_simple_helper; + var R = ReactiveVar(1); + tmpl.foo = function (x) { + return x + R.get(); + }; + tmpl.bar = function () { + return 123; + }; + var div = renderToDiv(tmpl); + + test.equal(canonicalizeHtml(div.innerHTML), '124'); + R.set(2); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '125'); + + // Test that `{{foo bar}}` throws if `foo` is missing or not a function. + tmpl.foo = 3; + test.throws(function () { + renderToDiv(tmpl); + }, /Can't call non-function/); + + delete tmpl.foo; + test.throws(function () { + renderToDiv(tmpl); + }, /No such function/); + + tmpl.foo = function () {}; + // doesn't throw + div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), ''); + + // now "foo" is a function in the data context + delete tmpl.foo; + + R = ReactiveVar(1); + div = renderToDiv(tmpl, { + foo: function (x) { + return x + R.get(); + }, + }); + test.equal(canonicalizeHtml(div.innerHTML), '124'); + R.set(2); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '125'); + + test.throws(function () { + renderToDiv(tmpl, { foo: 3 }); + }, /Can't call non-function/); + + test.throws(function () { + renderToDiv(tmpl, { foo: null }); + }, /No such function/); + + test.throws(function () { + renderToDiv(tmpl, {}); + }, /No such function/); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - dynamic template', + function (test) { + var tmpl = Template.old_spacebars_template_test_dynamic_template; + var aaa = Template.old_spacebars_template_test_aaa; + var bbb = Template.old_spacebars_template_test_bbb; + var R = ReactiveVar('aaa'); + tmpl.foo = function () { + return R.get() === 'aaa' ? aaa : bbb; + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'aaa'); + + R.set('bbb'); + Tracker.flush(); + + test.equal(canonicalizeHtml(div.innerHTML), 'bbb'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - interpolate attribute', + function (test) { + var tmpl = Template.old_spacebars_template_test_interpolate_attribute; + tmpl.foo = function (x) { + return x + 1; + }; + tmpl.bar = function () { + return 123; + }; + var div = renderToDiv(tmpl); + + test.equal($(div).find('div')[0].className, 'aaa124zzz'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - dynamic attrs', + function (test) { + var tmpl = Template.old_spacebars_template_test_dynamic_attrs; + + var R2 = ReactiveVar({ x: 'X' }); + var R3 = ReactiveVar('selected'); + tmpl.attrsObj = function () { + return R2.get(); + }; + tmpl.singleAttr = function () { + return R3.get(); + }; + + var div = renderToDiv(tmpl); + var span = $(div).find('span')[0]; + test.equal(span.innerHTML, 'hi'); + test.isTrue(span.hasAttribute('selected')); + test.equal(span.getAttribute('x'), 'X'); + + R2.set({ y: 'Y', z: 'Z' }); + R3.set(''); + Tracker.flush(); + test.equal(canonicalizeHtml(span.innerHTML), 'hi'); + test.isFalse(span.hasAttribute('selected')); + test.isFalse(span.hasAttribute('x')); + test.equal(span.getAttribute('y'), 'Y'); + test.equal(span.getAttribute('z'), 'Z'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - triple', + function (test) { + var tmpl = Template.old_spacebars_template_test_triple; + + var R = ReactiveVar('blah'); + tmpl.html = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + var elems = $(div).find('> *'); + test.equal(elems.length, 1); + test.equal(elems[0].nodeName, 'SPAN'); + var span = elems[0]; + test.equal(span.className, 'hi'); + test.equal(span.innerHTML, 'blah'); + + R.set('asdf'); + Tracker.flush(); + elems = $(div).find('> *'); + test.equal(elems.length, 0); + test.equal(canonicalizeHtml(div.innerHTML), 'asdf'); + + R.set('blah'); + Tracker.flush(); + elems = $(div).find('> *'); + test.equal(elems.length, 1); + test.equal(elems[0].nodeName, 'SPAN'); + span = elems[0]; + test.equal(span.className, 'hi'); + test.equal(canonicalizeHtml(span.innerHTML), 'blah'); + + var tmpl = Template.old_spacebars_template_test_triple2; + tmpl.html = function () {}; + tmpl.html2 = function () { + return null; + }; + // no tmpl.html3 + div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'xy'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - inclusion args', + function (test) { + var tmpl = Template.old_spacebars_template_test_inclusion_args; + + var R = ReactiveVar(Template.old_spacebars_template_test_aaa); + tmpl.foo = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + // `{{> foo bar}}`, with `foo` resolving to Template.aaa, + // which consists of "aaa" + test.equal(canonicalizeHtml(div.innerHTML), 'aaa'); + R.set(Template.old_spacebars_template_test_bbb); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'bbb'); + + ////// Ok, now `foo` *is* Template.aaa + tmpl.foo = Template.old_spacebars_template_test_aaa; + div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'aaa'); + + ////// Ok, now `foo` is a template that takes an argument; bar is a string. + tmpl.foo = Template.old_spacebars_template_test_bracketed_this; + tmpl.bar = 'david'; + div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), '[david]'); + + ////// Now `foo` is a template that takes an arg; bar is a function. + tmpl.foo = Template.old_spacebars_template_test_span_this; + R = ReactiveVar('david'); + tmpl.bar = function () { + return R.get(); + }; + div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'david'); + var span1 = div.querySelector('span'); + R.set('avi'); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'avi'); + var span2 = div.querySelector('span'); + test.isTrue(span1 === span2); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - inclusion args 2', + function (test) { + // `{{> foo bar q=baz}}` + var tmpl = Template.old_spacebars_template_test_inclusion_args2; + + tmpl.foo = Template.old_spacebars_template_test_span_this; + tmpl.bar = function (options) { + return options.hash.q; + }; + + var R = ReactiveVar('david!'); + tmpl.baz = function () { + return R.get().slice(0, 5); + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'david'); + var span1 = div.querySelector('span'); + R.set('brillo'); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'brill'); + var span2 = div.querySelector('span'); + test.isTrue(span1 === span2); + } +); + +// maybe use created callback on the template instead of this? +var extendTemplateWithInit = function (template, initFunc) { + var tmpl = new Template( + template.viewName + '-extended', + template.renderFunction + ); + tmpl.constructView = function (/*args*/) { + var view = Template.prototype.constructView.apply(this, arguments); + initFunc(view); + return view; + }; + return tmpl; +}; + +Tinytest.add( + 'spacebars-tests - old - template_tests - inclusion dotted args', + function (test) { + // `{{> foo bar.baz}}` + var tmpl = Template.old_spacebars_template_test_inclusion_dotted_args; + + var initCount = 0; + tmpl.foo = extendTemplateWithInit( + Template.old_spacebars_template_test_bracketed_this, + function () { + initCount++; + } + ); + + var R = ReactiveVar('david'); + tmpl.bar = function () { + // make sure `this` is bound correctly + return { baz: this.symbol + R.get() }; + }; + + var div = renderToDiv(tmpl, { symbol: '%' }); + test.equal(initCount, 1); + test.equal(canonicalizeHtml(div.innerHTML), '[%david]'); + + R.set('avi'); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '[%avi]'); + // check that invalidating the argument to `foo` doesn't require + // creating a new `foo`. + test.equal(initCount, 1); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - inclusion slashed args', + function (test) { + // `{{> foo bar/baz}}` + var tmpl = Template.old_spacebars_template_test_inclusion_dotted_args; + + var initCount = 0; + tmpl.foo = extendTemplateWithInit( + Template.old_spacebars_template_test_bracketed_this, + function () { + initCount++; + } + ); + var R = ReactiveVar('david'); + tmpl.bar = function () { + // make sure `this` is bound correctly + return { baz: this.symbol + R.get() }; + }; + + var div = renderToDiv(tmpl, { symbol: '%' }); + test.equal(initCount, 1); + test.equal(canonicalizeHtml(div.innerHTML), '[%david]'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block helper', + function (test) { + // test the case where `foo` is a calculated template that changes + // reactively. + // `{{#foo}}bar{{else}}baz{{/foo}}` + var tmpl = Template.old_spacebars_template_test_block_helper; + var R = ReactiveVar(Template.old_spacebars_template_test_content); + tmpl.foo = function () { + return R.get(); + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'bar'); + + R.set(Template.old_spacebars_template_test_elsecontent); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'baz'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block helper function with one string arg', + function (test) { + // `{{#foo "bar"}}content{{/foo}}` + var tmpl = + Template.old_spacebars_template_test_block_helper_function_one_string_arg; + tmpl.foo = function () { + if (String(this) === 'bar') + return Template.old_spacebars_template_test_content; + else return null; + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'content'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block helper function with one helper arg', + function (test) { + var tmpl = + Template.old_spacebars_template_test_block_helper_function_one_helper_arg; + var R = ReactiveVar('bar'); + tmpl.bar = function () { + return R.get(); + }; + tmpl.foo = function () { + if (String(this) === 'bar') + return Template.old_spacebars_template_test_content; + else return null; + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'content'); + + R.set('baz'); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), ''); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block helper component with one helper arg', + function (test) { + var tmpl = + Template.old_spacebars_template_test_block_helper_component_one_helper_arg; + var R = ReactiveVar(true); + tmpl.bar = function () { + return R.get(); + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'content'); + + R.set(false); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), ''); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block helper component with three helper args', + function (test) { + var tmpl = + Template.old_spacebars_template_test_block_helper_component_three_helper_args; + var R = ReactiveVar('bar'); + tmpl.bar_or_baz = function () { + return R.get(); + }; + tmpl.equals = function (x, y) { + return x === y; + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'content'); + + R.set('baz'); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), ''); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block helper with dotted arg', + function (test) { + var tmpl = Template.old_spacebars_template_test_block_helper_dotted_arg; + var R1 = ReactiveVar(1); + var R2 = ReactiveVar(10); + var R3 = ReactiveVar(100); + + var initCount = 0; + tmpl.foo = extendTemplateWithInit( + Template.old_spacebars_template_test_bracketed_this, + function () { + initCount++; + } + ); + tmpl.bar = function () { + return { + r1: R1.get(), + baz: function (r3) { + return this.r1 + R2.get() + r3; + }, + }; + }; + tmpl.qux = function () { + return R3.get(); + }; + + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), '[111]'); + test.equal(initCount, 1); + + R1.set(2); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '[112]'); + test.equal(initCount, 1); + + R2.set(20); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '[122]'); + test.equal(initCount, 1); + + R3.set(200); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '[222]'); + test.equal(initCount, 1); + + R2.set(30); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '[232]'); + test.equal(initCount, 1); + + R1.set(3); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '[233]'); + test.equal(initCount, 1); + + R3.set(300); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '[333]'); + test.equal(initCount, 1); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - nested content', + function (test) { + // Test that `{{> UI.contentBlock}}` in an `{{#if}}` works. + + // ``` + // + // ``` + + // ``` + // {{#spacebars_template_test_iftemplate flag}} + // hello + // {{else}} + // world + // {{/spacebars_template_test_iftemplate}} + // ``` + + var tmpl = Template.old_spacebars_template_test_nested_content; + var R = ReactiveVar(true); + tmpl.flag = function () { + return R.get(); + }; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'hello'); + R.set(false); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'world'); + R.set(true); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'hello'); + + // Also test that `{{> UI.contentBlock}}` in a custom block helper works. + tmpl = Template.old_spacebars_template_test_nested_content2; + R = ReactiveVar(true); + tmpl.x = function () { + return R.get(); + }; + div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'hello'); + R.set(false); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'world'); + R.set(true); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'hello'); + } +); + +Tinytest.add('spacebars-tests - old - template_tests - if', function (test) { + var tmpl = Template.old_spacebars_template_test_if; + var R = ReactiveVar(true); + tmpl.foo = function () { + return R.get(); + }; + tmpl.bar = 1; + tmpl.baz = 2; + + var div = renderToDiv(tmpl); + var rendersTo = function (html) { + divRendersTo(test, div, html); + }; + + rendersTo('1'); + R.set(false); + rendersTo('2'); +}); + +Tinytest.add( + 'spacebars-tests - old - template_tests - if in with', + function (test) { + var tmpl = Template.old_spacebars_template_test_if_in_with; + tmpl.foo = { bar: 'bar' }; + + var div = renderToDiv(tmpl); + divRendersTo(test, div, 'bar bar'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - each on cursor', + function (test) { + var tmpl = Template.old_spacebars_template_test_each; + var coll = new Mongo.Collection(null); + tmpl.items = function () { + return coll.find({}, { sort: { pos: 1 } }); + }; + + var div = renderToDiv(tmpl); + var rendersTo = function (html) { + divRendersTo(test, div, html); + }; + + rendersTo('else-clause'); + coll.insert({ text: 'one', pos: 1 }); + rendersTo('one'); + coll.insert({ text: 'two', pos: 2 }); + rendersTo('one two'); + coll.update({ text: 'two' }, { $set: { text: 'three' } }); + rendersTo('one three'); + coll.update({ text: 'three' }, { $set: { pos: 0 } }); + rendersTo('three one'); + coll.remove({}); + rendersTo('else-clause'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - each on array', + function (test) { + var tmpl = Template.old_spacebars_template_test_each; + var R = new ReactiveVar([]); + tmpl.items = function () { + return R.get(); + }; + tmpl.text = function () { + return this; + }; + + var div = renderToDiv(tmpl); + var rendersTo = function (html) { + divRendersTo(test, div, html); + }; + + rendersTo('else-clause'); + R.set(['']); + rendersTo(''); + R.set(['x', '', 'toString']); + rendersTo('x toString'); + R.set(['toString']); + rendersTo('toString'); + R.set([]); + rendersTo('else-clause'); + R.set([0, 1, 2]); + rendersTo('0 1 2'); + R.set([]); + rendersTo('else-clause'); + } +); + +Tinytest.add('spacebars-tests - old - template_tests - ..', function (test) { + var tmpl = Template.old_spacebars_template_test_dots; + Template.old_spacebars_template_test_dots_subtemplate.getTitle = function ( + from + ) { + return from.title; + }; + + tmpl.foo = { title: 'foo' }; + tmpl.foo.bar = { title: 'bar' }; + tmpl.foo.bar.items = [{ title: 'item' }]; + var div = renderToDiv(tmpl); + + test.equal( + canonicalizeHtml(div.innerHTML), + [ + 'A', + 'B', + 'C', + 'D', + // {{> spacebars_template_test_dots_subtemplate}} + 'TITLE', + '1item', + '2item', + '3bar', + '4foo', + 'GETTITLE', + '5item', + '6bar', + '7foo', + // {{> spacebars_template_test_dots_subtemplate ..}} + 'TITLE', + '1bar', + '2bar', + '3item', + '4bar', + 'GETTITLE', + '5bar', + '6item', + '7bar', + ].join(' ') + ); +}); + +Tinytest.add( + 'spacebars-tests - old - template_tests - select tags', + function (test) { + var tmpl = Template.old_spacebars_template_test_select_tag; + + // {label: (string)} + var optgroups = new Mongo.Collection(null); + + // {optgroup: (id), value: (string), selected: (boolean), label: (string)} + var options = new Mongo.Collection(null); + + tmpl.optgroups = function () { + return optgroups.find(); + }; + tmpl.options = function () { + return options.find({ optgroup: this._id }); + }; + tmpl.selectedAttr = function () { + return this.selected ? { selected: true } : {}; + }; + + var div = renderToDiv(tmpl); + var selectEl = $(div).find('select')[0]; + + // returns canonicalized contents of `div` in the form eg + // [""]. strip out selected attributes -- we + // verify correctness by observing the `selected` property + var divContent = function () { + return canonicalizeHtml( + div.innerHTML.replace(/selected="[^"]*"/g, '').replace(/selected/g, '') + ) + .replace(/\>\s*\\n<') + .split('\n'); + }; + + test.equal(divContent(), ['']); + + var optgroup1 = optgroups.insert({ label: 'one' }); + var optgroup2 = optgroups.insert({ label: 'two' }); + test.equal(divContent(), [ + '', + ]); + + options.insert({ + optgroup: optgroup1, + value: 'value1', + selected: false, + label: 'label1', + }); + options.insert({ + optgroup: optgroup1, + value: 'value2', + selected: true, + label: 'label2', + }); + test.equal(divContent(), [ + '', + ]); + test.equal(selectEl.value, 'value2'); + test.equal($(selectEl).find('option')[0].selected, false); + test.equal($(selectEl).find('option')[1].selected, true); + + // swap selection + options.update({ value: 'value1' }, { $set: { selected: true } }); + options.update({ value: 'value2' }, { $set: { selected: false } }); + Tracker.flush(); + + test.equal(divContent(), [ + '', + ]); + test.equal(selectEl.value, 'value1'); + test.equal($(selectEl).find('option')[0].selected, true); + test.equal($(selectEl).find('option')[1].selected, false); + + // change value and label + options.update({ value: 'value1' }, { $set: { value: 'value1.0' } }); + options.update({ value: 'value2' }, { $set: { label: 'label2.0' } }); + Tracker.flush(); + + test.equal(divContent(), [ + '', + ]); + test.equal(selectEl.value, 'value1.0'); + test.equal($(selectEl).find('option')[0].selected, true); + test.equal($(selectEl).find('option')[1].selected, false); + + // unselect and then select both options. normally, the second is + // selected (since it got selected later). then switch to '.slice(0, 30) + ); + + R.set('bar'); + Tracker.flush(); + test.equal( + canonicalizeHtml(div.innerHTML), + '' + ); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - no data context', + function (test) { + var tmpl = Template.old_spacebars_template_test_no_data; + + // failure is if an exception is thrown here + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'asdf'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - textarea', + function (test) { + var tmpl = Template.old_spacebars_template_test_textarea; + + var R = ReactiveVar('hello'); + + tmpl.foo = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + var textarea = div.querySelector('textarea'); + test.equal(textarea.value, 'hello'); + + R.set('world'); + Tracker.flush(); + test.equal(textarea.value, 'world'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - textarea 2', + function (test) { + var tmpl = Template.old_spacebars_template_test_textarea2; + + var R = ReactiveVar(true); + + tmpl.foo = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + var textarea = div.querySelector('textarea'); + test.equal(textarea.value, '
'); + + R.set(false); + Tracker.flush(); + test.equal(textarea.value, ''); + + R.set(true); + Tracker.flush(); + test.equal(textarea.value, ''); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - textarea 3', + function (test) { + var tmpl = Template.old_spacebars_template_test_textarea3; + + var R = ReactiveVar('hello'); + + tmpl.foo = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + var textarea = div.querySelector('textarea'); + test.equal(textarea.id, 'myTextarea'); + test.equal(textarea.value, 'hello'); + + R.set('world'); + Tracker.flush(); + test.equal(textarea.value, 'world'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - textarea each', + function (test) { + var tmpl = Template.old_spacebars_template_test_textarea_each; + + var R = ReactiveVar(['APPLE', 'BANANA']); + + tmpl.foo = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + var textarea = div.querySelector('textarea'); + test.equal(textarea.value, ''); + + R.set(['CUCUMBER']); + Tracker.flush(); + test.equal(textarea.value, 'Smurf') result = '
Smurf
'; // e.g. IE 9 and 10 + test.equal(result, '
Smurf
'); + }; + + shouldBe('donut frankfurter noodle'); + coll.remove({ name: 'frankfurter' }); // (it was kind of a mouthful) + shouldBe('donut noodle'); + coll.remove({ name: 'donut' }); + shouldBe('noodle'); + coll.remove({ name: 'noodle' }); + shouldBe(''); // 'David' and 'Steve' appear in the #each but fail the #if + coll.remove({}); + shouldBe('none'); // now the `{{else}}` case kicks in + coll.insert({ name: 'bubblegum' }); + shouldBe('bubblegum'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block helpers in attribute 2', + function (test) { + var tmpl = + Template.old_spacebars_template_test_block_helpers_in_attribute_2; + + var R = ReactiveVar(true); + + tmpl.foo = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + var input = div.querySelector('input'); + + test.equal(input.value, '"'); + R.set(false); + Tracker.flush(); + test.equal(input.value, '&<>'); + } +); + +// Test that if the argument to #each is a constant, it doesn't establish a +// dependency on the data context, so when the context changes, items of +// the #each are not "changed" and helpers do not rerun. +Tinytest.add( + 'spacebars-tests - old - template_tests - constant #each argument', + function (test) { + var tmpl = Template.old_spacebars_template_test_constant_each_argument; + + var justReturnRuns = 0; // how many times `justReturn` is called + var R = ReactiveVar(1); + + tmpl.someData = function () { + return R.get(); + }; + tmpl.anArray = ['foo', 'bar']; + tmpl.justReturn = function (x) { + justReturnRuns++; + return String(x); + }; + + var div = renderToDiv(tmpl); + + test.equal(justReturnRuns, 2); + test.equal( + canonicalizeHtml(div.innerHTML).replace(/\s+/g, ' '), + 'foo bar 1' + ); + + R.set(2); + Tracker.flush(); + + test.equal(justReturnRuns, 2); // still 2, no new runs! + test.equal( + canonicalizeHtml(div.innerHTML).replace(/\s+/g, ' '), + 'foo bar 2' + ); + } +); + +Tinytest.addAsync( + 'spacebars-tests - old - template_tests - #markdown - basic', + function (test, onComplete) { + var tmpl = Template.old_spacebars_template_test_markdown_basic; + tmpl.obj = { snippet: 'hi' }; + tmpl.hi = function () { + return this.snippet; + }; + var div = renderToDiv(tmpl); + + Meteor.call('getAsset', 'markdown_basic.html', function (err, html) { + test.isFalse(err); + test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(html)); + onComplete(); + }); + } +); + +testAsyncMulti('spacebars-tests - old - template_tests - #markdown - if', [ + function (test, expect) { + var self = this; + Meteor.call( + 'getAsset', + 'markdown_if1.html', + expect(function (err, html) { + test.isFalse(err); + self.html1 = html; + }) + ); + Meteor.call( + 'getAsset', + 'markdown_if2.html', + expect(function (err, html) { + test.isFalse(err); + self.html2 = html; + }) + ); + }, + + function (test, expect) { + var self = this; + var tmpl = Template.old_spacebars_template_test_markdown_if; + var R = new ReactiveVar(false); + tmpl.cond = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html1)); + R.set(true); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html2)); + }, +]); + +testAsyncMulti('spacebars-tests - old - template_tests - #markdown - each', [ + function (test, expect) { + var self = this; + Meteor.call( + 'getAsset', + 'markdown_each1.html', + expect(function (err, html) { + test.isFalse(err); + self.html1 = html; + }) + ); + Meteor.call( + 'getAsset', + 'markdown_each2.html', + expect(function (err, html) { + test.isFalse(err); + self.html2 = html; + }) + ); + }, + + function (test, expect) { + var self = this; + var tmpl = Template.old_spacebars_template_test_markdown_each; + var R = new ReactiveVar([]); + tmpl.seq = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html1)); + + R.set(['item']); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), canonicalizeHtml(self.html2)); + }, +]); + +Tinytest.add( + 'spacebars-tests - old - template_tests - #markdown - inclusion', + function (test) { + var tmpl = Template.old_spacebars_template_test_markdown_inclusion; + var subtmpl = + Template.old_spacebars_template_test_markdown_inclusion_subtmpl; + subtmpl.foo = 'bar'; + var div = renderToDiv(tmpl); + test.equal( + canonicalizeHtml(div.innerHTML), + '

Foo is bar.

' + ); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - #markdown - block helpers', + function (test) { + var tmpl = Template.old_spacebars_template_test_markdown_block_helpers; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), '

Hi there!

'); + } +); + +// Test that when a simple helper re-runs due to a dependency changing +// but the return value is the same, the DOM text node is not +// re-rendered. +Tinytest.add( + 'spacebars-tests - old - template_tests - simple helpers are isolated', + function (test) { + var runs = [ + { + helper: function () { + return 'foo'; + }, + nodeValue: 'foo', + }, + { + helper: function () { + return new Spacebars.SafeString('bar'); + }, + nodeValue: 'bar', + }, + ]; + + runs.forEach(function (run) { + var tmpl = + Template.old_spacebars_template_test_simple_helpers_are_isolated; + var dep = new Tracker.Dependency(); + tmpl.foo = function () { + dep.depend(); + return run.helper(); + }; + var div = renderToDiv(tmpl); + var fooTextNode = Array.from(div.childNodes).find(function (node) { + return node.nodeValue === run.nodeValue; + }); + + test.isTrue(fooTextNode); + + dep.changed(); + Tracker.flush(); + var newFooTextNode = Array.from(div.childNodes).find(function (node) { + return node.nodeValue === run.nodeValue; + }); + + test.equal(fooTextNode, newFooTextNode); + }); + } +); + +// Test that when a helper in an element attribute re-runs due to a +// dependency changing but the return value is the same, the attribute +// value is not set. +Tinytest.add( + 'spacebars-tests - old - template_tests - attribute helpers are isolated', + function (test) { + var tmpl = Template.old_spacebars_template_test_attr_helpers_are_isolated; + var dep = new Tracker.Dependency(); + tmpl.foo = function () { + dep.depend(); + return 'foo'; + }; + var div = renderToDiv(tmpl); + var pElement = div.querySelector('p'); + + test.equal(pElement.getAttribute('attr'), 'foo'); + + // set the attribute to something else, afterwards check that it + // hasn't been updated back to the correct value. + pElement.setAttribute('attr', 'not-foo'); + dep.changed(); + Tracker.flush(); + test.equal(pElement.getAttribute('attr'), 'not-foo'); + } +); + +// A helper can return an object with a set of element attributes via +// `

`. When it re-runs due to a dependency changing the +// value for a given attribute might stay the same. Test that the +// attribute is not set on the DOM element. +Tinytest.add( + 'spacebars-tests - old - template_tests - attribute object helpers are isolated', + function (test) { + var tmpl = + Template.old_spacebars_template_test_attr_object_helpers_are_isolated; + var dep = new Tracker.Dependency(); + tmpl.attrs = function () { + dep.depend(); + return { foo: 'bar' }; + }; + var div = renderToDiv(tmpl); + var pElement = div.querySelector('p'); + + test.equal(pElement.getAttribute('foo'), 'bar'); + + // set the attribute to something else, afterwards check that it + // hasn't been updated back to the correct value. + pElement.setAttribute('foo', 'not-bar'); + dep.changed(); + Tracker.flush(); + test.equal(pElement.getAttribute('foo'), 'not-bar'); + } +); + +// Test that when a helper in an inclusion directive (`{{> foo }}`) +// re-runs due to a dependency changing but the return value is the +// same, the template is not re-rendered. +// +// Also, verify that an error is thrown if the return value from such +// a helper is not a component. +Tinytest.add( + 'spacebars-tests - old - template_tests - inclusion helpers are isolated', + function (test) { + var tmpl = + Template.old_spacebars_template_test_inclusion_helpers_are_isolated; + var dep = new Tracker.Dependency(); + var subtmpl = + Template.old_spacebars_template_test_inclusion_helpers_are_isolated_subtemplate; + // make a copy so we can set "rendered" without mutating the original + var subtmplCopy = new Template(subtmpl.viewName, subtmpl.renderFunction); + + var R = new ReactiveVar(subtmplCopy); + tmpl.foo = function () { + dep.depend(); + return R.get(); + }; + + var div = renderToDiv(tmpl); + subtmplCopy.rendered = function () { + test.fail("shouldn't re-render when same value returned from helper"); + }; + + dep.changed(); + Tracker.flush({ _throwFirstError: true }); // `subtmplCopy.rendered` not called + + R.set(null); + Tracker.flush({ _throwFirstError: true }); // no error thrown + + R.set('neither a component nor null'); + + test.throws(function () { + Tracker.flush({ _throwFirstError: true }); + }, /Expected template or null/); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - nully attributes', + function (test) { + var tmpls = { + 0: Template.old_spacebars_template_test_nully_attributes0, + 1: Template.old_spacebars_template_test_nully_attributes1, + 2: Template.old_spacebars_template_test_nully_attributes2, + 3: Template.old_spacebars_template_test_nully_attributes3, + 4: Template.old_spacebars_template_test_nully_attributes4, + 5: Template.old_spacebars_template_test_nully_attributes5, + 6: Template.old_spacebars_template_test_nully_attributes6, + }; + + var run = function (whichTemplate, data, expectTrue) { + var div = renderToDiv(tmpls[whichTemplate], data); + var input = div.querySelector('input'); + var descr = JSON.stringify([whichTemplate, data, expectTrue]); + if (expectTrue) { + test.isTrue(input.checked, descr); + test.equal(typeof input.getAttribute('stuff'), 'string', descr); + } else { + test.isFalse(input.checked); + test.equal(JSON.stringify(input.getAttribute('stuff')), 'null', descr); + } + + var html = Blaze.toHTML( + Blaze.With(data, function () { + return tmpls[whichTemplate]; + }) + ); + + test.equal(/ checked="[^"]*"/.test(html), !!expectTrue); + test.equal(/ stuff="[^"]*"/.test(html), !!expectTrue); + }; + + run(0, {}, true); + + var truthies = [true, '']; + var falsies = [false, null, undefined]; + + truthies.forEach(function (x) { + run(1, { foo: x }, true); + }); + falsies.forEach(function (x) { + run(1, { foo: x }, false); + }); + + truthies.forEach(function (x) { + truthies.forEach(function (y) { + run(2, { foo: x, bar: y }, true); + }); + falsies.forEach(function (y) { + run(2, { foo: x, bar: y }, true); + }); + }); + falsies.forEach(function (x) { + truthies.forEach(function (y) { + run(2, { foo: x, bar: y }, true); + }); + falsies.forEach(function (y) { + run(2, { foo: x, bar: y }, false); + }); + }); + + run(3, { foo: true }, false); + run(3, { foo: false }, false); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - double', + function (test) { + var tmpl = Template.old_spacebars_template_test_double; + + var run = function (foo, expectedResult) { + tmpl.foo = foo; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), expectedResult); + }; + + run('asdf', 'asdf'); + run(1.23, '1.23'); + run(0, '0'); + run(true, 'true'); + run(false, ''); + run(null, ''); + run(undefined, ''); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - inclusion lookup order', + function (test) { + // test that {{> foo}} looks for a helper named 'foo', then a + // template named 'foo', then a 'foo' field in the data context. + var tmpl = Template.old_spacebars_template_test_inclusion_lookup; + var tmplData = function () { + return { + // shouldn't have an effect since we define a helper with the + // same name. + old_spacebars_template_test_inclusion_lookup_subtmpl: + Template.old_spacebars_template_test_inclusion_lookup_subtmpl3, + dataContextSubtmpl: + Template.old_spacebars_template_test_inclusion_lookup_subtmpl3, + }; + }; + + tmpl.old_spacebars_template_test_inclusion_lookup_subtmpl = + Template.old_spacebars_template_test_inclusion_lookup_subtmpl2; + + test.equal( + canonicalizeHtml(renderToDiv(tmpl, tmplData).innerHTML), + [ + 'This is generated by a helper with the same name.', + 'This is a template passed in the data context.', + ].join(' ') + ); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - content context', + function (test) { + var tmpl = Template.old_spacebars_template_test_content_context; + var R = ReactiveVar(true); + tmpl.foo = { + firstLetter: 'F', + secondLetter: 'O', + bar: { + cond: function () { + return R.get(); + }, + firstLetter: 'B', + secondLetter: 'A', + }, + }; + + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'BO'); + R.set(false); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'FA'); + } +); + +[ + 'textarea', + 'text', + 'password', + 'submit', + 'button', + 'reset', + 'select', + 'hidden', +].forEach(function (type) { + Tinytest.add( + 'spacebars-tests - old - template_tests - controls - ' + type, + function (test) { + var R = ReactiveVar({ x: 'test' }); + var R2 = ReactiveVar(''); + var tmpl; + + if (type === 'select') { + tmpl = Template.old_spacebars_test_control_select; + tmpl.options = [ + 'This is a test', + 'This is a fridge', + 'This is a frog', + 'This is a new frog', + 'foobar', + 'This is a photograph', + 'This is a monkey', + 'This is a donkey', + ]; + tmpl.selected = function () { + R2.get(); // Re-render when R2 is changed, even though it + // doesn't affect HTML. + return 'This is a ' + R.get().x === this.toString(); + }; + } else if (type === 'textarea') { + tmpl = Template.old_spacebars_test_control_textarea; + tmpl.value = function () { + R2.get(); // Re-render when R2 is changed, even though it + // doesn't affect HTML. + return 'This is a ' + R.get().x; + }; + } else { + tmpl = Template.old_spacebars_test_control_input; + tmpl.value = function () { + R2.get(); // Re-render when R2 is changed, even though it + // doesn't affect HTML. + return 'This is a ' + R.get().x; + }; + tmpl.type = type; + } + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + var canFocus = type !== 'hidden'; + + // find first element child, ignoring any marker nodes + var input = div.firstChild; + while (input.nodeType !== 1) input = input.nextSibling; + + if (type === 'textarea' || type === 'select') { + test.equal(input.nodeName, type.toUpperCase()); + } else { + test.equal(input.nodeName, 'INPUT'); + test.equal(input.type, type); + } + test.equal(DomUtils.getElementValue(input), 'This is a test'); + + // value updates reactively + R.set({ x: 'fridge' }); + Tracker.flush(); + test.equal(DomUtils.getElementValue(input), 'This is a fridge'); + + if (canFocus) { + // ...if focused, it still updates but focus isn't lost. + focusElement(input); + DomUtils.setElementValue(input, 'something else'); + R.set({ x: 'frog' }); + + Tracker.flush(); + test.equal(DomUtils.getElementValue(input), 'This is a frog'); + test.equal(document.activeElement, input); + } + + // Setting a value (similar to user typing) should prevent value from being + // reverted if the div is re-rendered but the rendered value (ie, R) does + // not change. + DomUtils.setElementValue(input, 'foobar'); + R2.set('change'); + Tracker.flush(); + test.equal(DomUtils.getElementValue(input), 'foobar'); + + // ... but if the actual rendered value changes, that should take effect. + R.set({ x: 'photograph' }); + Tracker.flush(); + test.equal(DomUtils.getElementValue(input), 'This is a photograph'); + + document.body.removeChild(div); + } + ); +}); + +Tinytest.add('spacebars-tests - old - template_tests - radio', function (test) { + var R = ReactiveVar(''); + var R2 = ReactiveVar(''); + var change_buf = []; + var tmpl = Template.old_spacebars_test_control_radio; + tmpl.bands = ['AM', 'FM', 'XM']; + tmpl.isChecked = function () { + return R.get() === this.toString(); + }; + tmpl.band = function () { + return R.get(); + }; + tmpl.events({ + 'change input': function (event) { + var btn = event.target; + var band = btn.value; + change_buf.push(band); + R.set(band); + }, + }); + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + + // get the three buttons; they should not change identities! + var btns = nodesToArray(div.getElementsByTagName('INPUT')); + var text = function () { + var text = div.innerText || div.textContent; + return text.replace(/[ \n\r]+/g, ' ').replace(/^\s+|\s+$/g, ''); + }; + + test.equal(btns.map(x => x.checked), [false, false, false]); + test.equal(text(), 'Band:'); + + clickIt(btns[0]); + test.equal(change_buf, ['AM']); + change_buf.length = 0; + Tracker.flush(); + test.equal(btns.map(x => x.checked), [true, false, false]); + test.equal(text(), 'Band: AM'); + + R2.set('change'); + Tracker.flush(); + test.length(change_buf, 0); + test.equal(btns.map(x => x.checked), [true, false, false]); + test.equal(text(), 'Band: AM'); + + clickIt(btns[1]); + test.equal(change_buf, ['FM']); + change_buf.length = 0; + Tracker.flush(); + test.equal(btns.map(x => x.checked), [false, true, false]); + test.equal(text(), 'Band: FM'); + + clickIt(btns[2]); + test.equal(change_buf, ['XM']); + change_buf.length = 0; + Tracker.flush(); + test.equal(btns.map(x => x.checked), [false, false, true]); + test.equal(text(), 'Band: XM'); + + clickIt(btns[1]); + test.equal(change_buf, ['FM']); + change_buf.length = 0; + Tracker.flush(); + test.equal(btns.map(x => x.checked), [false, true, false]); + test.equal(text(), 'Band: FM'); + + document.body.removeChild(div); +}); + +Tinytest.add( + 'spacebars-tests - old - template_tests - checkbox', + function (test) { + var tmpl = Template.old_spacebars_test_control_checkbox; + tmpl.labels = ['Foo', 'Bar', 'Baz']; + var Rs = {}; + tmpl.labels.forEach(function (label) { + Rs[label] = ReactiveVar(false); + }); + tmpl.isChecked = function () { + return Rs[this.toString()].get(); + }; + var changeBuf = []; + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + + var boxes = nodesToArray(div.getElementsByTagName('INPUT')); + + test.equal(boxes.map(x => x.checked), [false, false, false]); + + // Re-render with first one checked. + Rs.Foo.set(true); + Tracker.flush(); + test.equal(boxes.map(x => x.checked), [true, false, false]); + + // Re-render with first one unchecked again. + Rs.Foo.set(false); + Tracker.flush(); + test.equal(boxes.map(x => x.checked), [false, false, false]); + + // User clicks the second one. + clickElement(boxes[1]); + test.equal(boxes.map(x => x.checked), [false, true, false]); + Tracker.flush(); + test.equal(boxes.map(x => x.checked), [false, true, false]); + + // Re-render with third one checked. Second one should stay checked because + // it's a user update! + Rs.Baz.set(true); + Tracker.flush(); + test.equal(boxes.map(x => x.checked), [false, true, true]); + + // User turns second and third off. + clickElement(boxes[1]); + clickElement(boxes[2]); + test.equal(boxes.map(x => x.checked), [false, false, false]); + Tracker.flush(); + test.equal(boxes.map(x => x.checked), [false, false, false]); + + // Re-render with first one checked. Third should stay off because it's a user + // update! + Rs.Foo.set(true); + Tracker.flush(); + test.equal(boxes.map(x => x.checked), [true, false, false]); + + // Re-render with first one unchecked. Third should still stay off. + Rs.Foo.set(false); + Tracker.flush(); + test.equal(boxes.map(x => x.checked), [false, false, false]); + + document.body.removeChild(div); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - unfound template', + function (test) { + test.throws(function () { + renderToDiv(Template.old_spacebars_test_nonexistent_template); + }, /No such template/); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - helper passed to #if called exactly once when invalidated', + function (test) { + var tmpl = Template.old_spacebars_test_if_helper; + + var count = 0; + var d = new Tracker.Dependency(); + tmpl.foo = function () { + d.depend(); + count++; + return foo; + }; + + foo = false; + var div = renderToDiv(tmpl); + divRendersTo(test, div, 'false'); + test.equal(count, 1); + + foo = true; + d.changed(); + divRendersTo(test, div, 'true'); + test.equal(count, 2); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - custom block helper functions called exactly once when invalidated', + function (test) { + var tmpl = Template.old_spacebars_test_block_helper_function; + + var count = 0; + var d = new Tracker.Dependency(); + tmpl.foo = function () { + d.depend(); + count++; + return Template.old_spacebars_template_test_aaa; + }; + + foo = false; + renderToDiv(tmpl); + Tracker.flush(); + test.equal(count, 1); + + foo = true; + d.changed(); + Tracker.flush(); + test.equal(count, 2); + } +); + +var runOneTwoTest = function (test, subTemplateName, optionsData) { + [ + Template.old_spacebars_test_helpers_stop_onetwo, + Template.old_spacebars_test_helpers_stop_onetwo_attribute, + ].forEach(function (tmpl) { + tmpl.one = Template[subTemplateName + '1']; + tmpl.two = Template[subTemplateName + '2']; + + var buf = ''; + + var showOne = ReactiveVar(true); + var dummy = ReactiveVar(0); + + tmpl.showOne = function () { + return showOne.get(); + }; + tmpl.one.options = function () { + var x = dummy.get(); + buf += '1'; + if (optionsData) return optionsData[x]; + else return ['something']; + }; + tmpl.two.options = function () { + var x = dummy.get(); + buf += '2'; + if (optionsData) return optionsData[x]; + else return ['something']; + }; + + var div = renderToDiv(tmpl); + Tracker.flush(); + test.equal(buf, '1'); + + showOne.set(false); + dummy.set(1); + Tracker.flush(); + test.equal(buf, '12'); + + showOne.set(true); + dummy.set(2); + Tracker.flush(); + test.equal(buf, '121'); + + // clean up the div + $(div).remove(); + test.equal(showOne._numListeners(), 0); + test.equal(dummy._numListeners(), 0); + }); +}; + +Tinytest.add( + 'spacebars-tests - old - template_tests - with stops without re-running helper', + function (test) { + runOneTwoTest(test, 'old_spacebars_test_helpers_stop_with'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - each stops without re-running helper', + function (test) { + runOneTwoTest(test, 'old_spacebars_test_helpers_stop_each'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - each inside with stops without re-running helper', + function (test) { + runOneTwoTest(test, 'old_spacebars_test_helpers_stop_with_each'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - if stops without re-running helper', + function (test) { + runOneTwoTest(test, 'old_spacebars_test_helpers_stop_if', ['a', 'b', 'a']); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - unless stops without re-running helper', + function (test) { + runOneTwoTest(test, 'old_spacebars_test_helpers_stop_unless', [ + 'a', + 'b', + 'a', + ]); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - inclusion stops without re-running function', + function (test) { + var t = Template.old_spacebars_test_helpers_stop_inclusion3; + runOneTwoTest(test, 'old_spacebars_test_helpers_stop_inclusion', [t, t, t]); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - template with callbacks inside with stops without recalculating data', + function (test) { + var tmpl = Template.old_spacebars_test_helpers_stop_with_callbacks3; + tmpl.created = function () {}; + tmpl.rendered = function () {}; + tmpl.destroyed = function () {}; + runOneTwoTest(test, 'old_spacebars_test_helpers_stop_with_callbacks'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - no data context is seen as an empty object', + function (test) { + var tmpl = Template.old_spacebars_test_no_data_context; + + var dataInHelper = 'UNSET'; + var dataInRendered = 'UNSET'; + var dataInCreated = 'UNSET'; + var dataInDestroyed = 'UNSET'; + var dataInEvent = 'UNSET'; + + tmpl.foo = function () { + dataInHelper = this; + }; + tmpl.created = function () { + dataInCreated = this.data; + }; + tmpl.rendered = function () { + dataInRendered = this.data; + }; + tmpl.destroyed = function () { + dataInDestroyed = this.data; + }; + tmpl.events({ + click: function () { + dataInEvent = this; + }, + }); + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + clickElement(div.querySelector('button')); + Tracker.flush(); // rendered gets called afterFlush + $(div).remove(); + + test.isFalse(dataInHelper === window); + test.equal(dataInHelper, {}); + test.equal(dataInCreated, null); + test.equal(dataInRendered, null); + test.equal(dataInDestroyed, null); + test.isFalse(dataInEvent === window); + test.equal(dataInEvent, {}); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - falsy with', + function (test) { + var tmpl = Template.old_spacebars_test_falsy_with; + var R = ReactiveVar(null); + tmpl.obj = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl); + divRendersTo(test, div, ''); + + R.set({ greekLetter: 'alpha' }); + divRendersTo(test, div, 'alpha'); + + R.set(null); + divRendersTo(test, div, ''); + + R.set({ greekLetter: 'alpha' }); + divRendersTo(test, div, 'alpha'); + } +); + +Tinytest.add( + "spacebars-tests - old - template_tests - helpers don't leak", + function (test) { + var tmpl = Template.old_spacebars_test_helpers_dont_leak; + tmpl.foo = 'wrong'; + tmpl.bar = function () { + return 'WRONG'; + }; + + // Also test that custom block helpers (implemented as templates) do NOT + // interfere with helper lookup in the current template + Template.old_spacebars_test_helpers_dont_leak2.bonus = function () { + return 'BONUS'; + }; + + var div = renderToDiv(tmpl); + divRendersTo(test, div, 'correct BONUS'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - event handler returns false', + function (test) { + var tmpl = Template.old_spacebars_test_event_returns_false; + var elemId = 'spacebars_test_event_returns_false_link'; + tmpl.events({ + 'click a': function (evt) { + return false; + }, + }); + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + clickIt(document.getElementById(elemId)); + // NOTE: This failure can stick across test runs! Try + // removing '#bad-url' from the location bar and run + // the tests again. :) + test.isFalse(/#bad-url/.test(window.location.hash)); + document.body.removeChild(div); + } +); + +// Make sure that if you bind an event on "div p", for example, +// both the div and the p need to be in the template. jQuery's +// `$(elem).find(...)` works this way, but the browser's +// querySelector doesn't. +Tinytest.add( + 'spacebars-tests - old - template_tests - event map selector scope', + function (test) { + var tmpl = Template.old_spacebars_test_event_selectors1; + var tmpl2 = Template.old_spacebars_test_event_selectors2; + var buf = []; + tmpl2.events({ + 'click div p': function (evt) { + buf.push(evt.currentTarget.className); + }, + }); + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + test.equal(buf.join(), ''); + clickIt(div.querySelector('.p1')); + test.equal(buf.join(), ''); + clickIt(div.querySelector('.p2')); + test.equal(buf.join(), 'p2'); + document.body.removeChild(div); + } +); + +if (document.addEventListener) { + // see note about non-bubbling events in the "capuring events" + // templating test for why we use the VIDEO tag. (It would be + // nice to get rid of the network dependency, though.) + // We skip this test in IE 8. + Tinytest.add( + 'spacebars-tests - old - template_tests - event map selector scope (capturing)', + function (test) { + var tmpl = Template.old_spacebars_test_event_selectors_capturing1; + var tmpl2 = Template.old_spacebars_test_event_selectors_capturing2; + var buf = []; + tmpl2.events({ + 'play div video': function (evt) { + buf.push(evt.currentTarget.className); + }, + }); + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + test.equal(buf.join(), ''); + simulateEvent( + div.querySelector('.video1'), + 'play', + {}, + { bubbles: false } + ); + test.equal(buf.join(), ''); + simulateEvent( + div.querySelector('.video2'), + 'play', + {}, + { bubbles: false } + ); + test.equal(buf.join(), 'video2'); + document.body.removeChild(div); + } + ); +} + +Tinytest.add( + 'spacebars-tests - old - template_tests - tables', + function (test) { + var tmpl1 = Template.old_spacebars_test_tables1; + + var div = renderToDiv(tmpl1); + test.equal(Array.from(div.querySelectorAll('*')).map(x => x.tagName), [ + 'TABLE', + 'TR', + 'TD', + ]); + divRendersTo(test, div, '
Foo
'); + + var tmpl2 = Template.old_spacebars_test_tables2; + tmpl2.foo = 'Foo'; + div = renderToDiv(tmpl2); + test.equal(Array.from(div.querySelectorAll('*')).map(x => x.tagName), [ + 'TABLE', + 'TR', + 'TD', + ]); + divRendersTo(test, div, '
Foo
'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - jQuery.trigger extraParameters are passed to the event callback', + function (test) { + var tmpl = Template.old_spacebars_test_jquery_events; + var captured = false; + var args = ['param1', 'param2', { option: 1 }, 1, 2, 3]; + + tmpl.events({ + someCustomEvent: function (event, template) { + var i; + for (i = 0; i < args.length; i++) { + // expect the arguments to be just after template + test.equal(arguments[i + 2], args[i]); + } + captured = true; + }, + }); + + tmpl.rendered = function () { + $(this.find('button')).trigger('someCustomEvent', args); + }; + + renderToDiv(tmpl); + Tracker.flush(); + test.equal(captured, true); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - toHTML', + function (test) { + // run once, verifying that autoruns are stopped + var once = function (tmplToRender, tmplForHelper, helper, val) { + var count = 0; + var R = new ReactiveVar(); + var getR = function () { + count++; + return R.get(); + }; + + R.set(val); + tmplForHelper[helper] = getR; + test.equal(canonicalizeHtml(Blaze.toHTML(tmplToRender)), 'bar'); + test.equal(count, 1); + R.set(''); + Tracker.flush(); + test.equal(count, 1); // all autoruns stopped + }; + + once( + Template.old_spacebars_test_tohtml_basic, + Template.old_spacebars_test_tohtml_basic, + 'foo', + 'bar' + ); + once( + Template.old_spacebars_test_tohtml_if, + Template.old_spacebars_test_tohtml_if, + 'foo', + 'bar' + ); + once( + Template.old_spacebars_test_tohtml_with, + Template.old_spacebars_test_tohtml_with, + 'foo', + 'bar' + ); + once( + Template.old_spacebars_test_tohtml_each, + Template.old_spacebars_test_tohtml_each, + 'foos', + ['bar'] + ); + + once( + Template.old_spacebars_test_tohtml_include_with, + Template.old_spacebars_test_tohtml_with, + 'foo', + 'bar' + ); + once( + Template.old_spacebars_test_tohtml_include_each, + Template.old_spacebars_test_tohtml_each, + 'foos', + ['bar'] + ); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - block comments should not be displayed', + function (test) { + var tmpl = Template.old_spacebars_test_block_comment; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), ''); + } +); + +// Originally reported at https://github.com/meteor/meteor/issues/2046 +Tinytest.add( + 'spacebars-tests - old - template_tests - {{#with}} with mutated data context', + function (test) { + var tmpl = Template.old_spacebars_test_with_mutated_data_context; + var foo = { value: 0 }; + var dep = new Tracker.Dependency(); + tmpl.foo = function () { + dep.depend(); + return foo; + }; + + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), '0'); + + foo.value = 1; + dep.changed(); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), '1'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - event handlers get cleaned up when template is removed', + function (test) { + var tmpl = Template.old_spacebars_test_event_handler_cleanup; + var subtmpl = Template.old_spacebars_test_event_handler_cleanup_sub; + + var rv = new ReactiveVar(true); + tmpl.foo = function () { + return rv.get(); + }; + + subtmpl.events({ + 'click/mouseover': function () {}, + }); + + var div = renderToDiv(tmpl); + + test.equal(div.$blaze_events['click'].handlers.length, 1); + test.equal(div.$blaze_events['mouseover'].handlers.length, 1); + + rv.set(false); + Tracker.flush(); + + test.equal(div.$blaze_events['click'].handlers.length, 0); + test.equal(div.$blaze_events['mouseover'].handlers.length, 0); + } +); + +// This test makes sure that Blaze correctly finds the controller +// heirarchy surrounding an element that itself doesn't have a +// controller. +Tinytest.add( + 'spacebars-tests - old - template_tests - data context in event handlers on elements inside {{#if}}', + function (test) { + var tmpl = Template.old_spacebars_test_data_context_for_event_handler_in_if; + var data = null; + tmpl.events({ + 'click span': function () { + data = this; + }, + }); + var div = renderToDiv(tmpl); + document.body.appendChild(div); + clickIt(div.querySelector('span')); + test.equal(data, { foo: 'bar' }); + document.body.removeChild(div); + } +); + +// https://github.com/meteor/meteor/issues/2156 +Tinytest.add( + 'spacebars-tests - old - template_tests - each with inserts inside autorun', + function (test) { + var tmpl = Template.old_spacebars_test_each_with_autorun_insert; + var coll = new Mongo.Collection(null); + var rv = new ReactiveVar(); + + tmpl.items = function () { + return coll.find(); + }; + + var div = renderToDiv(tmpl); + + Tracker.autorun(function () { + if (rv.get()) { + coll.insert({ name: rv.get() }); + } + }); + + rv.set('foo1'); + Tracker.flush(); + var firstId = coll.findOne()._id; + + rv.set('foo2'); + Tracker.flush(); + + test.equal(canonicalizeHtml(div.innerHTML), 'foo1 foo2'); + + coll.update(firstId, { $set: { name: 'foo3' } }); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'foo3 foo2'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - ui hooks', + function (test) { + var tmpl = Template.old_spacebars_test_ui_hooks; + var rv = new ReactiveVar([]); + tmpl.items = function () { + return rv.get(); + }; + + var div = renderToDiv(tmpl); + + var hooks = []; + var container = div.querySelector('.test-ui-hooks'); + + // Before we attach the ui hooks, put two items in the DOM. + var origVal = [{ _id: 'foo1' }, { _id: 'foo2' }]; + rv.set(origVal); + Tracker.flush(); + + container._uihooks = { + insertElement: function (n, next) { + hooks.push('insert'); + + // check that the element hasn't actually been added yet + test.isTrue( + !n.parentNode || + n.parentNode.nodeType === 11 /*DOCUMENT_FRAGMENT_NODE*/ + ); + }, + removeElement: function (n) { + hooks.push('remove'); + // check that the element hasn't actually been removed yet + test.isTrue(n.parentNode === container); + }, + moveElement: function (n, next) { + hooks.push('move'); + // check that the element hasn't actually been moved yet + test.isFalse(n.nextNode === next); + }, + }; + + var testDomUnchanged = function () { + var items = div.querySelectorAll('.item'); + test.equal(items.length, 2); + test.equal(canonicalizeHtml(items[0].innerHTML), 'foo1'); + test.equal(canonicalizeHtml(items[1].innerHTML), 'foo2'); + }; + + var newVal = [...origVal]; + newVal.push({ _id: 'foo3' }); + rv.set(newVal); + Tracker.flush(); + test.equal(hooks, ['insert']); + testDomUnchanged(); + + newVal.reverse(); + rv.set(newVal); + Tracker.flush(); + test.equal(hooks, ['insert', 'move']); + testDomUnchanged(); + + newVal = [origVal[0]]; + rv.set(newVal); + Tracker.flush(); + test.equal(hooks, ['insert', 'move', 'remove']); + testDomUnchanged(); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - ui hooks - nested domranges', + function (test) { + var tmpl = Template.old_spacebars_test_ui_hooks_nested; + var rv = new ReactiveVar(true); + + tmpl.foo = function () { + return rv.get(); + }; + + var subtmpl = Template.old_spacebars_test_ui_hooks_nested_sub; + var uiHookCalled = false; + subtmpl.rendered = function () { + this.firstNode.parentNode._uihooks = { + removeElement: function (node) { + uiHookCalled = true; + }, + }; + }; + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + Tracker.flush(); + + var htmlBeforeRemove = canonicalizeHtml(div.innerHTML); + rv.set(false); + Tracker.flush(); + test.isTrue(uiHookCalled); + var htmlAfterRemove = canonicalizeHtml(div.innerHTML); + test.equal(htmlBeforeRemove, htmlAfterRemove); + document.body.removeChild(div); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - Template.instance from helper', + function (test) { + // Set a property on the template instance; check that it's still + // there from a helper. + + var tmpl = Template.old_spacebars_test_template_instance_helper; + var value = Random.id(); + var instanceFromHelper; + + tmpl.created = function () { + this.value = value; + }; + tmpl.foo = function () { + instanceFromHelper = Template.instance(); + }; + + var div = renderToDiv(tmpl); + test.equal(instanceFromHelper.value, value); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - Template.instance from helper, ' + + 'template instance is kept up-to-date', + function (test) { + var tmpl = Template.old_spacebars_test_template_instance_helper; + var rv = new ReactiveVar(''); + var instanceFromHelper; + + tmpl.foo = function () { + return Template.instance().data; + }; + + var div = renderToDiv(tmpl, function () { + return rv.get(); + }); + rv.set('first'); + divRendersTo(test, div, 'first'); + + rv.set('second'); + Tracker.flush(); + divRendersTo(test, div, 'second'); + + // Template.instance() returns null when no template instance + test.isTrue(Template.instance() === null); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - {{#with}} autorun is cleaned up', + function (test) { + var tmpl = Template.old_spacebars_test_with_cleanup; + var rv = new ReactiveVar(''); + var helperCalled = false; + tmpl.foo = function () { + helperCalled = true; + return rv.get(); + }; + + var div = renderToDiv(tmpl); + rv.set('first'); + Tracker.flush(); + test.equal(helperCalled, true); + + helperCalled = false; + $(div).find('.test-with-cleanup').remove(); + + rv.set('second'); + Tracker.flush(); + test.equal(helperCalled, false); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - UI.parentData from helpers', + function (test) { + var childTmpl = + Template.old_spacebars_test_template_parent_data_helper_child; + var parentTmpl = Template.old_spacebars_test_template_parent_data_helper; + + var height = new ReactiveVar(0); + var bar = new ReactiveVar('bar'); + + childTmpl.a = ['a']; + childTmpl.b = function () { + return bar.get(); + }; + childTmpl.c = ['c']; + + childTmpl.foo = function () { + var a = Template.parentData(height.get()); + var b = UI._parentData(height.get()); // back-compat + test.equal(a, b); + return a; + }; + + var div = renderToDiv(parentTmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'd'); + + height.set(1); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'bar'); + + // Test UI.parentData() reactivity + + bar.set('baz'); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'baz'); + + height.set(2); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'a'); + + height.set(3); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'parent'); + } +); + +Tinytest.add('spacebars - old - SVG elements', function (test) { + if (!document.createElementNS) { + // IE 8 + return; + } + + var tmpl = Template.old_spacebars_test_svg_anchor; + var div = renderToDiv(tmpl); + + var anchNamespace = $(div).find('a').get(0).namespaceURI; + test.equal(anchNamespace, 'http://www.w3.org/2000/svg'); +}); + +Tinytest.add( + 'spacebars-tests - old - template_tests - created/rendered/destroyed by each', + function (test) { + var outerTmpl = + Template.old_spacebars_test_template_created_rendered_destroyed_each; + var innerTmpl = + Template.old_spacebars_test_template_created_rendered_destroyed_each_sub; + + var buf = ''; + + innerTmpl.created = function () { + buf += 'C' + String(this.data).toLowerCase(); + }; + innerTmpl.rendered = function () { + buf += 'R' + String(this.data).toLowerCase(); + }; + innerTmpl.destroyed = function () { + buf += 'D' + String(this.data).toLowerCase(); + }; + + var R = ReactiveVar([{ _id: 'A' }]); + + outerTmpl.items = function () { + return R.get(); + }; + + var div = renderToDiv(outerTmpl); + divRendersTo(test, div, '

'); + test.equal(buf, 'CaRa'); + + R.set([{ _id: 'B' }]); + divRendersTo(test, div, '
B
'); + test.equal(buf, 'CaRaDaCbRb'); + + R.set([{ _id: 'C' }]); + divRendersTo(test, div, '
C
'); + test.equal(buf, 'CaRaDaCbRbDbCcRc'); + + $(div).remove(); + test.equal(buf, 'CaRaDaCbRbDbCcRcDc'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - UI.render/UI.remove', + function (test) { + var div = document.createElement('DIV'); + document.body.appendChild(div); + + var created = false, + rendered = false, + destroyed = false; + var R = ReactiveVar('aaa'); + + var tmpl = Template.old_spacebars_test_ui_render; + tmpl.greeting = function () { + return this.greeting || 'Hello'; + }; + tmpl.r = function () { + return R.get(); + }; + tmpl.created = function () { + created = true; + }; + tmpl.rendered = function () { + rendered = true; + }; + tmpl.destroyed = function () { + destroyed = true; + }; + + test.equal([created, rendered, destroyed], [false, false, false]); + + var renderedTmpl = UI.render(tmpl, div); + test.equal([created, rendered, destroyed], [true, false, false]); + + // Flush now. We fire the rendered callback in an afterFlush block, + // to ensure that the DOM is completely updated. + Tracker.flush(); + test.equal([created, rendered, destroyed], [true, true, false]); + + var otherDiv = document.createElement('DIV'); + // can run a second time without throwing + var x = UI.render(tmpl, otherDiv); + // note: we'll have clean up `x` below + + var renderedTmpl2 = UI.renderWithData(tmpl, { greeting: 'Bye' }, div); + test.equal( + canonicalizeHtml(div.innerHTML), + 'Hello aaaBye aaa' + ); + R.set('bbb'); + Tracker.flush(); + test.equal( + canonicalizeHtml(div.innerHTML), + 'Hello bbbBye bbb' + ); + test.equal([created, rendered, destroyed], [true, true, false]); + test.equal(R._numListeners(), 3); + UI.remove(renderedTmpl); + UI.remove(renderedTmpl); // test that double-remove doesn't throw + UI.remove(renderedTmpl2); + UI.remove(x); + test.equal([created, rendered, destroyed], [true, true, true]); + test.equal(R._numListeners(), 0); + test.equal(canonicalizeHtml(div.innerHTML), ''); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - UI.render fails on jQuery objects', + function (test) { + var tmpl = Template.old_spacebars_test_ui_render; + test.throws(function () { + UI.render(tmpl, $('body')); + }, /'parentElement' must be a DOM node/); + test.throws(function () { + UI.render(tmpl, document.body, $('body')); + }, /'nextNode' must be a DOM node/); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - UI.getElementData', + function (test) { + var div = document.createElement('DIV'); + var tmpl = Template.old_spacebars_test_ui_getElementData; + UI.renderWithData(tmpl, { foo: 'bar' }, div); + + var span = div.querySelector('SPAN'); + test.isTrue(span); + test.equal(UI.getElementData(span), { foo: 'bar' }); + test.equal(Blaze.getData(span), { foo: 'bar' }); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - autorun cleanup', + function (test) { + var tmpl = Template.old_spacebars_test_parent_removal; + + var Acalls = ''; + var A = ReactiveVar('hi'); + tmpl.A = function (chr) { + Acalls += chr; + return A.get(); + }; + var Bcalls = 0; + var B = ReactiveVar(['one', 'two']); + tmpl.B = function () { + Bcalls++; + return B.get(); + }; + + // Assert how many times A and B were accessed (since last time) + // and how many autoruns are listening to them. + var assertCallsAndListeners = function ( + a_calls, + b_calls, + a_listeners, + b_listeners + ) { + test.equal('A calls: ' + Acalls.length, 'A calls: ' + a_calls, Acalls); + test.equal('B calls: ' + Bcalls, 'B calls: ' + b_calls); + test.equal( + 'A listeners: ' + A._numListeners(), + 'A listeners: ' + a_listeners + ); + test.equal( + 'B listeners: ' + B._numListeners(), + 'B listeners: ' + b_listeners + ); + Acalls = ''; + Bcalls = 0; + }; + + var div = renderToDiv(tmpl); + assertCallsAndListeners(10, 1, 10, 1); + A.set(''); + Tracker.flush(); + // Confirm that #4, #5, #6, and #9 are not re-run. + // #a is newly run, for a total of 10 - 4 + 1 = 7, + assertCallsAndListeners(7, 0, 7, 1); + A.set('hi'); + Tracker.flush(); + assertCallsAndListeners(10, 0, 10, 1); + + // Now see that removing the DOM with jQuery, below + // the level of the entire template, stops everything. + $(div.querySelector('.toremove')).remove(); + assertCallsAndListeners(0, 0, 0, 0); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - focus/blur with clean-up', + function (test) { + var tmpl = Template.old_spacebars_test_focus_blur_outer; + var cond = ReactiveVar(true); + tmpl.cond = function () { + return cond.get(); + }; + var buf = []; + Template.old_spacebars_test_focus_blur_inner.events({ + 'focus input': function () { + buf.push('FOCUS'); + }, + 'blur input': function () { + buf.push('BLUR'); + }, + }); + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + + // check basic focus and blur to make sure + // everything is sane + test.equal(div.querySelectorAll('input').length, 1); + var input; + focusElement((input = div.querySelector('input'))); + // We don't get focus events when the Chrome Dev Tools are focused, + // unfortunately, as of Chrome 35. I think this is a regression in + // Chrome 34. So, the goal is to work whether or not focus is + // "borken," where "working" means always failing if DOMBackend isn't + // correctly unbinding the old event handlers when we switch the IF, + // and always passing if it is. To cause the problem in DOMBackend, + // delete the '**' argument to jQuery#off in + // DOMBackend.Events.undelegateEvents. The only compromise we are + // making here is that if some unrelated bug in Blaze makes + // focus/blur not work, the failure might be masked while the Dev + // Tools are open. + var borken = false; + if (buf.length === 0 && document.activeElement === input) { + test.ok({ + note: + 'You might need to defocus the Chrome Dev Tools to get a more accurate run of this test!', + }); + borken = true; + $(input).trigger('focus'); + } + test.equal(buf.join(), 'FOCUS'); + blurElement(div.querySelector('input')); + if (buf.length === 1) $(input).trigger('blur'); + test.equal(buf.join(), 'FOCUS,BLUR'); + + // now switch the IF and check again. The failure mode + // we observed was that DOMBackend would not correctly + // unbind the old event listener at the jQuery level, + // so the old event listener would fire and cause an + // exception inside Blaze ("Must be attached" in + // DOMRange#containsElement), which would show up in + // the console and cause our handler not to fire. + cond.set(false); + buf.length = 0; + Tracker.flush(); + test.equal(div.querySelectorAll('input').length, 1); + focusElement((input = div.querySelector('input'))); + if (borken) $(input).trigger('focus'); + test.equal(buf.join(), 'FOCUS'); + blurElement(div.querySelector('input')); + if (!borken) test.equal(buf.join(), 'FOCUS,BLUR'); + + document.body.removeChild(div); + } +); + +// We used to remove event handlers on DOMRange detached, but when +// tearing down a view, we don't "detach" all the DOMRanges recursively. +// Mainly, we destroy the View. Destroying a View should remove its +// event listeners. (In practice, however, it's hard to think of +// consequences to not removing event handlers on removed DOM nodes, +// which will probably be GCed anyway.) +Tinytest.add( + 'spacebars-tests - old - template_tests - event cleanup on destroyed', + function (test) { + var tmpl = Template.old_spacebars_test_event_cleanup_on_destroyed_outer; + var cond = ReactiveVar(true); + tmpl.cond = function () { + return cond.get(); + }; + + Template.old_spacebars_test_event_cleanup_on_destroyed_inner.events({ + 'click span': function () {}, + }); + + var div = renderToDiv(tmpl); + document.body.appendChild(div); + + var eventDiv = div.querySelector('div'); + test.equal(eventDiv.$blaze_events.click.handlers.length, 1); + + cond.set(false); + Tracker.flush(); + test.equal(eventDiv.$blaze_events.click.handlers.length, 0); + + document.body.removeChild(div); + } +); + +[1, 2, 3].forEach(function (n) { + Tinytest.add( + 'spacebars-tests - old - template_tests - lookup is isolated ' + n, + function (test) { + var buf = ''; + var inclusion = Template.old_spacebars_test_isolated_lookup_inclusion; + inclusion.created = function () { + buf += 'C'; + }; + inclusion.destroyed = function () { + buf += 'D'; + }; + + var tmpl = Template['old_spacebars_test_isolated_lookup' + n]; + var R = ReactiveVar(Template.old_spacebars_template_test_aaa); + + tmpl.bar = function () { + return R.get(); + }; + + var div = renderToDiv(tmpl, function () { + return { foo: R.get() }; + }); + + test.equal(canonicalizeHtml(div.innerHTML), 'aaa--x'); + test.equal(buf, 'C'); + R.set(Template.old_spacebars_template_test_bbb); + Tracker.flush(); + test.equal(canonicalizeHtml(div.innerHTML), 'bbb--x'); + test.equal(buf, 'C'); + } + ); +}); + +Tinytest.add( + 'spacebars-tests - old - template_tests - current view in event handler', + function (test) { + var tmpl = Template.old_spacebars_test_current_view_in_event; + + var currentView; + var currentData; + + tmpl.events({ + 'click span': function () { + currentView = Blaze.getView(); + currentData = Blaze.getData(); + }, + }); + + var div = renderToDiv(tmpl, 'blah'); + test.equal(canonicalizeHtml(div.innerHTML), 'blah'); + document.body.appendChild(div); + clickElement(div.querySelector('span')); + $(div).remove(); + + test.isTrue(currentView); + test.equal(currentData, 'blah'); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - textarea attrs', + function (test) { + var tmplNoContents = { + tmpl: Template.old_spacebars_test_textarea_attrs, + hasTextAreaContents: false, + }; + var tmplWithContents = { + tmpl: Template.old_spacebars_test_textarea_attrs_contents, + hasTextAreaContents: true, + }; + var tmplWithContentsAndMoreAttrs = { + tmpl: Template.old_spacebars_test_textarea_attrs_array_contents, + hasTextAreaContents: true, + }; + + [tmplNoContents, tmplWithContents, tmplWithContentsAndMoreAttrs].forEach( + function (tmplInfo) { + var id = new ReactiveVar('textarea-' + Random.id()); + var name = new ReactiveVar('one'); + var attrs = new ReactiveVar({ + id: 'textarea-' + Random.id(), + }); + + var div = renderToDiv(tmplInfo.tmpl, { + attrs: function () { + return attrs.get(); + }, + name: function () { + return name.get(); + }, + }); + + // Check that the id and value attribute are as we expect. + // We can't check div.innerHTML because Chrome at least doesn't + // appear to put textarea value attributes in innerHTML. + var textarea = div.querySelector('textarea'); + test.equal(textarea.id, attrs.get().id); + test.equal( + textarea.value, + tmplInfo.hasTextAreaContents ? 'Hello one' : '' + ); + // One of the templates has a separate attribute in addition to + // an attributes dictionary. + if (tmplInfo === tmplWithContentsAndMoreAttrs) { + test.equal($(textarea).attr('class'), 'bar'); + } + + // Change the id, check that the attribute updates reactively. + attrs.set({ id: 'textarea-' + Random.id() }); + Tracker.flush(); + test.equal(textarea.id, attrs.get().id); + + // Change the name variable, check that the textarea value + // updates reactively. + name.set('two'); + Tracker.flush(); + test.equal( + textarea.value, + tmplInfo.hasTextAreaContents ? 'Hello two' : '' + ); + + if (tmplInfo === tmplWithContentsAndMoreAttrs) { + test.equal($(textarea).attr('class'), 'bar'); + } + } + ); + } +); + +Tinytest.add( + 'spacebars-tests - old - template_tests - this.autorun', + function (test) { + var tmpl = Template.old_spacebars_test_autorun; + var tmplInner = Template.old_spacebars_test_autorun_inner; + + // Keep track of the value of `Template.instance()` inside the + // autorun each time it runs. + var autorunTemplateInstances = []; + var actualTemplateInstance; + var returnedComputation; + var computationArg; + + var show = new ReactiveVar(true); + var rv = new ReactiveVar('foo'); + + tmplInner.created = function () { + actualTemplateInstance = this; + returnedComputation = this.autorun(function (c) { + computationArg = c; + rv.get(); + autorunTemplateInstances.push(Template.instance()); + }); + }; + + tmpl.helpers({ + show: function () { + return show.get(); + }, + }); + + var div = renderToDiv(tmpl); + test.equal(autorunTemplateInstances.length, 1); + test.equal(autorunTemplateInstances[0], actualTemplateInstance); + + // Test that the autorun returned a computation and received a + // computation as an argument. + test.isTrue(returnedComputation instanceof Tracker.Computation); + test.equal(returnedComputation, computationArg); + + // Make sure the autorun re-runs when `rv` changes, and that it has + // the correct current view. + rv.set('bar'); + Tracker.flush(); + test.equal(autorunTemplateInstances.length, 2); + test.equal(autorunTemplateInstances[1], actualTemplateInstance); + + // If the inner template is destroyed, the autorun should be stopped. + show.set(false); + Tracker.flush(); + rv.set('baz'); + Tracker.flush(); + + test.equal(autorunTemplateInstances.length, 2); + test.equal(rv._numListeners(), 0); + } +); + +// Test that argument in {{> UI.contentBlock arg}} is evaluated in +// the proper data context. +Tinytest.add( + 'spacebars-tests - old - template_tests - contentBlock argument', + function (test) { + var tmpl = Template.old_spacebars_test_contentBlock_arg; + var div = renderToDiv(tmpl); + test.equal(canonicalizeHtml(div.innerHTML), 'AAA BBB'); + } +); + +// Test that when Blaze sets an input field to the same value, +// we don't lose the insertion point position. +Tinytest.add( + 'spacebars-tests - old - template_tests - input field to same value', + function (test) { + var tmpl = Template.old_spacebars_template_test_input_field_to_same_value; + var R = ReactiveVar('BLAH'); + tmpl.foo = function () { + return R.get(); + }; + var div = renderToDiv(tmpl); + + document.body.appendChild(div); + + var input = div.querySelector('input'); + test.equal(input.value, 'BLAH'); + + var setSelection = function (startEnd) { + startEnd = startEnd.split(' '); + if (typeof input.selectionStart === 'number') { + // all but IE < 9 + input.selectionStart = startEnd[0]; + input.selectionEnd = startEnd[1]; + } else { + // IE 8 + input.focus(); + var r = input.createTextRange(); + // move the start and end of the range to the beginning + // of the input field + r.moveStart('textedit', -1); + r.moveEnd('textedit', -1); + // move the start and end a certain number of characters + // (relative to their current position) + r.moveEnd('character', startEnd[1]); + r.moveStart('character', startEnd[0]); + r.select(); + } + }; + var getSelection = function () { + if (typeof input.selectionStart === 'number') { + // all but IE < 9 + return input.selectionStart + ' ' + input.selectionEnd; + } else { + // IE 8 + input.focus(); + var r = document.selection.createRange(); + var fullText = input.value; + var start, end; + if (r.text) { + // one or more characters are selected. + // this is kind of hacky! Relies on fullText + // not having duplicate letters, for example. + start = fullText.indexOf(r.text); + end = start + r.text.length; + } else { + r.moveStart('textedit', -1); + start = end = r.text.length; + } + return start + ' ' + end; + } + }; + + setSelection('2 3'); + test.equal(getSelection(), '2 3'); + // At this point, we COULD confirm that setting input.value to + // the same thing as before ("BLAH") loses the insertion + // point (per browser behavior). However, it doesn't on Firefox. + // So we set it to something different, which verifies that our + // test machinery is correct. + input.value = 'BLAN'; + // test that insertion point is lost + var selectionAfterSet = getSelection(); + if (selectionAfterSet !== '0 0') + // IE 8 + test.equal(getSelection(), '4 4'); + + // now make the input say "BLAH" but the AttributeHandler + // says "OTHER" (so we can make it do the no-op update) + R.set('OTHER'); + Tracker.flush(); + test.equal(input.value, 'OTHER'); + input.value = 'BLAH'; + setSelection('2 2'); + + R.set('BLAH'); + Tracker.flush(); + test.equal(input.value, 'BLAH'); + // test that didn't lose insertion point! + test.equal(getSelection(), '2 2'); + + // clean up after ourselves + document.body.removeChild(div); + } +); diff --git a/packages/spacebars-tests/package.js b/packages/spacebars-tests/package.js index dcc068c26..d9a52c1fa 100644 --- a/packages/spacebars-tests/package.js +++ b/packages/spacebars-tests/package.js @@ -33,6 +33,9 @@ Package.onTest(function (api) { 'template_tests.js', 'templating_tests.html', 'templating_tests.js', + + 'old_templates.js', // backcompat for packages built with old Blaze APIs. + 'old_templates_tests.js' ], 'client'); api.addFiles('template_tests_server.js', 'server'); From 0832a3f6d3516d2a813d2e9166a64a095c3f3381 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 15 Apr 2022 08:14:11 +0200 Subject: [PATCH 04/16] Return Template.__define__ --- packages/templating-runtime/package.js | 4 ++-- packages/templating-runtime/templating.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/templating-runtime/package.js b/packages/templating-runtime/package.js index e5da34431..a4b177b66 100644 --- a/packages/templating-runtime/package.js +++ b/packages/templating-runtime/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'templating-runtime', summary: "Runtime for compiled .html files", - version: '1.6.0', + version: '1.6.1', git: 'https://github.com/meteor/blaze.git', documentation: null }); @@ -28,7 +28,7 @@ Package.onUse(function (api) { 'ecmascript@0.15.1' ]); api.imply([ - 'meteor@1.2.17', // TODO update + 'meteor@1.10.0', 'blaze@2.6.0', 'spacebars@1.2.1' ], 'client'); diff --git a/packages/templating-runtime/templating.js b/packages/templating-runtime/templating.js index 223226310..a775607d8 100644 --- a/packages/templating-runtime/templating.js +++ b/packages/templating-runtime/templating.js @@ -26,6 +26,27 @@ Template.__checkName = function (name) { } }; +var shownWarning = false; + +// XXX COMPAT WITH 0.8.3 +Template.__define__ = function (name, renderFunc) { + Template.__checkName(name); + Template[name] = new Template("Template." + name, renderFunc); + // Exempt packages built pre-0.9.0 from warnings about using old + // helper syntax, because we can. It's not very useful to get a + // warning about someone else's code (like a package on Atmosphere), + // and this should at least put a bit of a dent in number of warnings + // that come from packages that haven't been updated lately. + Template[name]._NOWARN_OLDSTYLE_HELPERS = true; + + // Now we want to show at least one warning so that people get serious about + // updating away from this method. + if (!shownWarning) { + shownWarning = true; + console.warn("You app is using old Template definition that is scheduled to be removed with Blaze 3.0, please check your app and packages for use of: Template.__define__"); + } +}; + // Define a template `Template.body` that renders its // `contentRenderFuncs`. `` tags (of which there may be // multiple) will have their contents added to it. From dc2cad08faba54ceed22752a07d05d1285111245 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 15 Apr 2022 08:16:11 +0200 Subject: [PATCH 05/16] Add history entry --- HISTORY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 4f44cf6da..176bfa04d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +## v2.6.1, 2022-April-XX + +* [#370](https://github.com/meteor/blaze/pull/370) `templating-runtime@1.6.1`, returned the `Template.__define__` with warning message + ## v2.6.0, 2022-April-13 * [#330](https://github.com/meteor/blaze/pull/330) Removed deprecated APIs from before Meteor 1.0 From 2b091187773f2edd071916dba869283ac88bfb9b Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 15 Apr 2022 15:57:07 +0200 Subject: [PATCH 06/16] Replace removed API with new version --- packages/blaze/builtins.js | 2 +- packages/spacebars-tests/old_templates.js | 46 +++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/blaze/builtins.js b/packages/blaze/builtins.js index 0735d3cb2..044e68a45 100644 --- a/packages/blaze/builtins.js +++ b/packages/blaze/builtins.js @@ -295,7 +295,7 @@ Blaze._TemplateWith = function (arg, contentFunc) { // parent Views in the current template. However, when there's an argument // (`{{> Template.contentBlock arg}}`), the argument needs to be evaluated // in the original scope. There's no good order to nest - // Blaze._InOuterTemplateScope and Spacebars.TemplateWith to achieve this, + // Blaze._InOuterTemplateScope and Blaze._TemplateWith to achieve this, // so we wrap argFunc to run it in the "original parentView" of the // Blaze._InOuterTemplateScope. // diff --git a/packages/spacebars-tests/old_templates.js b/packages/spacebars-tests/old_templates.js index e92edcb87..5cb450770 100644 --- a/packages/spacebars-tests/old_templates.js +++ b/packages/spacebars-tests/old_templates.js @@ -38,7 +38,7 @@ Template.__define__("old_spacebars_template_test_span_this", (function() { Template.__define__("old_spacebars_template_test_content", (function() { var view = this; - return Blaze.InOuterTemplateScope(view, function() { + return Blaze._InOuterTemplateScope(view, function() { return Spacebars.include(function() { return Spacebars.call(view.templateContentBlock); }); @@ -47,7 +47,7 @@ Template.__define__("old_spacebars_template_test_content", (function() { Template.__define__("old_spacebars_template_test_elsecontent", (function() { var view = this; - return Blaze.InOuterTemplateScope(view, function() { + return Blaze._InOuterTemplateScope(view, function() { return Spacebars.include(function() { return Spacebars.call(view.templateElseBlock); }); @@ -59,13 +59,13 @@ Template.__define__("old_spacebars_template_test_iftemplate", (function() { return Blaze.If(function() { return Spacebars.call(view.lookup("condition")); }, function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return [ "\n ", Blaze._InOuterTemplateScope(view, function() { return Spacebars.include(function() { return Spacebars.call(view.templateContentBlock); }); }), "\n " ]; }, function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return [ "\n ", Blaze._InOuterTemplateScope(view, function() { return Spacebars.include(function() { return Spacebars.call(view.templateElseBlock); }); @@ -125,7 +125,7 @@ Template.__define__("old_spacebars_template_test_triple2", (function() { Template.__define__("old_spacebars_template_test_inclusion_args", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return Spacebars.call(view.lookup("bar")); }, function() { return Spacebars.include(view.lookupTemplate("foo")); @@ -134,7 +134,7 @@ Template.__define__("old_spacebars_template_test_inclusion_args", (function() { Template.__define__("old_spacebars_template_test_inclusion_args2", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return Spacebars.dataMustache(view.lookup("bar"), Spacebars.kw({ q: view.lookup("baz") })); @@ -145,7 +145,7 @@ Template.__define__("old_spacebars_template_test_inclusion_args2", (function() { Template.__define__("old_spacebars_template_test_inclusion_dotted_args", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return Spacebars.call(Spacebars.dot(view.lookup("bar"), "baz")); }, function() { return Spacebars.include(view.lookupTemplate("foo")); @@ -154,7 +154,7 @@ Template.__define__("old_spacebars_template_test_inclusion_dotted_args", (functi Template.__define__("old_spacebars_template_test_inclusion_slashed_args", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return Spacebars.call(Spacebars.dot(view.lookup("bar"), "baz")); }, function() { return Spacebars.include(view.lookupTemplate("foo")); @@ -172,7 +172,7 @@ Template.__define__("old_spacebars_template_test_block_helper", (function() { Template.__define__("old_spacebars_template_test_block_helper_function_one_string_arg", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return "bar"; }, function() { return Spacebars.include(view.lookupTemplate("foo"), function() { @@ -183,7 +183,7 @@ Template.__define__("old_spacebars_template_test_block_helper_function_one_strin Template.__define__("old_spacebars_template_test_block_helper_function_one_helper_arg", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return Spacebars.call(view.lookup("bar")); }, function() { return Spacebars.include(view.lookupTemplate("foo"), function() { @@ -212,7 +212,7 @@ Template.__define__("old_spacebars_template_test_block_helper_component_three_he Template.__define__("old_spacebars_template_test_block_helper_dotted_arg", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return Spacebars.dataMustache(Spacebars.dot(view.lookup("bar"), "baz"), view.lookup("qux")); }, function() { return Spacebars.include(view.lookupTemplate("foo"), function() { @@ -223,7 +223,7 @@ Template.__define__("old_spacebars_template_test_block_helper_dotted_arg", (func Template.__define__("old_spacebars_template_test_nested_content", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return { condition: Spacebars.call(view.lookup("flag")) }; @@ -238,19 +238,19 @@ Template.__define__("old_spacebars_template_test_nested_content", (function() { Template.__define__("old_spacebars_template_test_iftemplate2", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return { condition: Spacebars.call(view.lookup("flag")) }; }, function() { return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_iftemplate"), function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return [ "\n ", Blaze._InOuterTemplateScope(view, function() { return Spacebars.include(function() { return Spacebars.call(view.templateContentBlock); }); }), "\n " ]; }, function() { - return [ "\n ", Blaze.InOuterTemplateScope(view, function() { + return [ "\n ", Blaze._InOuterTemplateScope(view, function() { return Spacebars.include(function() { return Spacebars.call(view.templateElseBlock); }); @@ -261,7 +261,7 @@ Template.__define__("old_spacebars_template_test_iftemplate2", (function() { Template.__define__("old_spacebars_template_test_nested_content2", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return { flag: Spacebars.call(view.lookup("x")) }; @@ -333,7 +333,7 @@ Template.__define__("old_spacebars_template_test_dots", (function() { return [ "\n C\n ", Blaze.Each(function() { return Spacebars.call(view.lookup("items")); }, function() { - return [ "\n D\n \n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_dots_subtemplate")), "\n ", Spacebars.TemplateWith(function() { + return [ "\n D\n \n ", Spacebars.include(view.lookupTemplate("old_spacebars_template_test_dots_subtemplate")), "\n ", Blaze._TemplateWith(function() { return Spacebars.call(view.lookup("..")); }, function() { return Spacebars.include(view.lookupTemplate("old_spacebars_template_test_dots_subtemplate")); @@ -755,7 +755,7 @@ Template.__define__("old_spacebars_template_test_markdown_block_helpers", (funct Template.__define__("old_spacebars_template_test_just_content", (function() { var view = this; - return Blaze.InOuterTemplateScope(view, function() { + return Blaze._InOuterTemplateScope(view, function() { return Spacebars.include(function() { return Spacebars.call(view.templateContentBlock); }); @@ -882,7 +882,7 @@ Template.__define__("old_spacebars_template_test_content_context", (function() { return [ "\n ", Spacebars.With(function() { return Spacebars.call(view.lookup("bar")); }, function() { - return [ "\n ", Spacebars.TemplateWith(function() { + return [ "\n ", Blaze._TemplateWith(function() { return { condition: Spacebars.call(view.lookup("cond")) }; @@ -1184,7 +1184,7 @@ Template.__define__("old_spacebars_test_falsy_with", (function() { Template.__define__("old_spacebars_test_helpers_dont_leak", (function() { var view = this; - return Spacebars.TemplateWith(function() { + return Blaze._TemplateWith(function() { return { foo: Spacebars.call("correct") }; @@ -1480,7 +1480,7 @@ Template.__define__("old_spacebars_test_template_created_rendered_destroyed_each return Blaze.Each(function() { return Spacebars.call(view.lookup("items")); }, function() { - return [ "\n ", HTML.DIV(Spacebars.TemplateWith(function() { + return [ "\n ", HTML.DIV(Blaze._TemplateWith(function() { return Spacebars.call(view.lookup("_id")); }, function() { return Spacebars.include(view.lookupTemplate("old_spacebars_test_template_created_rendered_destroyed_each_sub")); @@ -1687,8 +1687,8 @@ Template.__define__("old_spacebars_test_contentBlock_arg_inner", (function() { }, function() { return [ "\n ", Blaze.View(function() { return Spacebars.mustache(Spacebars.dot(view.lookup("."), "foo")); - }), " ", Blaze.InOuterTemplateScope(view, function() { - return Spacebars.TemplateWith(function() { + }), " ", Blaze._InOuterTemplateScope(view, function() { + return Blaze._TemplateWith(function() { return Spacebars.call(view.lookup(".")); }, function() { return Spacebars.include(function() { From 070d42507365ce70ceaaddaa0d1db3e28244c20e Mon Sep 17 00:00:00 2001 From: denihs Date: Tue, 19 Apr 2022 16:00:03 -0400 Subject: [PATCH 07/16] - Updating history.md --- HISTORY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 4f44cf6da..5a6abf743 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +## v2.6.1, 2022-April-xx +* [#366](https://github.com/meteor/blaze/pull/366) Prevent firing callbacks until members are destroyed + * fix destroying child templates when parent is destroyed; prevents memory leak and DOMRange "not attached" error + ## v2.6.0, 2022-April-13 * [#330](https://github.com/meteor/blaze/pull/330) Removed deprecated APIs from before Meteor 1.0 From 48853c3b9594ae8bd48421c5b0b503d924518574 Mon Sep 17 00:00:00 2001 From: denihs Date: Tue, 19 Apr 2022 16:05:46 -0400 Subject: [PATCH 08/16] - bumping blaze version to 2.6.1-rc.0 --- packages/blaze/package.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/blaze/package.js b/packages/blaze/package.js index 60aa9a10f..9aee49ae9 100644 --- a/packages/blaze/package.js +++ b/packages/blaze/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'blaze', summary: "Meteor Reactive Templating library", - version: '2.6.0', + version: '2.6.1-rc.0', git: 'https://github.com/meteor/blaze.git' }); @@ -9,7 +9,7 @@ Npm.depends({ 'lodash.has': '4.5.2', 'lodash.isfunction': '3.0.9', 'lodash.isempty': '4.4.0', - 'lodash.isobject': '3.0.2' + 'lodash.isobject': '3.0.2' }); Package.onUse(function (api) { From 4ab041f5583ed676055b5c5da311fc04f81364ae Mon Sep 17 00:00:00 2001 From: denihs Date: Wed, 20 Apr 2022 09:35:19 -0400 Subject: [PATCH 09/16] - bumping blaze version to 2.6.1-rc.1 --- packages/blaze/.versions | 66 +++++++++++++------------- packages/blaze/package.js | 2 +- packages/spacebars-tests/package.js | 2 +- packages/templating-runtime/package.js | 6 +-- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/blaze/.versions b/packages/blaze/.versions index f4f59fd26..a8f572af3 100644 --- a/packages/blaze/.versions +++ b/packages/blaze/.versions @@ -1,64 +1,64 @@ -allow-deny@1.1.0 -babel-compiler@7.6.1 +allow-deny@1.1.1 +babel-compiler@7.9.0 babel-runtime@1.5.0 base64@1.0.12 binary-heap@1.0.11 -blaze@2.5.0 -blaze-tools@1.1.2 +blaze@2.6.1-rc.1 +blaze-tools@1.1.3 boilerplate-generator@1.7.1 caching-compiler@1.2.2 caching-html-compiler@1.1.2 -callback-hook@1.3.0 +callback-hook@1.4.0 check@1.3.1 ddp@1.4.0 -ddp-client@2.4.0 +ddp-client@2.5.0 ddp-common@1.4.0 -ddp-server@2.3.2 +ddp-server@2.5.0 diff-sequence@1.1.1 -dynamic-import@0.6.0 -ecmascript@0.15.1 -ecmascript-runtime@0.7.0 -ecmascript-runtime-client@0.11.0 -ecmascript-runtime-server@0.10.0 -ejson@1.1.1 +dynamic-import@0.7.2 +ecmascript@0.16.2 +ecmascript-runtime@0.8.0 +ecmascript-runtime-client@0.12.1 +ecmascript-runtime-server@0.11.0 +ejson@1.1.2 fetch@0.1.1 geojson-utils@1.0.10 -html-tools@1.1.0 -htmljs@1.1.0 -id-map@1.1.0 +html-tools@1.1.3 +htmljs@1.1.1 +id-map@1.1.1 inter-process-messaging@0.1.1 jquery@1.11.10 -local-test:blaze@2.5.0 -logging@1.2.0 -meteor@1.9.3 -minimongo@1.6.2 -modern-browsers@0.1.5 -modules@0.16.0 -modules-runtime@0.12.0 -mongo@1.11.0 +local-test:blaze@2.6.1-rc.1 +logging@1.3.1 +meteor@1.10.0 +minimongo@1.8.0 +modern-browsers@0.1.7 +modules@0.18.0 +modules-runtime@0.13.0 +mongo@1.14.6 mongo-decimal@0.1.2 mongo-dev-server@1.1.0 -mongo-id@1.0.7 -npm-mongo@3.9.0 +mongo-id@1.0.8 +npm-mongo@4.3.1 observe-sequence@1.0.16 ordered-dict@1.1.0 -promise@0.11.2 +promise@0.12.0 random@1.2.0 -react-fast-refresh@0.1.0 +react-fast-refresh@0.2.3 reactive-var@1.0.11 reload@1.3.1 retry@1.1.0 -routepolicy@1.1.0 -socket-stream-client@0.3.1 +routepolicy@1.1.1 +socket-stream-client@0.4.0 spacebars@1.0.15 spacebars-compiler@1.1.2 templating@1.3.2 templating-compiler@1.3.2 templating-runtime@1.3.2 templating-tools@1.1.2 -test-helpers@1.2.0 -tinytest@1.1.0 +test-helpers@1.3.0 +tinytest@1.2.1 tracker@1.2.0 underscore@1.0.10 -webapp@1.10.1 +webapp@1.13.1 webapp-hashing@1.1.0 diff --git a/packages/blaze/package.js b/packages/blaze/package.js index 9aee49ae9..849029be4 100644 --- a/packages/blaze/package.js +++ b/packages/blaze/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'blaze', summary: "Meteor Reactive Templating library", - version: '2.6.1-rc.0', + version: '2.6.1-rc.1', git: 'https://github.com/meteor/blaze.git' }); diff --git a/packages/spacebars-tests/package.js b/packages/spacebars-tests/package.js index d9a52c1fa..11a341ad2 100644 --- a/packages/spacebars-tests/package.js +++ b/packages/spacebars-tests/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'spacebars-tests', summary: "Additional tests for Spacebars", - version: '1.3.0', + version: '1.3.1-rc.1', git: 'https://github.com/meteor/blaze.git' }); diff --git a/packages/templating-runtime/package.js b/packages/templating-runtime/package.js index a4b177b66..311fd489e 100644 --- a/packages/templating-runtime/package.js +++ b/packages/templating-runtime/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'templating-runtime', summary: "Runtime for compiled .html files", - version: '1.6.1', + version: '1.6.1-rc.1', git: 'https://github.com/meteor/blaze.git', documentation: null }); @@ -23,13 +23,13 @@ Package.onUse(function (api) { // Blaze, so anybody using templating (eg apps) need to implicitly use // 'meteor' and 'blaze'. api.use([ - 'blaze@2.6.0', + 'blaze@2.6.1-rc.1', 'spacebars@1.2.1', 'ecmascript@0.15.1' ]); api.imply([ 'meteor@1.10.0', - 'blaze@2.6.0', + 'blaze@2.6.1-rc.1', 'spacebars@1.2.1' ], 'client'); From cfae2c4d8011d7c696b65a60af1b6efa8fa53d38 Mon Sep 17 00:00:00 2001 From: jankapunkt Date: Tue, 26 Apr 2022 16:32:59 +0200 Subject: [PATCH 10/16] fix: Blaze.remove should destroy view before detaching --- packages/blaze/view.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/blaze/view.js b/packages/blaze/view.js index dbf5277c1..9048efaee 100644 --- a/packages/blaze/view.js +++ b/packages/blaze/view.js @@ -692,9 +692,11 @@ Blaze.remove = function (view) { while (view) { if (! view.isDestroyed) { var range = view._domrange; - if (range.attached && ! range.parentRange) - range.detach(); range.destroy(); + + if (range.attached && ! range.parentRange) { + range.detach(); + } } view = view._hasGeneratedParent && view.parentView; From 85c24b97f2a663ef9cd44f3da2a28b8f9613f4f8 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sat, 18 Jun 2022 20:23:31 +0200 Subject: [PATCH 11/16] [blaze] Modify 'Must be attached' error Now it outputs a more descriptive version: `${event} event triggerd with ${selector} on ${templateName} but associated view is not be found. Make sure the event doesn't destroy the view.` Fixes https://github.com/meteor/blaze/issues/213 --- packages/blaze/domrange.js | 6 ++++-- packages/blaze/view.js | 2 +- packages/blaze/view_tests.js | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/blaze/domrange.js b/packages/blaze/domrange.js index ca39ac459..216d434ae 100644 --- a/packages/blaze/domrange.js +++ b/packages/blaze/domrange.js @@ -332,9 +332,11 @@ DOMRange.prototype.destroy = function (_skipNodes) { DOMRange._destroy(this, _skipNodes); }; -DOMRange.prototype.containsElement = function (elem) { +DOMRange.prototype.containsElement = function (elem, selector, event) { + const templateName = this.view.name.split('.')[1]; if (! this.attached) - throw new Error("Must be attached"); + throw new Error(`${event} event triggerd with ${selector} on ${templateName} but associated view is not be found. + Make sure the event doesn't destroy the view.`); // An element is contained in this DOMRange if it's possible to // reach it by walking parent pointers, first through the DOM and diff --git a/packages/blaze/view.js b/packages/blaze/view.js index 413bb4ab7..185197e62 100644 --- a/packages/blaze/view.js +++ b/packages/blaze/view.js @@ -895,7 +895,7 @@ Blaze._addEventMap = function (view, eventMap, thisInHandler) { handles.push(Blaze._EventSupport.listen( element, newEvents, selector, function (evt) { - if (! range.containsElement(evt.currentTarget)) + if (! range.containsElement(evt.currentTarget, selector, newEvents)) return null; var handlerThis = thisInHandler || this; var handlerArgs = arguments; diff --git a/packages/blaze/view_tests.js b/packages/blaze/view_tests.js index c9f271723..fe1796a1d 100644 --- a/packages/blaze/view_tests.js +++ b/packages/blaze/view_tests.js @@ -56,4 +56,9 @@ if (Meteor.isClient) { test.equal(buf, ""); }); + Tinytest.add("blaze - view - attached", function (test) { + test.throws(() => Blaze._DOMRange.prototype.containsElement.call({attached: false, view: {name: 'Template.foo'}}, undefined, '.class', 'click'), + `click event triggerd with .class on foo but associated view is not be found. + Make sure the event doesn't destroy the view.`) + }); } From 64373078ae4a720bb57eb1fdd17be097ddca07e3 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sun, 19 Jun 2022 08:05:48 +0200 Subject: [PATCH 12/16] Add test for https://github.com/meteor/blaze/pull/374 --- packages/blaze/view_tests.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/blaze/view_tests.js b/packages/blaze/view_tests.js index c9f271723..acd04bc4c 100644 --- a/packages/blaze/view_tests.js +++ b/packages/blaze/view_tests.js @@ -56,4 +56,14 @@ if (Meteor.isClient) { test.equal(buf, ""); }); + + Tinytest.add("blaze - view - destroy", function (test) { + var v = { + _domrange: Blaze._DOMRange([]) + }; + v._domrange.view = Blaze.View(); + v.isDestroyed = false; + Blaze.remove(v); + test.equal(v._domrange.view.isDestroyed, true); + }); } From 53fdacb68966dbef904807162d6683b70de849e4 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sun, 19 Jun 2022 08:14:53 +0200 Subject: [PATCH 13/16] Check for isDestroyed before Blaze.remove --- packages/blaze/view_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/blaze/view_tests.js b/packages/blaze/view_tests.js index acd04bc4c..2bc60abe4 100644 --- a/packages/blaze/view_tests.js +++ b/packages/blaze/view_tests.js @@ -62,7 +62,7 @@ if (Meteor.isClient) { _domrange: Blaze._DOMRange([]) }; v._domrange.view = Blaze.View(); - v.isDestroyed = false; + test.equal(v._domrange.view.isDestroyed, false); Blaze.remove(v); test.equal(v._domrange.view.isDestroyed, true); }); From dc2a520d2c3892460d92b4aa03295b479f662e24 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sun, 19 Jun 2022 09:25:37 +0200 Subject: [PATCH 14/16] [blaze] Add guarding for templateName --- packages/blaze/domrange.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/blaze/domrange.js b/packages/blaze/domrange.js index 216d434ae..4be7662ee 100644 --- a/packages/blaze/domrange.js +++ b/packages/blaze/domrange.js @@ -333,7 +333,7 @@ DOMRange.prototype.destroy = function (_skipNodes) { }; DOMRange.prototype.containsElement = function (elem, selector, event) { - const templateName = this.view.name.split('.')[1]; + const templateName = this.view.name?.split('.')[1]; if (! this.attached) throw new Error(`${event} event triggerd with ${selector} on ${templateName} but associated view is not be found. Make sure the event doesn't destroy the view.`); From 334130c26b320e4e6a75b1a32519405867eb3fa2 Mon Sep 17 00:00:00 2001 From: harryadel Date: Sun, 19 Jun 2022 09:35:50 +0200 Subject: [PATCH 15/16] [blaze] Add 'unkown template' as a fallback to templateName --- packages/blaze/domrange.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/blaze/domrange.js b/packages/blaze/domrange.js index 4be7662ee..f9baa465f 100644 --- a/packages/blaze/domrange.js +++ b/packages/blaze/domrange.js @@ -333,7 +333,9 @@ DOMRange.prototype.destroy = function (_skipNodes) { }; DOMRange.prototype.containsElement = function (elem, selector, event) { - const templateName = this.view.name?.split('.')[1]; + const templateName = this.view?.name + ? this.view.name.split('.')[1] + : 'unknown template'; if (! this.attached) throw new Error(`${event} event triggerd with ${selector} on ${templateName} but associated view is not be found. Make sure the event doesn't destroy the view.`); From 03ac1fc2eaa70156d6bfafe7538fc4be566d66c6 Mon Sep 17 00:00:00 2001 From: denihs Date: Mon, 4 Jul 2022 09:21:36 -0400 Subject: [PATCH 16/16] - bumping blaze version to 2.6.1-rc.2 --- packages/blaze/package.js | 2 +- packages/spacebars-tests/.versions | 64 +++++++++++------------ packages/spacebars-tests/package.js | 2 +- packages/templating-runtime/.versions | 70 +++++++++++++------------- packages/templating-runtime/package.js | 6 +-- 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/packages/blaze/package.js b/packages/blaze/package.js index 849029be4..1a07bafb9 100644 --- a/packages/blaze/package.js +++ b/packages/blaze/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'blaze', summary: "Meteor Reactive Templating library", - version: '2.6.1-rc.1', + version: '2.6.1-rc.2', git: 'https://github.com/meteor/blaze.git' }); diff --git a/packages/spacebars-tests/.versions b/packages/spacebars-tests/.versions index 76b5f7358..7fe5e486c 100644 --- a/packages/spacebars-tests/.versions +++ b/packages/spacebars-tests/.versions @@ -1,6 +1,6 @@ -allow-deny@1.1.0 -babel-compiler@7.6.1 -babel-runtime@1.5.0 +allow-deny@1.1.1 +babel-compiler@7.9.0 +babel-runtime@1.5.1 base64@1.0.12 binary-heap@1.0.11 blaze@2.5.0 @@ -8,62 +8,62 @@ blaze-tools@1.1.0 boilerplate-generator@1.7.1 caching-compiler@1.2.2 caching-html-compiler@1.2.0 -callback-hook@1.3.0 +callback-hook@1.4.0 check@1.3.1 ddp@1.4.0 -ddp-client@2.4.0 +ddp-client@2.5.0 ddp-common@1.4.0 -ddp-server@2.3.2 +ddp-server@2.5.0 diff-sequence@1.1.1 -dynamic-import@0.6.0 -ecmascript@0.15.1 -ecmascript-runtime@0.7.0 -ecmascript-runtime-client@0.11.0 -ecmascript-runtime-server@0.10.0 -ejson@1.1.1 +dynamic-import@0.7.2 +ecmascript@0.16.2 +ecmascript-runtime@0.8.0 +ecmascript-runtime-client@0.12.1 +ecmascript-runtime-server@0.11.0 +ejson@1.1.2 es5-shim@4.8.0 fetch@0.1.1 geojson-utils@1.0.10 html-tools@1.1.0 htmljs@1.1.0 -id-map@1.1.0 +id-map@1.1.1 inter-process-messaging@0.1.1 jquery@1.11.10 -local-test:spacebars-tests@1.3.0 -logging@1.2.0 +local-test:spacebars-tests@1.3.1-rc.2 +logging@1.3.1 markdown@1.0.14 -meteor@1.9.3 -minimongo@1.6.2 -modern-browsers@0.1.5 -modules@0.16.0 -modules-runtime@0.12.0 -mongo@1.11.1 -mongo-decimal@0.1.2 +meteor@1.10.0 +minimongo@1.8.0 +modern-browsers@0.1.8 +modules@0.18.0 +modules-runtime@0.13.0 +mongo@1.15.0 +mongo-decimal@0.1.3 mongo-dev-server@1.1.0 -mongo-id@1.0.7 -npm-mongo@3.9.0 +mongo-id@1.0.8 +npm-mongo@4.3.1 observe-sequence@1.0.16 ordered-dict@1.1.0 -promise@0.11.2 +promise@0.12.0 random@1.2.0 -react-fast-refresh@0.1.0 +react-fast-refresh@0.2.3 reactive-dict@1.3.0 reactive-var@1.0.11 reload@1.3.1 retry@1.1.0 -routepolicy@1.1.0 +routepolicy@1.1.1 session@1.2.0 -socket-stream-client@0.3.1 +socket-stream-client@0.5.0 spacebars@1.2.0 spacebars-compiler@1.2.0 -spacebars-tests@1.3.0 +spacebars-tests@1.3.1-rc.2 templating@1.4.1 templating-compiler@1.4.1 templating-runtime@1.5.0 templating-tools@1.2.0 -test-helpers@1.2.0 -tinytest@1.1.0 +test-helpers@1.3.0 +tinytest@1.2.1 tracker@1.2.0 underscore@1.0.10 -webapp@1.10.1 +webapp@1.13.1 webapp-hashing@1.1.0 diff --git a/packages/spacebars-tests/package.js b/packages/spacebars-tests/package.js index 11a341ad2..fbe8fa4aa 100644 --- a/packages/spacebars-tests/package.js +++ b/packages/spacebars-tests/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'spacebars-tests', summary: "Additional tests for Spacebars", - version: '1.3.1-rc.1', + version: '1.3.1-rc.2', git: 'https://github.com/meteor/blaze.git' }); diff --git a/packages/templating-runtime/.versions b/packages/templating-runtime/.versions index d98b4a17c..847b1a6a1 100644 --- a/packages/templating-runtime/.versions +++ b/packages/templating-runtime/.versions @@ -1,62 +1,62 @@ -allow-deny@1.1.0 -babel-compiler@7.6.1 -babel-runtime@1.5.0 +allow-deny@1.1.1 +babel-compiler@7.9.0 +babel-runtime@1.5.1 base64@1.0.12 binary-heap@1.0.11 -blaze@2.5.0 +blaze@2.6.1-rc.2 blaze-tools@1.1.0 boilerplate-generator@1.7.1 caching-compiler@1.2.2 caching-html-compiler@1.2.0 -callback-hook@1.3.0 +callback-hook@1.4.0 check@1.3.1 ddp@1.4.0 -ddp-client@2.4.0 +ddp-client@2.5.0 ddp-common@1.4.0 -ddp-server@2.3.2 +ddp-server@2.5.0 diff-sequence@1.1.1 -dynamic-import@0.6.0 -ecmascript@0.15.1 -ecmascript-runtime@0.7.0 -ecmascript-runtime-client@0.11.0 -ecmascript-runtime-server@0.10.0 -ejson@1.1.1 +dynamic-import@0.7.2 +ecmascript@0.16.2 +ecmascript-runtime@0.8.0 +ecmascript-runtime-client@0.12.1 +ecmascript-runtime-server@0.11.0 +ejson@1.1.2 fetch@0.1.1 geojson-utils@1.0.10 html-tools@1.1.0 -htmljs@1.1.0 -id-map@1.1.0 +htmljs@1.1.1 +id-map@1.1.1 inter-process-messaging@0.1.1 -local-test:templating-runtime@1.5.0 -logging@1.2.0 -meteor@1.9.3 -minimongo@1.6.2 -modern-browsers@0.1.5 -modules@0.16.0 -modules-runtime@0.12.0 -mongo@1.11.0 -mongo-decimal@0.1.2 +local-test:templating-runtime@1.6.1-rc.2 +logging@1.3.1 +meteor@1.10.0 +minimongo@1.8.0 +modern-browsers@0.1.8 +modules@0.18.0 +modules-runtime@0.13.0 +mongo@1.15.0 +mongo-decimal@0.1.3 mongo-dev-server@1.1.0 -mongo-id@1.0.7 -npm-mongo@3.9.0 +mongo-id@1.0.8 +npm-mongo@4.3.1 observe-sequence@1.0.16 ordered-dict@1.1.0 -promise@0.11.2 +promise@0.12.0 random@1.2.0 -react-fast-refresh@0.1.0 +react-fast-refresh@0.2.3 reactive-var@1.0.11 reload@1.3.1 retry@1.1.0 -routepolicy@1.1.0 -socket-stream-client@0.3.1 -spacebars@1.2.0 +routepolicy@1.1.1 +socket-stream-client@0.5.0 +spacebars@1.3.0 spacebars-compiler@1.2.0 templating-compiler@1.4.1 -templating-runtime@1.5.0 +templating-runtime@1.6.1-rc.2 templating-tools@1.2.0 -test-helpers@1.2.0 -tinytest@1.1.0 +test-helpers@1.3.0 +tinytest@1.2.1 tracker@1.2.0 underscore@1.0.10 -webapp@1.10.1 +webapp@1.13.1 webapp-hashing@1.1.0 diff --git a/packages/templating-runtime/package.js b/packages/templating-runtime/package.js index 311fd489e..e2d410d49 100644 --- a/packages/templating-runtime/package.js +++ b/packages/templating-runtime/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'templating-runtime', summary: "Runtime for compiled .html files", - version: '1.6.1-rc.1', + version: '1.6.1-rc.2', git: 'https://github.com/meteor/blaze.git', documentation: null }); @@ -23,13 +23,13 @@ Package.onUse(function (api) { // Blaze, so anybody using templating (eg apps) need to implicitly use // 'meteor' and 'blaze'. api.use([ - 'blaze@2.6.1-rc.1', + 'blaze@2.6.1-rc.2', 'spacebars@1.2.1', 'ecmascript@0.15.1' ]); api.imply([ 'meteor@1.10.0', - 'blaze@2.6.1-rc.1', + 'blaze@2.6.1-rc.2', 'spacebars@1.2.1' ], 'client');