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

Template tags support #2

Open grabbou opened 10 years ago

grabbou commented 10 years ago

In addition to our talk:

Its quite hard to accomplish tag parsing the way you proposed, as long as there is no easy way to pass additional template tags to Template.__define__ without rewriting entire html_scanner.

What about creating template helpers, like:

For copyAs it's not needed as 'pure' idea of having it is to avoid creating HTML file for a view that inherits from abstract one its properties.

I've created sample UI helper for that:

UI.registerHelper('inheritsHelpersFromTemplate', function (tmpName) {
    UI._templateInstance().__view__.template.inheritsHelpersFromTemplate(tmpName);
});
<template name="foo">
    {{inheritsHelpersFromTemplate 'bar'}}
    {{#each photos}}
          <img src="{{images.[0].source}}" />
    {{/each}}
</template>

and it works! :+1:

PR?

aldeed commented 10 years ago

I worry that they would be reactively re-run multiple times, which would re-replace and re-inherit, potentially overwriting any overrides that were defined between runs.

aldeed commented 9 years ago

I still think it would be best to use additional template attributes for this (e.g., <template name="foo" inherits-helpers-from="bar">), but as you said the core packages don't currently make this possible. It would be good to get a final verdict from MDG on whether they're willing to fold this package into blaze/templating packages, or whether we can do a PR to support tracking additional attributes that are added to template tags. Since they now take feature requests on GitHub, I'll submit an issue.

mitar commented 9 years ago

Some time ago I also create a spaceless which removes all the whitespace. One idea I had then was that this could be simply an attribute on the template as well. So you could do <template spaceless="true">...</template>. In general having custom annotations on the template could be helpful. So PR for any attributions become maybe simple values in template instance. So <template name="test" foo="bar"> would be the same as:

Template.test.created = function () {
  this._foo = "bar";
};
mitar commented 9 years ago

Or maybe:

Template.test.created = function () {
  this.attrs = {foo: "bar"};
};
aldeed commented 9 years ago

Yep, this.attrs is how I was picturing it working, too.