diff --git a/spec/stdlib/template-spec.coffee b/spec/stdlib/template-spec.coffee index 299a0aa4f..184fd0cae 100644 --- a/spec/stdlib/template-spec.coffee +++ b/spec/stdlib/template-spec.coffee @@ -17,6 +17,11 @@ fdescribe "Template", -> @li outlet: 'li1', class: 'foo', "one" @li outlet: 'li2', class: 'bar', "two" + viewProperties: + initialize: (attrs) -> + @initializeCalledWith = attrs + foo: "bar" + view = Foo.build(title: "Zebra") afterEach -> @@ -29,6 +34,11 @@ fdescribe "Template", -> expect(view.find("ol > li.foo:contains(one)")).toExist() expect(view.find("ol > li.bar:contains(two)")).toExist() + it "extends the view with viewProperties, calling the 'constructor' property if present", -> + expect(view.constructor).toBeDefined() + expect(view.foo).toBe("bar") + expect(view.initializeCalledWith).toEqual(title: "Zebra") + it "wires references for elements with 'outlet' attributes", -> expect(view.li1).toMatchSelector("li.foo:contains(one)") expect(view.li2).toMatchSelector("li.bar:contains(two)") diff --git a/src/stdlib/template.coffee b/src/stdlib/template.coffee index 49c3d3197..cb4f7a31f 100644 --- a/src/stdlib/template.coffee +++ b/src/stdlib/template.coffee @@ -18,6 +18,9 @@ class Template @content(attributes) view = @builder.toFragment() @wireOutlets(view) + if @viewProperties + $.extend(view, @viewProperties) + view.initialize?(attributes) view wireOutlets: (view) ->