Skip to content

Commit

Permalink
Use Rollup for packaging dist files, update package.json scripts and …
Browse files Browse the repository at this point in the history
…documentation
  • Loading branch information
jgarber623 committed May 15, 2018
1 parent 9e8bf0d commit 22cb5a8
Show file tree
Hide file tree
Showing 14 changed files with 846 additions and 377 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
dist/*
scripts/*
spec/*
7 changes: 3 additions & 4 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
extends: 'eslint:recommended'
parserOptions:
sourceType: module
env:
browser: true
es6: true
extends: 'eslint:recommended'
globals:
define: true
module: true
rules:
indent:
- error
Expand Down
25 changes: 13 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
I'd love to have your help improving TemplateTemplate! If you'd like to pitch in, you can do so in a number of ways:

1. Look through open [Issues](https://github.com/jgarber623/TemplateTemplate/issues).
2. Review any open [Pull Requests](https://github.com/jgarber623/TemplateTemplate/pulls).
3. [Fork TemplateTemplate](#get-set-up-to-contribute) and fix an open Issue or add your own feature.
4. File new Issues if you have a good idea or see a bug and don't know how to fix it yourself. _Only do this after you've made sure the behavior or problem you're seeing isn't already documented in an open Issue._
1. Review any open [Pull Requests](https://github.com/jgarber623/TemplateTemplate/pulls).
1. [Fork TemplateTemplate](#get-set-up-to-contribute) and fix an open Issue or add your own feature.
1. File new Issues if you have a good idea or see a bug and don't know how to fix it yourself. _Only do this after you've made sure the behavior or problem you're seeing isn't already documented in an open Issue._

I definitely appreciate your interest in (and help improving) TemplateTemplate. Thanks!

Expand All @@ -24,15 +24,16 @@ If you're using a different operating system, use a different package manager, o
Contributing to TemplateTemplate is pretty straightforward:

1. Fork the TemplateTemplate repo and clone it.
2. Install development dependencies by running `npm install` from the root of the project.
3. Create a feature branch for the issue or new feature you're looking to tackle: `git checkout -b your-descriptive-branch-name`.
4. _Write some code!_
5. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `npm test`.
6. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`.
7. Push the branch to your fork of TemplateTemplate: `git push origin your-descriptive-branch-name`.
8. Create a new Pull Request and I'll give it a look!

## "But what files do I change?!?"
1. Install development dependencies by running `npm install` from the root of the project.
1. Create a feature branch for the issue or new feature you're looking to tackle: `git checkout -b your-descriptive-branch-name`.
1. Run `npm start` which instructs [Rollup](https://rollupjs.org) to watch `src/templatetemplate.js` for changes and automatically exports built files to the `dist` folder.
1. _Write some code!_
1. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `npm test`.
1. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`.
1. Push the branch to your fork of TemplateTemplate: `git push origin your-descriptive-branch-name`.
1. Create a new Pull Request and I'll give it a look!

## "But which files do I change?!?"

Excellent question. TemplateTemplate's source code is in the file `src/templatetemplate.js`. Make your changes here!

Expand Down
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,11 @@

TemplateTemplate is also really tiny:

<table>
<tbody>
<tr>
<th align="left">Uncompressed</th>
<td>1,839 bytes</td>
</tr>
<tr>
<th align="left">Minified</th>
<td>1,092 bytes</td>
</tr>
<tr>
<th align="left">Minified and gzipped</th>
<td>582 bytes</td>
</tr>
</tbody>
</table>
| Format | File Size | Gzipped Size |
|:-----------------------|:------------|:-------------|
| Uncompressed (module) | 1,502 bytes | 613 bytes |
| Uncompressed (browser) | 1,812 bytes | 717 bytes |
| Minified (browser) | 1,074 bytes | 575 bytes |

## Getting TemplateTemplate

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "templatetemplate",
"description": "A very small JavaScript <template> manipulation library.",
"version": "0.2.0",
"version": "0.3.0",
"main": "dist/templatetemplate.js",
"moduleType": [
"globals",
Expand Down
40 changes: 40 additions & 0 deletions dist/templatetemplate.es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
* TemplateTemplate v0.3.0
*
* A very small JavaScript <template> manipulation library.
*
* Source code available at: https://github.com/jgarber623/TemplateTemplate
*
* (c) 2018-present Jason Garber (https://sixtwothree.org)
*
* TemplateTemplate may be freely distributed under the MIT license.
*/

