Comparing version 1.2.0 to 2.0.0
@@ -0,1 +1,4 @@ | ||
# 2.0.0 | ||
* Changed: `<eh-placeholder>` is no longer a void element, its content indicates the default value if no content for it is provided | ||
# 1.2.0 | ||
@@ -2,0 +5,0 @@ * Added: support for custom elements |
@@ -92,3 +92,6 @@ /*jshint evil:true*/ | ||
function createCode(tokens) { | ||
let code = 'var __output = "";\nlocals = locals || {};\nwith(locals) {' | ||
let code = `var __output = ""; | ||
locals = locals || {}; | ||
__contents = locals.__contents || {}; | ||
with(locals) {` | ||
@@ -95,0 +98,0 @@ for (let i = 0, len = tokens.length; i < len; i++) { |
@@ -48,3 +48,3 @@ 'use strict' | ||
let content = compile.createCode(reduce(tokens)) | ||
jsCode += `\n\t\t"${jsEscape(name)}": function () {\n${content}}(),` | ||
jsCode += `\n\t\t"${jsEscape(name)}": (function () {\n${content}})(),` | ||
}) | ||
@@ -96,7 +96,5 @@ | ||
module.exports.preparePlaceholder = function (element) { | ||
if (element.children.length) { | ||
throw new Error('eh-placeholder should have no content') | ||
} | ||
let name = getNameAttributeValue(element) | ||
let name = getNameAttributeValue(element), | ||
escapedName = jsEscape(name), | ||
content = compile.createCode(reduce(element.children)) | ||
return { | ||
@@ -106,3 +104,3 @@ type: 'ejs-raw', | ||
end: element.end, | ||
content: `(locals.__contents || {})["${jsEscape(name)}"] || ''` | ||
content: `"${escapedName}" in __contents ? __contents["${escapedName}"] : (function () {\n${content}})()` | ||
} | ||
@@ -109,0 +107,0 @@ } |
@@ -34,3 +34,3 @@ 'use strict' | ||
// Known void elements (elements that must have no content) | ||
voidElementsRegex = /^(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr|eh-placeholder)$/, | ||
voidElementsRegex = /^(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/, | ||
assert = require('assert') | ||
@@ -37,0 +37,0 @@ |
{ | ||
"name": "ejs-html", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"author": "Sitegui <sitegui@sitegui.com.br>", | ||
@@ -24,4 +24,4 @@ "description": "Embedded JavaScript HTML templates. Another implementation of EJS, focused on run-time performance, HTML syntax checking and outputting minified HTML.", | ||
"mocha": "^2.3.4", | ||
"should": "^8.0.1" | ||
"should": "^8.0.2" | ||
} | ||
} |
@@ -47,3 +47,3 @@ # EJS HTML | ||
This is one point that makes this not EJS compliant. In EJS, anything literal text is outputed as is. In the example above this is not happens: the text `disabled=` is not outputed if the local value `disabled` is falsy, since ejs-html knows this is a boolean attribute. | ||
This is one point that makes this not EJS compliant. In EJS, any literal text is outputed as is. In the example above this is not what happens: the text `disabled=` is not outputed if the local value `disabled` is falsy, since ejs-html knows this is a boolean attribute. | ||
@@ -77,6 +77,6 @@ ### Server-side compiled, client-side rendered | ||
### Custom elements | ||
Unleash the semantic power of HTML with custom elements. To use custom element you must first define one: | ||
Unleash the semantic power of HTML with custom elements. To use custom elements you must first define one: | ||
For example, define your own confirm dialog (in `dialog.ejs`): | ||
``` | ||
```html | ||
<div class="dialog"> | ||
@@ -89,4 +89,5 @@ <div class="dialog-title"> | ||
</div> | ||
<!-- dialog content goes here --> | ||
<eh-placeholder /> | ||
<eh-placeholder> | ||
<!-- dialog content goes here --> | ||
</eh-placeholder> | ||
<div class="dialog-buttons"> | ||
@@ -100,3 +101,3 @@ <button class="dialog-yes">Yes</button> | ||
And then use it, like: | ||
``` | ||
```html | ||
<custom-dialog title="Wanna Know?" closable> | ||
@@ -107,4 +108,6 @@ <em>HTML</em> Content | ||
The attributes on the `custom-dialog` tag is passed as locals to `dialog.ejs` and its content is replaces the `<eh-placeholder />` tag. | ||
The attributes on the `custom-dialog` tag is passed as locals to `dialog.ejs` and its content replaces the `<eh-placeholder></eh-placeholder>` tag. | ||
Custom elements is a more powerful replacement for ejs' include feature. | ||
This is the most basic usage of this feature. For more (like passing JS values and multiple content areas), see [custom-tags.md](https://github.com/sitegui/ejs-html/blob/master/custom-tags.md) | ||
@@ -117,8 +120,8 @@ | ||
* No caching | ||
* No includes | ||
* No built-in express support | ||
* No include: use custom elements instead | ||
## API | ||
The main API is the `compile` function. Everything else is auxiliary and mostly not used. | ||
The main API is the `compile` function. Everything else is auxiliary. | ||
@@ -125,0 +128,0 @@ ### compile(source[, options]) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36649
915
145