-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from github/initial-implementation
Initial implementation
- Loading branch information
Showing
18 changed files
with
4,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"root": true, | ||
"plugins": ["github"], | ||
"extends": ["plugin:github/recommended", "plugin:github/typescript", "plugin:github/browser"], | ||
"rules": { | ||
"no-invalid-this": "off", | ||
"@typescript-eslint/no-invalid-this": ["error"] | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": "test/*", | ||
"rules": { | ||
"github/unescaped-html-literal": "off" | ||
}, | ||
"globals": { | ||
"chai": false, | ||
"expect": false | ||
}, | ||
"env": { | ||
"mocha": true | ||
} | ||
}, | ||
{ | ||
"files": "*.cjs", | ||
"env": { | ||
"node": true | ||
} | ||
} | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Build | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test-node: | ||
name: Test on Node.js | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the project | ||
uses: actions/checkout@v2 | ||
- name: Cache node modules | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Use Node.js 14.7.0 | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.7.0 | ||
- name: Install dependencies | ||
run: npm i | ||
- name: Run Node.js Tests | ||
run: npm run test |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
*.tsbuildinfo | ||
lib/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @github/web-systems-reviewers |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 GitHub, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Template Parts | ||
|
||
This library is designed as a "ponyfill" library that implements the design in the [Template Parts Proposal](https://github.com/domenic/template-parts) that has been sketched out in order to address [whatwg/html#2254](https://github.com/whatwg/html/issues/2254). | ||
|
||
This implements the minimally viable parts of the proposal, to provide something that works, but should be easy to drop if the Template Parts Proposal lands. | ||
|
||
To reiterate the example in the above proposal, given a template such as: | ||
|
||
``` | ||
<template id="foo"> | ||
<div class="foo {{y}}">{{x}} world</div> | ||
</template> | ||
``` | ||
|
||
We'd like `{{x}}` and `{{y}}` to be **template parts**, exposed as JavaScript objects which can be manipulated. | ||
|
||
With this library, and that given template, one could implement the following: | ||
|
||
```js | ||
import {StampedTemplate} from '@github/template-parts' | ||
|
||
const tpl = new StampedTemplate(document.getElementById('foo'), (parts, params) => { | ||
for (const part of parts) { | ||
const key = part.expression.trim() | ||
const value = (key in params ? params[key] : '') | ||
if (part.attribute) { | ||
part.value = value | ||
} else { | ||
part.replaceWith(value) | ||
} | ||
} | ||
}, { x: 'Hello', y: 'bar'}) | ||
``` | ||
|
||
A `StampedTemplate` instance has the `fragment: DocumentFragment` property - the cloned contents of the template - and an `update(params: Record<string, unknown>): void` method - which when called will run the given processor again, with the new `params`. | ||
|
||
This library also comes with two ready-to-use processors: `propertyIdentity` and `propertyIdentityOrBooleanAttribute`. These processors implement a basic functionality that will replace expressions with the corresponding property value in the params object. You can use this processors rather than writing a custom one: | ||
|
||
|
||
```js | ||
import {StampedTemplate, propertyIdentity, propertyIdentityOrBooleanAttribute} from '@github/template-parts' | ||
|
||
// This will simply replace `{{x}}` with `"Hello"` and `{{y}}` with `"bar"` | ||
const tpl = new StampedTemplate(document.getElementById('foo'), propertyIdentity, { x: 'Hello', y: 'bar'}) | ||
|
||
// The `propertyIdentityOrBooleanAttribute` processor will check for `false`/`true` values which map to attribute values, and add/remove the attribute. | ||
const tpl = new StampedTemplate(document.getElementById('foo'), propertyIdentityOrBooleanAttribute, { x: 'Hello', y: false}) | ||
``` |
Oops, something went wrong.