-
-
Save bigopon/996a176e979c4c8dd84857ca50f99f37 to your computer and use it in GitHub Desktop.
process-content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Dumber Gist</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"> | |
<base href="/"> | |
</head> | |
<!-- | |
Dumber gist uses dumber bundler, the default bundle file | |
is /dist/entry-bundle.js. | |
The starting module is pointed to aurelia-bootstrapper | |
(data-main attribute on script) for Aurelia, | |
The aurelia bootstrapper then loads up user module "main" | |
(aurelia-app attribute on <body>) which is your src/main.ts. | |
--> | |
<body aurelia-app="main"> | |
<script src="/dist/entry-bundle.js" data-main="aurelia-bootstrapper"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"aurelia-bootstrapper": "^2.3.3" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<!-- Try to create a css/scss/sass/less file then require it here --> | |
<h1>${message}</h1> | |
<slotted-element> | |
<troubled><span>Works in root!</span></troubled> | |
<parent></parent> | |
</slotted-element> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
public message: string = 'Hello Aurelia!'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Aurelia, FrameworkConfiguration} from 'aurelia-framework'; | |
export function configure(aurelia: Aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging('info') | |
.globalResources(['troubled','slotted-element']); | |
aurelia.use.postTask(() => { | |
const config = new FrameworkConfiguration(aurelia); | |
config.globalResources(['parent']); | |
return config.apply(); | |
}); | |
aurelia.start().then(() => aurelia.setRoot()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<!--<require from="./troubled"></require>--> | |
<troubled repeat.for="i of items"><span>Works in parent!</span></troubled> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
customElement, processContent, ViewCompiler, ViewResources, BehaviorInstruction, | |
ViewCompileInstruction, useView, PLATFORM, containerless | |
} from 'aurelia-framework'; | |
@customElement('parent') | |
@containerless | |
export class Parent { | |
items = [1,2]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
Slotted | |
<div> | |
<slot></slot> | |
</div> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SlottedElement { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template>The real template is in the processContent function</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
customElement, processContent, ViewCompiler, ViewResources, BehaviorInstruction, | |
ViewCompileInstruction, useView, PLATFORM | |
} from 'aurelia-framework'; | |
@customElement('troubled') | |
@processContent(Troubled.processContent) | |
export class Troubled { | |
static processContent(viewCompiler: ViewCompiler, _resources: ViewResources, element: Element, instruction: BehaviorInstruction) { | |
const elementResource = instruction.type; | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
const viewResources = (elementResource as any).viewFactory.resources; | |
const shouldCreateFactory = element.children.length > 0; | |
// inside this if, we are going to create a new factory to supply | |
// to the creation of the custom element | |
if (shouldCreateFactory) { | |
const compileInstruction = new ViewCompileInstruction(/* shadow DOM? */false, true); | |
const template = ` | |
<template class="troubled"> | |
<div class="troubled__container"> | |
${element.innerHTML} | |
</div> | |
</template>`; | |
const viewFactory = viewCompiler.compile(template, viewResources, compileInstruction); | |
// override default view factory | |
// Aurelia fallbacks to instruction view factory if there's any | |
instruction.viewFactory = viewFactory; | |
// only use the content as template | |
// remove all after use to avoid undesirable visual | |
element.innerHTML = ''; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment