Skip to content

Instantly share code, notes, and snippets.

@JeroenVinke
Created December 11, 2015 18:55
Show Gist options
  • Save JeroenVinke/917ab83e09b92c523ba9 to your computer and use it in GitHub Desktop.
Save JeroenVinke/917ab83e09b92c523ba9 to your computer and use it in GitHub Desktop.
import {inject, noView, processContent, bindable, TargetInstruction} from 'aurelia-framework';
import {Compiler} from '../common/compiler';
import {DOM} from 'aurelia-pal';
import {ViewSlot} from 'aurelia-templating';
@noView
@processContent((compiler, resources, element, instruction) => {
// let html = element.innerHTML;
// if (html !== '') {
// instruction.template = html;
// }
//
// return true;
let html = element.innerHTML;
if (html !== '') {
let fragment = DOM.createDocumentFragment();
let current = element.firstChild;
while (current) {
fragment.appendChild(current);
current = current.nextSibling || element.firstChild;
}
let factory = compiler.compile(fragment, resources);
instruction.factory = factory;
}
return false;
})
@inject(TargetInstruction, Compiler)
export class AuCol {
@bindable title;
@bindable field;
@bindable format;
@bindable command;
@bindable width;
@bindable lockable;
@bindable locked;
template;
constructor(targetInstruction, compiler) {
this.factory = targetInstruction.elementInstruction.factory;
if (this.factory) {
this.template = (dataItem) => {
let view = this.factory.create();
let viewSlot = new ViewSlot(DOM.createElement('span'), false);
viewSlot.add(view);
viewSlot.bind(dataItem);
viewSlot.attached();
return viewSlot;
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment