longshotlabs / meteor-template-extension

A Meteor package: Replace already defined templates, inherit helpers and events from other templates
https://atmospherejs.com/aldeed/template-extension
MIT License
220 stars 20 forks source link

inheritsHelpersFrom Seems Broken #6

Closed kev1597770 closed 10 years ago

kev1597770 commented 10 years ago

The copyAs and inheritsHelpersFrom functions don't work as expected. I'm not sure if this is an issue with the package or my expectations.

<template name="abstract">
  {{hello}} {{name}}
</template>
Template.abstract.helpers({
  name:  "abstract",
  hello: function() {
    return "Hello my name is ";
  }
});

Template.abstract.copyAs('foo');
Template.abstract.copyAs('bar');

//Template.foo.__helpers = jQuery.extend( {},Template.abstract.__helpers );
//Template.bar.__helpers = jQuery.extend( {},Template.abstract.__helpers );

Template.foo.helpers({
    name: "foo"
});

Template.bar.helpers({
  hello: function() {
    return "Ahoy-hoy my name is ";
  }
});

With the preceding code I would expect the following template renderings:

Abstract: "Hello my name is abstract" foo: "Hello my name is foo" bar: "Ahoy-hoy my name is abstract"

Instead I get:

Abstract: "Hello my name is abstract" foo: "foo" bar: "Ahoy-hoy my name is"

In stepping through the code it appears as though the inheritsHelpersFrom portion of copyAs is not correctly copying the abstact helpers to the foo and bar classes. Manually copying the helpers over by uncommenting the two lines of code in the preceding example seems to fix this.