Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions template/partials/codeTemplate.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{#if example}}
<template id="{{id}}-example-template">{{{example.description}}}</template>
{{/if}}
{{#children}}
{{~> codeTemplate}}
{{/children}}
2 changes: 1 addition & 1 deletion template/partials/section.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="livingcss__section-description">{{{description}}}</div>

{{#if example}}
<livingcss-example>{{{example.description}}}</livingcss-example>
<livingcss-example example="{{id}}"></livingcss-example>
{{/if}}

{{#if code}}
Expand Down
45 changes: 40 additions & 5 deletions template/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,51 @@
<link rel="stylesheet" href="{{this}}">
{{/each}}
<!-- /user styles -->

<script src="https://cdn.jsdelivr.net/webcomponentsjs/0.7.24/webcomponents.min.js"></script>
</head>
<body class="livingcss">
<!-- webcomponent -->
<!--
inlining polymer makes this section really long, but inlining it prevents FOUC and
makes all examples the correct size when created for determining scroll positions
inlining web components prevents FOUC and makes all examples the correct
size when created for determining scroll positions
-->
{{> polymer}}
<template id="livingcss-example-template">
<style>
:host {
display: block;
}

{{#each parsedStylesheets}}
{{{this}}}

{{/each}}
</style>
</template>

{{#each sections}}
{{~> codeTemplate }}
{{/each}}

<script>
class LivingCSSExample extends HTMLElement {
constructor() {
super();

const template = document.getElementById('livingcss-example-template');
const shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.appendChild(template.content.cloneNode(true));

this._shadowRoot = shadowRoot;
}

connectedCallback() {
const example = this.getAttribute('example');
const template = document.getElementById(`${example}-example-template`);
this._shadowRoot.appendChild(template.content.cloneNode(true));
}
}

customElements.define('livingcss-example', LivingCSSExample);
</script>
<!-- /webcomponent -->

<div class="livingcss__wrapper">
Expand Down