Skip to content

Instantly share code, notes, and snippets.

@djedi
Last active February 21, 2018 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djedi/d3c8b68f5cf4a015a5f0fa35e7d94de3 to your computer and use it in GitHub Desktop.
Save djedi/d3c8b68f5cf4a015a5f0fa35e7d94de3 to your computer and use it in GitHub Desktop.
code sample component
<template>
<require from="./my-code-sample"></require>
<require from="./my-button.html"></require>
<my-code-sample>
<br><hr><hr>
</my-code-sample>
<my-code-sample>
<table border="1">
<thead>
<tr>
<td>Head 1</td>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
</tr>
</tbody>
</table>
</my-code-sample>
<my-code-sample>
<my-button></my-button>
</my-code-sample>
</template>
export class App {
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
<template>
<button>My Button</button>
</template>
<template>
<span style="display: none"><slot></slot></span>
<style>
pre {
background-color: #eee;
border: 1px solid #999;
padding: 3px 9px;
}
</style>
<div>
<div>
<pre><code class="language-markup" au-syntax textcontent.bind="code"></code></pre>
</div>
<template replaceable part="rendered"></template>
</div>
<br><br>
</template>
import {processContent, child} from 'aurelia-framework';
@processContent((compiler, resources, node) => {
const originalContent = node.innerHTML;
const stringified = JSON.stringify(originalContent);
node.innerHTML = `<code-sample data.bind='${stringified}'></code-sample>`;
node.innerHTML += `<template replace-part="rendered">${originalContent}</template>`;
return true;
})
export class MyCodeSample {
@child('code-sample') codeSample;
attached() {
this.code = this.codeSample.data.trim();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment