diff --git a/CHANGELOG.md b/CHANGELOG.md index da2c7ed6..e454d077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ - Put your changes here... +## 0.6.3 + +- Restored template-level caching feature with an improved API. +- Restored compile method but now with an API similar to other templating systems. It will now take a template string and return a function which when given model data will render HTML from the template and model data. +- Now hosting the Teddy playground on [https://rooseveltframework.github.io/teddy/playground.html](https://rooseveltframework.github.io/teddy/playground.html). Thanks to [jsDelivr](https://www.jsdelivr.com/package/npm/teddy?tab=files) for CDN hosting. +- Various dependencies bumped. + ## 0.6.2 - Significant performance improvements. diff --git a/README.md b/README.md index e0e0beb4..951fe7e7 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,11 @@ Teddy is the most readable and easy to learn templating language there is! Or put a more technical way, Teddy is an easy to read, HTML-inspired, mostly logic-less DOM templating engine with support for both server-side and client-side templating. -It uses HTML-like `` for rudimentary templating logic and Teddy Roosevelt's facial hair for `{variables}`. +It uses HTML-like `` for rudimentary templating logic and Teddy Roosevelt's facial hair for `{variables}`. -![Teddy Roosevelt's facial hair is a curly brace.](https://github.com/rooseveltframework/generator-roosevelt/blob/master/generators/app/templates/statics/images/teddy.jpg "Teddy Roosevelt's facial hair is a curly brace.") +[Check out this live demo](https://rooseveltframework.github.io/teddy/playground.html) or see below for documentation on how to write Teddy templates. + +![Teddy Roosevelt's facial hair is a curly brace.](https://github.com/rooseveltframework/generator-roosevelt/blob/main/generators/app/templates/statics/images/teddy.jpg "Teddy Roosevelt's facial hair is a curly brace.") Table of contents @@ -379,8 +381,13 @@ Here's what the attributes mean: - `teddy.clearCache(name, keyVal)` will delete just the value at that keyVal, e.g. just the cache for when `{city}` resolves to NY if you set keyVal to NY. - `key`: The model value to use to index new caches. - Example: Suppose `city` in the above example could resolve to three possible values: NY, SF, and LA. In that case, the caching feature will create 3 caches using the `city` key: one for each of the three possible values. +- `maxAge`: How old the cache can be in milliseconds before it is invalidated and will be re-rendered. + - Default: 0 (no limit). + - `maxCaches`: The maximum number of caches that Teddy will be allowed to create for a given `` element. If the maximum is reached, Teddy will remove the oldest cache in the stack, where oldest is defined as the least recently created *or* accessed. - - Default: 10. + - Default: 1000. + +You can also cache whole templates. For more details about that, see the API docs below. A complex example combining many tags --- @@ -443,22 +450,73 @@ API documentation === - `teddy.getTemplates()`: Get the internal cache of templates. + - `teddy.setTemplate(name, template)`: Add a new template to the template cache. + - `teddy.render(template, model)`: Render a template by supplying either source code or a file name (in Node.js). + - Returns fully rendered HTML. - Removes `{! teddy comments !}` + - `teddy.setTemplateRoot(path)`: Set the location of your templates directory. + - Default is the current directory. + +- `teddy.compile(templateString)`: Takes a template string and returns a function which when given model data will render HTML from the template and model data. + + - e.g. + + - ```javascript + const templateFunction = teddy.compile('

{hello}

') + templateFunction({ hello: 'world' }) // returns "

world

