Skip to content

Commit

Permalink
Fixed bug variable names
Browse files Browse the repository at this point in the history
Fixed issue with variable names containing $.  Added test for special characters in variable names $ _
  • Loading branch information
moappi committed Jan 24, 2022
1 parent 479ead3 commit 5ca9d93
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2021 JSON2HTML. https://json2html.com/
Copyright (c) 2022 JSON2HTML. https://www.json2html.com/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jQuery
Use seemlessly with jQuery, oh did we also mention that you can embed events in your template? Forget attaching your events after you've rendered your templates.
```javascript
{"<>":"button","text":"Click Me","onclick":funciton(e){
{"<>":"button","text":"Click Me","onclick":(e)=>{
alert("You just clicked this");
}};
```
Expand All @@ -59,7 +59,7 @@ Will render into the following html and will alert when clicked :)
Node.js
=========
Use your temlpates seemlessly on Node.js (sorry no events here)
Use your temlpates seemlessly on Node.js
Installation
------------
Expand Down
6 changes: 3 additions & 3 deletions examples/arrays.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ <h1>Working with Data Mapping &amp; Arrays</h1>
//List the access that each employee has
{"<>":"ul","html":[

//We can list all the access by simply mapping the access array (using the reserved obj attribute) to the li element
//We can list all the access by simply mapping the access array (using the reserved {} attribute) to the li element
// this will repeat an li element for every value in the array
// NOTE the $ reserved attribute needs to be a function that returns the data you wish to map
// NOTE the {} reserved attribute needs to be a function that returns the data you wish to map
// this also works for components! But we'll get to this later
{"<>":"li","obj":function(){
{"<>":"li","{}":function(){
return(this.access);
},"text":"${value}"}
]}
Expand Down
2 changes: 1 addition & 1 deletion examples/wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

//Render the employees payments using the employee/payment component
// note that we need to pass the payment array directly to this component so it can render each payment
// the obj property MUST be a function with the return value being the data object used to render this component
// the {} property MUST be a function with the return value being the data object used to render this component
{"[]":"employee/payment","{}":function(){
return(this.payments);
}}
Expand Down
4 changes: 2 additions & 2 deletions json2html.es6.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// json2html.es6.js 2.2.0
// json2html.es6.js 2.2.1
// https://www.json2html.com
// (c) 2006-2021 Crystalline Technologies
// (c) 2006-2022 Crystalline Technologies
// json2html may be freely distributed under the MIT license.

(function() {
Expand Down
8 changes: 4 additions & 4 deletions json2html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// json2html.js 2.2.0
// json2html.js 2.2.1
// https://www.json2html.com
// (c) 2006-2021 Crystalline Technologies
// (c) 2006-2022 Crystalline Technologies
// json2html may be freely distributed under the MIT license.

(function() {
Expand Down Expand Up @@ -134,7 +134,7 @@
if(!root.json2html) root.json2html = {};

//Current Version
root.json2html.version = "2.2.0";
root.json2html.version = "2.2.1";

//Render a json2html template
// obj : json object to render, or json string
Expand Down Expand Up @@ -845,7 +845,7 @@
function _parse(str, method) {

let tokenizer = new Tokenizer([
/\${([\w\.\,]+)}/
/\${([\w\.\,\$]+)}/
],function( src, real, re ){
return real ? src.replace(re,method) : src;
}
Expand Down
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"name": "node-json2html",
"description": "json2html - HTML Templating in Pure Javascript",
"version": "2.2.0",
"version": "2.2.1",
"homepage": "https://www.json2html.com",
"repository": {
"url": "git://github.com/moappi/json2html.git"
Expand Down
8 changes: 8 additions & 0 deletions test/test.render.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ module.exports =
"template":{"<>":"div","html":"${name}"},
"html":""
},

//Special characters in variable name $ _
{
"name":"Render Data Special Characters ($_)",
"data":{"$var":"$","_var":"_"},
"template":{"<>":"div","html":"${$var} ${_var}"},
"html":"<div>$ _</div>"
},

//Object Array
{
Expand Down

0 comments on commit 5ca9d93

Please sign in to comment.