function TemplateTemplate(template, insertions) {
template = template instanceof HTMLElement ? template : document.querySelector(template);
insertions = insertions || {};
if (template === null || !(template instanceof HTMLTemplateElement)) {
throw new TypeError(template + " is not an HTMLTemplateElement");
}
if (typeof insertions !== "object") {
throw new TypeError(insertions + " is not an Object");
}
var importedNode = document.importNode(template.content, true);
Object.entries(insertions).forEach(function(insertionArray) {
var currentNode = importedNode.querySelector(insertionArray[0]), insertionValue = insertionArray[1];
if (insertionValue instanceof Array) {
Object.entries(insertionValue[1]).forEach(function(attributesArray) {
currentNode.setAttribute(attributesArray[0], attributesArray[1]);
});
insertionValue = insertionValue[0];
}
if (insertionValue instanceof DocumentFragment || insertionValue instanceof HTMLElement) {
currentNode.appendChild(insertionValue);
} else {
currentNode.textContent = insertionValue;
}
});
return importedNode;
}

export default TemplateTemplate;
21 changes: 8 additions & 13 deletions dist/templatetemplate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TemplateTemplate 0.2.0
* TemplateTemplate v0.3.0
*
* A very small JavaScript <template> manipulation library.
*
Expand All @@ -10,17 +10,11 @@
* TemplateTemplate may be freely distributed under the MIT license.
*/

(function(root, factory) {
if (typeof define === "function" && define.amd) {
define([], factory);
} else if (typeof module === "object" && module.exports) {
module.exports = factory();
} else {
root.TemplateTemplate = factory();
}
})(typeof self !== "undefined" ? self : this, function() {
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : global.TemplateTemplate = factory();
})(this, function() {
"use strict";
return function(template, insertions) {
function TemplateTemplate(template, insertions) {
template = template instanceof HTMLElement ? template : document.querySelector(template);
insertions = insertions || {};
if (template === null || !(template instanceof HTMLTemplateElement)) {
Expand All @@ -45,5 +39,6 @@
}
});
return importedNode;
};
});
}
return TemplateTemplate;
});
4 changes: 2 additions & 2 deletions dist/templatetemplate.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TemplateTemplate 0.2.0
* TemplateTemplate v0.3.0
*
* A very small JavaScript <template> manipulation library.
*
Expand All @@ -10,4 +10,4 @@
* TemplateTemplate may be freely distributed under the MIT license.
*/

!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.TemplateTemplate=t()}("undefined"!=typeof self?self:this,function(){"use strict";return function(e,t){if(e=e instanceof HTMLElement?e:document.querySelector(e),t=t||{},null===e||!(e instanceof HTMLTemplateElement))throw new TypeError(e+" is not an HTMLTemplateElement");if("object"!=typeof t)throw new TypeError(t+" is not an Object");var n=document.importNode(e.content,!0);return Object.entries(t).forEach(function(e){var t=n.querySelector(e[0]),o=e[1];o instanceof Array&&(Object.entries(o[1]).forEach(function(e){t.setAttribute(e[0],e[1])}),o=o[0]),o instanceof DocumentFragment||o instanceof HTMLElement?t.appendChild(o):t.textContent=o}),n}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.TemplateTemplate=t()}(this,function(){"use strict";return function(e,t){if(e=e instanceof HTMLElement?e:document.querySelector(e),t=t||{},null===e||!(e instanceof HTMLTemplateElement))throw new TypeError(e+" is not an HTMLTemplateElement");if("object"!=typeof t)throw new TypeError(t+" is not an Object");var n=document.importNode(e.content,!0);return Object.entries(t).forEach(function(e){var t=n.querySelector(e[0]),o=e[1];o instanceof Array&&(Object.entries(o[1]).forEach(function(e){t.setAttribute(e[0],e[1])}),o=o[0]),o instanceof DocumentFragment||o instanceof HTMLElement?t.appendChild(o):t.textContent=o}),n}});
Loading

0 comments on commit 22cb5a8

Please sign in to comment.