" + - `teddy.setVerbosity(n)`: Sets the level of verbosity in Teddy's console logs. Call `teddy.setVerbosity(n)` where `n` equals one of the below values to change the default: + - `0`: No logging. - `1`: The default. Concise logging. Will usually only log serious errors. - `2`: Verbose logging. Logs even minor errors. - `3`: Debug mode. Very verbose. + - `teddy.setDefaultParams()`: Reset all params to default. + - `teddy.maxPasses(n)`: Sets the maximum number of passes the parser can execute over your template. If this maximum is exceeded, Teddy will stop attempting to render the template. The limit exists to prevent the possibility of teddy producing infinite loops due to improperly coded templates. - Default: 1000. -- `teddy.clearCache(name)`: Deletes the whole cache at that name. -- `teddy.clearCache(name, keyVal)`: Deletes just the value at that keyVal. + +- `teddy.setCache(params)`: Declare a template-level cache. + + - Params: + + - `template`: Name of the template to cache. + - `key`: Model variable to cache it by. + - Set to `none` to cache the first render for all model values. + + - `maxAge`: How old the cache can be in milliseconds before it is invalidated and will be re-rendered. + - Default: 0 (no limit). + + - `maxCaches`: The maximum number of caches that Teddy will be allowed to create for a given template/key combination. If the maximum is reached, Teddy will remove the oldest cache in the stack, where oldest is defined as the least recently created *or* accessed. + - Default: 1000. + - Note: does not apply to caches where `key` is not also set. + + - Example: + + - ```javascript + teddy.setCache({ + template: 'someTemplate.html', + key: 'city', + maxAge: 1000 + }) + +- `teddy.clearCache(name)`: If `name` is a string, it will delete the whole cache at that name. + +- `teddy.clearCache(name, keyVal)`: Deletes just the value at that keyVal. Assumes `name` will be a string. + +- `teddy.clearCache(params)`: If `params` is an object, it will delete a whole template-level cache. + + - Params: + - `template`: Name of the template to delete the cache of. + - `key`: Model variable cache index to delete it by. + - If `key` is not provided, it will delete all caches of that template. + Hacking the code === diff --git a/package-lock.json b/package-lock.json index ac6f9102..9f736c7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "teddy", - "version": "0.6.2", + "version": "0.6.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "teddy", - "version": "0.6.2", + "version": "0.6.3", "license": "CC-BY-4.0", "dependencies": { "cheerio": "1.0.0-rc.12", @@ -24,7 +24,7 @@ "karma": "6.4.2", "karma-chrome-launcher": "3.2.0", "karma-cli": "2.0.0", - "karma-coverage": "2.2.0", + "karma-coverage": "2.2.1", "karma-edge-launcher": "0.4.2", "karma-firefox-launcher": "2.1.2", "karma-html2js-preprocessor": "1.1.0", @@ -759,9 +759,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.3.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.1.tgz", - "integrity": "sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==", + "version": "20.3.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.2.tgz", + "integrity": "sha512-vOBLVQeCQfIcF/2Y7eKFTqrMnizK5lRNQ7ykML/5RuwVXVWxYkgwS7xbt4B6fKCUPgbSL5FSsjHQpaGQP/dQmw==", "dev": true }, "node_modules/@webassemblyjs/ast": { @@ -1769,9 +1769,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001506", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001506.tgz", - "integrity": "sha512-6XNEcpygZMCKaufIcgpQNZNf00GEqc7VQON+9Rd0K1bMYo8xhMZRAo5zpbnbMNizi4YNgIDAFrdykWsvY3H4Hw==", + "version": "1.0.30001508", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001508.tgz", + "integrity": "sha512-sdQZOJdmt3GJs1UMNpCCCyeuS2IEGLXnHyAo9yIO5JJDjbjoVRij4M1qep6P6gFpptD1PqIYgzM+gwJbOi92mw==", "dev": true, "funding": [ { @@ -2562,9 +2562,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.439", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.439.tgz", - "integrity": "sha512-BHpErPSNhb9FB25+OwQP6mCAf3ZXfGbmuvc4LzBNVJwpCcXQJm++LerimocYRG9FRxUVRKZqaB7d0+pImSTPSg==", + "version": "1.4.441", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.441.tgz", + "integrity": "sha512-LlCgQ8zgYZPymf5H4aE9itwiIWH4YlCiv1HFLmmcBeFYi5E+3eaIFnjHzYtcFQbaKfAW+CqZ9pgxo33DZuoqPg==", "dev": true }, "node_modules/elliptic": { @@ -4907,9 +4907,9 @@ } }, "node_modules/karma-coverage": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/karma-coverage/-/karma-coverage-2.2.0.tgz", - "integrity": "sha512-gPVdoZBNDZ08UCzdMHHhEImKrw1+PAOQOIiffv1YsvxFhBjqvo/SVXNk4tqn1SYqX0BJZT6S/59zgxiBe+9OuA==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/karma-coverage/-/karma-coverage-2.2.1.tgz", + "integrity": "sha512-yj7hbequkQP2qOSb20GuNSIyE//PgJWHwC2IydLE6XRtsnaflv+/OSGNssPjobYUlhVVagy99TQpqUt3vAUG7A==", "dev": true, "dependencies": { "istanbul-lib-coverage": "^3.2.0", diff --git a/package.json b/package.json index b346fe84..21312b5e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "https://github.com/rooseveltframework/teddy/graphs/contributors" } ], - "version": "0.6.2", + "version": "0.6.3", "files": [ "dist/teddy.js", "dist/cheerio.client.js" @@ -36,7 +36,7 @@ "karma": "6.4.2", "karma-chrome-launcher": "3.2.0", "karma-cli": "2.0.0", - "karma-coverage": "2.2.0", + "karma-coverage": "2.2.1", "karma-edge-launcher": "0.4.2", "karma-firefox-launcher": "2.1.2", "karma-html2js-preprocessor": "1.1.0", diff --git a/playground.html b/playground.html index f80bed98..b4505889 100644 --- a/playground.html +++ b/playground.html @@ -39,7 +39,10 @@

Teddy Templating Engine playground

- + + + +