Skip to content

Instantly share code, notes, and snippets.

@djedi
Last active December 21, 2020 00:49
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/207296739baf5ad6948fbfc6167f1ad7 to your computer and use it in GitHub Desktop.
Save djedi/207296739baf5ad6948fbfc6167f1ad7 to your computer and use it in GitHub Desktop.
Basic Aurelia Gist Starter
<template>
<require from="./toggle-code"></require>
<toggle-code>
<br><hr><hr>
</toggle-code>
<toggle-code>
<table>
<thead>
<tr>
<td>Head 1</td>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
</tr>
</tbody>
</table>
</toggle-code>
</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>
<span style="display: none"><slot></slot></span>
<style>
pre {
background-color: #eee;
border: 1px solid #999;
padding: 3px 9px;
}
</style>
<div style="${visible ? '' : 'display:none'}">
<div style="${render ? 'display:none' : ''}">
<pre><code class="language-markup" au-syntax textcontent.bind="code"></code></pre>
</div>
<div style="${render ? '' : 'display:none'}" innerhtml.bind="code"></div>
<button click.delegate="renderCode()">Render</button>
</div>
<button click.delegate="toggleCodeBlock()">${visible ? 'Hide' : 'Show'} Code</button>
<br><br>
</template>
import {processContent, child} from 'aurelia-framework';
@processContent((compiler, resources, node) => {
const originalContent = node.innerHTML;
node.innerHTML = `<hackity-hack style="display:none" data.bind='${JSON.stringify(originalContent)}'></hackity-hack>`;
return true;
})
export class toggleCode {
@child('hackity-hack') hackData;
attached() {
this.visible = true;
this.render = false;
this.code = this.hackData.data.trim();
}
toggleCodeBlock() {
this.visible = !this.visible;
}
renderCode() {
this.render = !this.render;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment