<commit_before># raze-tpl
A js template engine with syntax like [Microsoft Razor Render Engine](https://github.com/aspnet/Razor)

## how to use
### build
`make`

### use
```
var raze = require('./index');

var tpl = fs.readFileSync(filename, 'utf-8');

var render = raze(tpl, {
  safe: false // true to add try/catch to variables accessing
});

var html = render(data);
```

## test and see the demo of syntax/features
* `node test.js`
* see `tpls/template.html` and `tpls/template.out.html`

## syntax and fetures

### variable outputing
#### implicit
```
<span>@some_variable[index]</span>
```
#### explicit
```
<span>@(some_variable[index])</span>
```
#### no html escaping
```
<span@(-some_variable[index])</span>
```
#### filtering
```
<span>@(some_variable[index] | replace(/lorem/ig, '>>$0<<')</span>
```

### flow control
#### loop on array
```
@each (value in arr) {
  <li>@value</li>
}
@each (index:value in arr) {
  <li>No.@index of arr is @value</li>
}
```
#### loop on kv-obj
```
@objEach (value in kv) {
  <li>@value</li>
}
@objEach (k:v in kv) {
  <dt>@k</dt>
  <dd>@v</dd>
}
#### conditions
```
@if (condition) {
  <span>Yes!!</span>
}

@if (condition) {
  <span>Yes!!</span>
} else {
  <span>Ooops..</span>
}
```

### function defination add calling
#### defination
```
@func sayHello(name) {
  <span>Hello, <strong>@name</strong>!</span>
}<commit_msg>fix doc bugs<commit_after># raze-tpl
A js template engine with syntax like [Microsoft Razor Render Engine](https://github.com/aspnet/Razor)

## how to use
### build
`make`

### use
```
var raze = require('./index');

var tpl = fs.readFileSync(filename, 'utf-8');

var render = raze(tpl, {
  safe: false // true to add try/catch to variables accessing
});

var html = render(data);
```

## test and see the demo of syntax/features
* `node test.js`
* see `tpls/template.html` and `tpls/template.out.html`

## syntax and fetures

### variable outputing
#### implicit
```
<span>@some_variable[index]</span>
```
#### explicit
```
<span>@(some_variable[index])</span>
```
#### no html escaping
```
<span@(-some_variable[index])</span>
```
#### filtering
```
<span>@(some_variable[index] | replace(/lorem/ig, '>>$0<<')</span>
```

### flow control
#### loop on array
```
@each (value in arr) {
  <li>@value</li>
}
@each (index:value in arr) {
  <li>No.@index of arr is @value</li>
}
```
#### loop on kv-obj
```
@objEach (value in kv) {
  <li>@value</li>
}
@objEach (k:v in kv) {
  <dt>@k</dt>
  <dd>@v</dd>
}
```
#### conditions
```
@if (condition) {
  <span>Yes!!</span>
}

@if (condition) {
  <span>Yes!!</span>
} else {
  <span>Ooops..</span>
}
```

### function defination add calling
#### defination
```
@func sayHello(name) {
  <span>Hello, <strong>@name</strong>!</span>
}
{'fraction_non_alphanumeric': 0.2353155782561109, 'fraction_numerical': 0.001459321415541773, 'mean_word_length': 4.4189723320158105, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 61, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1101862', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1053, 'n_words': 246}