Skip to content

Commit

Permalink
Refactor project file structure
Browse files Browse the repository at this point in the history
- removes most dependencies
- removes build-related tasks and code
- removes lint-related tasks and code
- moves source and test files to `index[.test].js` in root of project
- updates documentation
- adds note about feature completeness

Moving forward, this package will only provide an ESM formatted file. It's 2025
and that style module is supported basically everywhere you'd use this package.
  • Loading branch information
jgarber623 committed Jan 2, 2025
1 parent 08eb675 commit 79a89df
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 2,761 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@ on:
workflow_dispatch:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: npm
- run: npm ci
- run: npm run lint
test:
name: Test (Node.js v${{ matrix.version }})
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
cache: npm
registry-url: https://registry.npmjs.org
- run: npm ci
- run: npm run build
- run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -46,7 +45,6 @@ jobs:
cache: npm
registry-url: https://npm.pkg.github.com
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/coverage/
/dist/
/node_modules/
40 changes: 10 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
[![Downloads](https://img.shields.io/npm/dt/@jgarber/templatetemplate.svg?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/@jgarber/templatetemplate)
[![Build](https://img.shields.io/github/actions/workflow/status/jgarber623/TemplateTemplate/ci.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/jgarber623/TemplateTemplate/actions/workflows/ci.yml)

> [!NOTE]
> TemplateTemplate is feature complete and will only be updated to address bugs or security issues.
### Key Features

- Uses established Web standards (e.g. `<template>`, `document.querySelector`)
- Dependency-free
- JavaScript module (ESM), CommonJS, and browser global (`window.TemplateTemplate`) support
- JavaScript module (ESM)

## Getting TemplateTemplate

Expand All @@ -22,33 +25,6 @@ You've got a couple options for adding TemplateTemplate to your project:

## Usage

If you're comfortable attaching TemplateTemplate to the browser's `window` object, you may do the following:

```html
<script src="./dist/templatetemplate.js"></script>
<script>
// Verify everything loaded properly...
console.log(window.TemplateTemplate)
</script>
```

Or, you may use the JavaScript module (ESM) version:

```html
<script type="module">
import TemplateTemplate from "./dist/templatetemplate.mjs";
// Verify everything loaded properly...
console.log(TemplateTemplate);
</script>
```

> [!NOTE]\
> Full-featured examples of both of the above approaches are available in the [`example`](https://github.com/jgarber623/TemplateTemplate/tree/main/example) folder.
> [!NOTE]\
> If you're using an asset-bundling system (there are _so many_), refer to its documentation to determine which version of TemplateTemplate you should use (ESM, CommonJS, etc.).
TemplateTemplate takes two arguments: a reference to a `<template>` element and an object of `insertions` defining the content to insert into the `<template>`.

### Basic Example
Expand Down Expand Up @@ -77,7 +53,9 @@ A basic example, inserting a row into a `<table>`:
</tr>
</template>

<script>
<script type="module">
import TemplateTemplate from "@jgarber/templatetemplate";
const tbody = document.querySelector("#projects tbody");
const emptyTemplate = document.querySelector("#row-template");
Expand Down Expand Up @@ -127,7 +105,9 @@ A more complex example, inserting a row into a `<table>` with different types of
<a></a>
</template>

<script>
<script type="module">
import TemplateTemplate from "@jgarber/templatetemplate";
const tbody = document.querySelector("#projects tbody");
const anchor = document.createElement("a");
Expand Down
17 changes: 0 additions & 17 deletions eslint.config.js

This file was deleted.

21 changes: 8 additions & 13 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,33 @@ <h1>TemplateTemplate: Example</h1>
</template>

<script type="module">
import TemplateTemplate from "../src/templatetemplate.js";
import TemplateTemplate from "../index.js";

const tbody = document.querySelector("#projects tbody");
const anchor = document.createElement("a");

tbody.appendChild(
anchor.href = "https://sixtwothree.org";
anchor.textContent = "Jason Garber";

document.querySelector("#projects tbody").append(
TemplateTemplate(document.querySelector("#row-template"), {
".name": "TemplateTemplate",
".author": "Jason Garber",
".url": "https://github.com/jgarber623/TemplateTemplate",
".languages": "JavaScript",
}),
);

let anchor = document.createElement("a");

anchor.setAttribute("href", "https://sixtwothree.org");
anchor.textContent = "Jason Garber";

tbody.appendChild(
TemplateTemplate("#row-template", {
"th": "CashCash",
"th + td": anchor,
".url": ["https://github.com/jgarber623/CashCash", {
"style": "font-style: italic;"
"style": "font-style: italic;",
}],
"td:last-child": TemplateTemplate("#anchor-template", {
"a": ["JavaScript", {
"href": "https://github.com/search?q=language%3AJavaScript",
"target": "_blank",
}],
}),
}),
})
);
</script>

Expand Down
14 changes: 12 additions & 2 deletions src/templatetemplate.js → index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
/*!
* @name TemplateTemplate
* @version 3.0.0
*
* @file A very small JavaScript <template> manipulation library.
*
* {@link https://github.com/jgarber623/TemplateTemplate}
*
* @copyright 2018 Jason Garber (https://sixtwothree.org)
* @license MIT
*/

/**
* @param {(HTMLTemplateElement|string)} template An HTML `<template>` element
* or a string representing a valid CSS selector referencing an HTML
* `<template>` element.
* @param {object} insertions An object whose keys are strings representing
* valid CSS selectors and whose values are strings, arrays, or instances of
* TemplateTemplate.
*
* @returns {DocumentFragment} The rendered HTMLTemplateElement.
*
* @throws {TypeError} Argument must be a string or an HTMLTemplateElement.
* @throws {TypeError} Argument must be an object.
*/
Expand Down
2 changes: 1 addition & 1 deletion test/templatetemplate.test.js → index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import test from "node:test";

import { JSDOM } from "jsdom";

import TemplateTemplate from "../src/templatetemplate.js";
import TemplateTemplate from "./index.js";

const html = `\
<!doctype html>
Expand Down
Loading

0 comments on commit 79a89df

Please sign in to comment.