Skip to content

Instantly share code, notes, and snippets.

@djedi
Last active February 21, 2018 16:18
Show Gist options
  • Select an option

  • Save djedi/d3c8b68f5cf4a015a5f0fa35e7d94de3 to your computer and use it in GitHub Desktop.

Select an option

Save djedi/d3c8b68f5cf4a015a5f0fa35e7d94de3 to your computer and use it in GitHub Desktop.

Revisions

  1. djedi revised this gist Feb 21, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.html
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    </my-code-sample>

    <my-code-sample>
    <table>
    <table border="1">
    <thead>
    <tr>
    <td>Head 1</td>
  2. djedi revised this gist Feb 20, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion my-code-sample.js
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,6 @@ export class MyCodeSample {
    @child('code-sample') codeSample;

    attached() {
    this.code = this.codeSample.data;
    this.code = this.codeSample.data.trim();
    }
    }
  3. djedi revised this gist Feb 20, 2018. No changes.
  4. djedi revised this gist Feb 20, 2018. 3 changed files with 3 additions and 2 deletions.
    1 change: 1 addition & 0 deletions app.html
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    <template>
    <require from="./my-code-sample"></require>
    <require from="./my-button.html"></require>

    <my-code-sample>
    <br><hr><hr>
    2 changes: 1 addition & 1 deletion my-code-sample.html
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    <div>
    <pre><code class="language-markup" au-syntax textcontent.bind="code"></code></pre>
    </div>
    <div innerhtml.bind="code"></div>
    <template replaceable part="rendered"></template>
    </div>

    <br><br>
    2 changes: 1 addition & 1 deletion my-code-sample.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ import {processContent, child} from 'aurelia-framework';
    const stringified = JSON.stringify(originalContent);

    node.innerHTML = `<code-sample data.bind='${stringified}'></code-sample>`;
    node.innerHTML += `<template>${originalContent}</template>`;
    node.innerHTML += `<template replace-part="rendered">${originalContent}</template>`;

    return true;
    })
  5. djedi revised this gist Feb 20, 2018. 5 changed files with 35 additions and 37 deletions.
    14 changes: 9 additions & 5 deletions app.html
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    <template>
    <require from="./toggle-code"></require>
    <require from="./my-code-sample"></require>

    <toggle-code>
    <my-code-sample>
    <br><hr><hr>
    </toggle-code>
    </my-code-sample>

    <toggle-code>
    <my-code-sample>
    <table>
    <thead>
    <tr>
    @@ -18,6 +18,10 @@
    </tr>
    </tbody>
    </table>
    </toggle-code>
    </my-code-sample>

    <my-code-sample>
    <my-button></my-button>
    </my-code-sample>

    </template>
    3 changes: 3 additions & 0 deletions my-button.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <template>
    <button>My Button</button>
    </template>
    9 changes: 4 additions & 5 deletions toggle-code.html → my-code-sample.html
    Original file line number Diff line number Diff line change
    @@ -9,13 +9,12 @@
    }
    </style>

    <div style="${visible ? '' : 'display:none'}">
    <div style="${render ? 'display:none' : ''}">
    <div>
    <div>
    <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 innerhtml.bind="code"></div>
    </div>
    <button click.delegate="toggleCodeBlock()">${visible ? 'Hide' : 'Show'} Code</button>

    <br><br>
    </template>
    19 changes: 19 additions & 0 deletions my-code-sample.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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>${originalContent}</template>`;

    return true;
    })
    export class MyCodeSample {
    @child('code-sample') codeSample;

    attached() {
    this.code = this.codeSample.data;
    }
    }
    27 changes: 0 additions & 27 deletions toggle-code.js
    Original file line number Diff line number Diff line change
    @@ -1,27 +0,0 @@
    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;
    }
    }
  6. djedi revised this gist Feb 20, 2018. No changes.
  7. djedi created this gist Feb 20, 2018.
    23 changes: 23 additions & 0 deletions app.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <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>
    3 changes: 3 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    export class App {

    }
    18 changes: 18 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <!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>
    21 changes: 21 additions & 0 deletions toggle-code.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <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>
    27 changes: 27 additions & 0 deletions toggle-code.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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;
    }
    }