Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
agoalofalife committed Jan 16, 2017
1 parent 00803b3 commit a5bc75f
Showing 1 changed file with 59 additions and 16 deletions.
75 changes: 59 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Aromatic
#
Aromatic
## **What is it?**
This is templates with elements [mustache](http://mustache.github.io/) and similar to [handlebars](http://handlebarsjs.com/)

Expand All @@ -12,17 +13,22 @@ To use it is quite simple and trivial.

```
// index.js import Aromatic from './src/Aromatic';
let node = document.querySelector('#test');
let some = { foo : 'light', foo2 : 'some' ,
deep : {
name : 'Yee'
} } Aromatic.compile(node.innerHTML, some);
name : 'Yee
}
Aromatic.compile(node.innerHTML, some);
// first parameter is your original string
// second parameter is the object with data
// to get generated html, just call getHtml node.innerHTML = Aromatic.getHtml();
// What to find in html?
// index.html
<div id="test">
<div>{{ foo }}</div>
Expand All @@ -39,55 +45,91 @@ Expressions in parentheses correspond to data in the object


```
let data = { one : 'one string', two : 'two string' } // index.html <div id="test"> <div>{{ one }}</div> <div>{{ two }}</div> </div> // after compile <div id="test"> <div>one string</div> <div>two string</div> </div>
let data = {
one : 'one string',
two : 'two string'
}
// index.html
<div id="test">
<div>{{ one }}</div>
<div>{{ two }}</div>
</div>
// after compile
<div id="test">
<div>one string</div>
<div>two string</div>
</div>
```


_It's simple, you write Aromatic inserts_


Sometimes you may have html in data
**Sometimes you may have html in data**

example :
**example** :


```
let data = { one : '<p>one string</p>', two : '<h2>two string</h2>' }
let data = {
one : '<p>one string</p>',
two : '<h2>two string</h2>'
}
```
if you want to html escape, it is necessary in the line

```
<div id="test"> <div>{{ !!one!! }}</div> <div>{{ !!two!! }}</div> </div>
<div id="test">
<div>{{ !!one!! }}</div>
<div>{{ !!two!! }}</div>
</div>
```
**Loops? No, problem**

Let's imagine that we need a loop


```
// data let loop = [ { firstname : 'Ilya', lastname : 'Chubarov' }, { firstname : 'Maria', lastname : 'Ivanova' }, { firstname : 'Misha', lastname : 'Bootosov', age : 20 },
// data let loop = [
{ firstname : 'Ilya',
lastname : 'Chubarov'
},
{
firstname : 'Maria',
lastname : 'Ivanova'
},
{
firstname : 'Misha',
lastname : 'Bootosov',
age : 20
},
{
firstname : 'Misha',
lastname : 'Bootosov',
age : 20 ,
child : {
name : 'To'
}
} ];
}
];
// index.html
<div id="test">
<div class="entry">
<ul>
{{#each loop}}
{{#each loop}}
<li>
<p>firstname : {{ firstname }}</p>
<p>lastname {{ lastname }}p>
<p>lastname {{ lastname }}<p>
{{#if age}}
<h1>{{ age }}</h1>
{{#else}}
<p>it is unknown how many years</p>
{{/if}}
{{#if child}}
<h1>{{ child.name }}</h1>
{{/if}}
Expand All @@ -100,8 +142,6 @@ name : 'To'

**I want to add your filter values**



```
let data = {
Expand All @@ -115,14 +155,17 @@ two : 'two string'
<div>{{ two }}</div>
</div>
Aromatic.registerFilter('toLowerCase', function(test) { return test.test.toLowerCase(); });
Aromatic.registerFilter('toLowerCase', function(test) {
return test.test.toLowerCase();
});
// after compile
<div id="test">
<div>one string</div>
<div>two string</div>
</div>
```
```



Expand Down

0 comments on commit a5bc75f

Please sign in to comment.