summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.html62
-rw-r--r--_template/default.html6
-rw-r--r--block_helpers.html40
-rw-r--r--builtin_helpers.html40
-rw-r--r--demo/SafeString.html56
-rw-r--r--demo/demo.html25
-rw-r--r--demo/execution-1.html (renamed from demo/index-1.html)17
-rw-r--r--execution.html62
-rw-r--r--expressions.html6
-rw-r--r--gulpfile.js2
-rw-r--r--index.html251
-rw-r--r--posts/block_helpers.md19
-rw-r--r--posts/builtin_helpers.md19
-rw-r--r--posts/demo/SafeString.md34
-rw-r--r--posts/demo/demo.md27
-rw-r--r--posts/demo/execution-1.md (renamed from posts/demo/index-1.md)15
-rw-r--r--posts/execution.md54
-rw-r--r--posts/index.md370
-rw-r--r--posts/precompilation.md19
-rw-r--r--posts/reference.md19
-rw-r--r--precompilation.html40
-rw-r--r--reference.html40
-rw-r--r--static/css/demo.css3
-rwxr-xr-xstatic/images/favicon.png (renamed from images/favicon.png)bin550 -> 550 bytes
-rw-r--r--static/images/forkme_right_darkblue_121621.pngbin0 -> 7791 bytes
-rwxr-xr-xstatic/images/handlebars-devswag.png (renamed from images/handlebars-devswag.png)bin30323 -> 30323 bytes
-rwxr-xr-xstatic/images/handlebars-mark.png (renamed from images/handlebars-mark.png)bin46649 -> 46649 bytes
-rwxr-xr-xstatic/images/handlebars_logo.png (renamed from images/handlebars_logo.png)bin25946 -> 25946 bytes
-rwxr-xr-xstatic/images/noise.png (renamed from images/noise.png)bin12873 -> 12873 bytes
-rwxr-xr-xstatic/stylesheets/application.css12
-rw-r--r--static/stylesheets/site.css11
31 files changed, 1164 insertions, 85 deletions
diff --git a/README.html b/README.html
new file mode 100644
index 0000000..f91a3ad
--- /dev/null
+++ b/README.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Handlebars 中文网:轻逻辑语义化的模板引擎</title>
+ <meta charset="UTF-8">
+ <link href="static/stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/sunburst.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/site.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/images/favicon.png" rel="shortcut icon" type="image/png" />
+ </head>
+ <body>
+ <div id="body">
+ <div id="header">
+ <a href="index.html">
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
+ </a>
+ </div>
+ <div id="contents">
+ <a href="http://www.devswag.com/collections/handlebars" id="callout">
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
+ </a>
+ <h1><a href="http://www.handlebarsjs.org/" target="_blank">Handlebars &#x4E2D;&#x6587;&#x7F51;</a></h1>
+<p><a href="http://www.handlebarsjs.org" target="_blank"><img src="https://cloud.githubusercontent.com/assets/3949015/7113820/4d7c487a-e20a-11e4-9335-53552a711137.jpg"></a></p>
+<p><a href="http://handlebarsjs.com/" target="_blank">handlebras</a> &#x5B98;&#x65B9;&#x6587;&#x6863;&#x7684;&#x4E2D;&#x6587;&#x7248;</p>
+<ul>
+<li>&#x4E2D;&#x6587;&#x7248;&#xFF1A;<a href="http://www.handlebarsjs.org/" target="_blank">http://www.handlebarsjs.org</a></li>
+<li>&#x82F1;&#x6587;&#x7248;&#xFF1A;<a href="http://www.handlebarsjs.com/" target="_blank">http://www.handlebarsjs.com</a></li>
+</ul>
+<h2>&#x76F4;&#x63A5;&#x63D0;&#x4EA4; <a href="https://github.com/nimojs/handlebarsjs.org/issues" target="_blank">issues</a> &#x62A5;&#x544A;&#x7FFB;&#x8BD1;&#x9519;&#x8BEF;</h2>
+<p>&#x6253;&#x5F00; <a href="https://github.com/nimojs/handlebarsjs.org/issues/new" target="_blank">issues</a> &#xFF0C;&#x586B;&#x5199;&#x7FFB;&#x8BD1;&#x9519;&#x8BEF;&#x5BF9;&#x5E94;&#x7684; URL &#x5730;&#x5740;&#x3001;&#x9519;&#x8BEF;&#x6587;&#x5B57;&#x3001;&#x6B63;&#x786E;&#x6587;&#x5B57;&#xFF0C;&#x539F;&#x56E0;&#x3002;</p>
+<h2>&#x4F7F;&#x7528; gulp &#x53C2;&#x4E0E;&#x7F16;&#x8F91;</h2>
+<ol>
+<li>Fork &#x6B64;&#x9879;&#x76EE;</li>
+<li>&#x4F7F;&#x7528; Github Clone &#x5230;&#x672C;&#x5730;</li>
+<li>&#x6253;&#x5F00;&#x547D;&#x4EE4;&#x884C;/&#x7EC8;&#x7AEF;</li>
+<li>&#x8DF3;&#x8F6C;&#x81F3;&#x5BF9;&#x5E94;&#x76EE;&#x5F55;</li>
+<li>&#x547D;&#x4EE4;&#x884C;&#x8F93;&#x5165; <code>npm install</code></li>
+<li>&#x8F93;&#x5165; <code>gulp</code> &#x56DE;&#x8F66;</li>
+<li>&#x5F00;&#x59CB;&#x76D1;&#x63A7; <code>/post/**/*.md</code> &#x6587;&#x4EF6;&#x4FEE;&#x6539;&#xFF0C;&#x5F53; <code>*.md</code> &#x6587;&#x4EF6;&#x88AB;&#x4FEE;&#x6539;&#x65F6;&#xFF0C;&#x5C06;&#x81EA;&#x52A8;&#x540C;&#x6B65; &#x5BF9;&#x5E94;&#x7684; <code>/**/*.html</code> &#x6587;&#x4EF6;&#x3002;</li>
+</ol>
+<p>&#x4FEE;&#x6539;&#x5B8C;&#x6210;&#x540E;&#x4F7F;&#x7528; github &#x53D1;&#x9001; pull requests</p>
+<h3>HTML &#x7279;&#x6B8A;&#x5904;&#x7406;</h3>
+<p>&#x56E0;&#x4E3A;&#x5B98;&#x65B9;&#x82F1;&#x6587;&#x6587;&#x6863;&#x4E2D;&#x5939;&#x6742;&#x7740;&#x4E00;&#x4E9B;&#x5E26; class &#x7684; <code>&lt;div&gt;</code> &#x6240;&#x4EE5;&#x901A;&#x8FC7; replace &#x505A;&#x4E86;&#x4E00;&#x4E2A;&#x66FF;&#x6362;&#x3002;</p>
+<pre><code class="lang-html"><span class="hljs-comment">&lt;!---&lt;div class=&quot;bullet&quot;&gt;--&gt;</span>
+
+Handlebars &#x6A21;&#x677F;&#x770B;&#x8D77;&#x6765;&#x5F88;&#x50CF; HTML &#xFF0C;Handlebars &#x8868;&#x8FBE;&#x5F0F;&#x5D4C;&#x5165;&#x5728; HTML &#x4E2D;&#x3002;
+</code></pre>
+<pre><code class="lang-js">html = html.replace(/<span class="hljs-comment">&lt;!---([^-]+)--&gt;</span>/g,&apos;$1&apos;)
+</code></pre>
+<p>&#x53EF;&#x67E5;&#x770B; <a href="https://github.com/nimojs/handlebarsjs.org/edit/master/posts/index.html" target="_blank">/posts/index.md</a> &#x7684;&#x6E90;&#x7801;&#x4EE5;&#x7406;&#x89E3; <code>&lt;!---&lt;tag&gt;--&gt;</code> &#x7684;&#x7528;&#x6CD5;&#x3002;</p>
+
+ <a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
+ 发现翻译错误?告诉我们。
+ </a>
+ </div>
+ </div>
+ <div id="credits"></div>
+ <a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
+ </a>
+ </body>
+</html>
diff --git a/_template/default.html b/_template/default.html
index cee1cec..a00d9da 100644
--- a/_template/default.html
+++ b/_template/default.html
@@ -12,12 +12,12 @@
<div id="body">
<div id="header">
<a href="index.html">
- <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="images/handlebars_logo.png"/>
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
</a>
</div>
<div id="contents">
<a href="http://www.devswag.com/collections/handlebars" id="callout">
- <img alt="Buy Handlebars swag on DevSwag!" src="images/handlebars-devswag.png"/>
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
</a>
{{content}}
<a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
@@ -27,7 +27,7 @@
</div>
<div id="credits"></div>
<a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
- <img alt="Fork me on GitHub" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" />
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
</a>
</body>
</html>
diff --git a/block_helpers.html b/block_helpers.html
new file mode 100644
index 0000000..e4c428f
--- /dev/null
+++ b/block_helpers.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Handlebars 中文网:轻逻辑语义化的模板引擎</title>
+ <meta charset="UTF-8">
+ <link href="static/stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/sunburst.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/site.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/images/favicon.png" rel="shortcut icon" type="image/png" />
+ </head>
+ <body>
+ <div id="body">
+ <div id="header">
+ <a href="index.html">
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
+ </a>
+ </div>
+ <div id="contents">
+ <a href="http://www.devswag.com/collections/handlebars" id="callout">
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
+ </a>
+
+<div id="intro">
+
+&#x6B63;&#x5728;&#x7FFB;&#x8BD1;&#x4E2D;... &#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE; <a href="https://github.com/nimojs/handlebarsjs.org/" target="_blank">https://github.com/nimojs/handlebarsjs.org/</a> &#x53C2;&#x4E0E;&#x7FFB;&#x8BD1;&#x5DE5;&#x4F5C;
+
+</div>
+
+<!-- End .contents-->
+ <a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
+ 发现翻译错误?告诉我们。
+ </a>
+ </div>
+ </div>
+ <div id="credits"></div>
+ <a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
+ </a>
+ </body>
+</html>
diff --git a/builtin_helpers.html b/builtin_helpers.html
new file mode 100644
index 0000000..e4c428f
--- /dev/null
+++ b/builtin_helpers.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Handlebars 中文网:轻逻辑语义化的模板引擎</title>
+ <meta charset="UTF-8">
+ <link href="static/stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/sunburst.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/site.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/images/favicon.png" rel="shortcut icon" type="image/png" />
+ </head>
+ <body>
+ <div id="body">
+ <div id="header">
+ <a href="index.html">
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
+ </a>
+ </div>
+ <div id="contents">
+ <a href="http://www.devswag.com/collections/handlebars" id="callout">
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
+ </a>
+
+<div id="intro">
+
+&#x6B63;&#x5728;&#x7FFB;&#x8BD1;&#x4E2D;... &#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE; <a href="https://github.com/nimojs/handlebarsjs.org/" target="_blank">https://github.com/nimojs/handlebarsjs.org/</a> &#x53C2;&#x4E0E;&#x7FFB;&#x8BD1;&#x5DE5;&#x4F5C;
+
+</div>
+
+<!-- End .contents-->
+ <a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
+ 发现翻译错误?告诉我们。
+ </a>
+ </div>
+ </div>
+ <div id="credits"></div>
+ <a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
+ </a>
+ </body>
+</html>
diff --git a/demo/SafeString.html b/demo/SafeString.html
new file mode 100644
index 0000000..64d1f54
--- /dev/null
+++ b/demo/SafeString.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Handlebars 中文网:{ HTML 转义配合 SafeString }</title>
+ <link rel="stylesheet" href="../static/css/demo.css">
+ <script src="../static/js/jquery-1.11.1.min.js"></script>
+ <script src="../static/js/handlebars-v3.0.0.js"></script>
+ <script src="../static/js/demo.js"></script>
+</head>
+<body>
+ <div class="ui-header">
+ <h1 class="ui-header-title">
+ <a href="../index.html" class="ui-header-tip">Handlebars 中文网:</a>{ HTML 转义配合 SafeString }
+ <span class="ui-header-more">
+ <iframe src="http://ghbtns.com/github-btn.html?user=nimojs&repo=handlebarsjs.org&type=watch&count=true&size=large"
+ allowtransparency="true" frameborder="0" scrolling="0" width="131" height="30"></iframe>
+ </span>
+ </h1>
+ </div>
+ <div class="ui-box"><!-- ui-box Start -->
+ 建议将此页面保存至本地修改相关代码以帮助理解,与本示例相关的文档:<a href="../index.html#SafeString">HTML 转义配合 SafeString</a>
+
+<!-- 模板 -->
+<script class="show" id="source" type="text/x-handlebars-template">
+{{{link "<em>html</em>" "http://www.handlebarsjs.org"}}}
+</script>
+
+<!-- 数据 -->
+<script class="show json-format-error" id="data" type="text/json">
+
+</script>
+
+<!-- helper实现 -->
+<script class="show" id="helper">
+Handlebars.registerHelper('link', function(text, url) {
+ // 将下行 text = ... 注释以查看未作安全性转义导致的文字倾斜效果
+ text = Handlebars.Utils.escapeExpression(text);
+ url = Handlebars.Utils.escapeExpression(url);
+
+ var result = '<a href="' + url + '">' + text + '</a>';
+
+ return new Handlebars.SafeString(result);
+});
+</script>
+<!-- 渲染结果字符 -->
+<div class="expandingArea">
+ <textarea class="show" id="result"></textarea>
+ <pre id="expandingPre"><span></span><br></pre>
+</div>
+
+<div class="ui-dom" id="dom"></div>
+ </div><!-- ui-box End -->
+ <div class="ui-error" id="showerror"></div>
+</body>
+</html> \ No newline at end of file
diff --git a/demo/demo.html b/demo/demo.html
index 603a7ac..03b3760 100644
--- a/demo/demo.html
+++ b/demo/demo.html
@@ -23,27 +23,32 @@
<!-- 模板 -->
<script class="show" id="source" type="text/x-handlebars-template">
-{{{link "See more..." story.url}}}
+{{#nimo}}
+{{.}} {{root.a.b.c}}
+{{/nimo}}
</script>
<!-- 数据 -->
<script class="show json-format-error" id="data" type="text/json">
{
- "story": {
- "url": "http://www.handlebarsjs.org"
- }
+ "a":{
+ "b":{
+ "c":"cccc"
+ }
+ },
+ "nimo": [
+ 1
+ ,
+ 2
+ ]
}
</script>
<!-- helper实现 -->
<script class="show" id="helper">
-Handlebars.registerHelper('link', function(text, url) {
- url = Handlebars.escapeExpression(url);
- text = Handlebars.escapeExpression(text);
+Handlebars.registerHelper('helper-name', function(obj) {
+ return 'output'
- return new Handlebars.SafeString(
- "<a href='" + url + "'>" + text + "</a>"
- );
});
</script>
<!-- 渲染结果字符 -->
diff --git a/demo/index-1.html b/demo/execution-1.html
index ec6eab3..c5f2147 100644
--- a/demo/index-1.html
+++ b/demo/execution-1.html
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
- <title>Handlebars 中文网:{ Handlebars 中文网:轻逻辑语义化的模板引擎 }</title>
+ <title>Handlebars 中文网:{ Handlebars 执行渲染 }</title>
<link rel="stylesheet" href="../static/css/demo.css">
<script src="../static/js/jquery-1.11.1.min.js"></script>
<script src="../static/js/handlebars-v3.0.0.js"></script>
@@ -11,7 +11,7 @@
<body>
<div class="ui-header">
<h1 class="ui-header-title">
- <a href="../index.html" class="ui-header-tip">Handlebars 中文网:</a>{ Handlebars 中文网:轻逻辑语义化的模板引擎 }
+ <a href="../index.html" class="ui-header-tip">Handlebars 中文网:</a>{ Handlebars 执行渲染 }
<span class="ui-header-more">
<iframe src="http://ghbtns.com/github-btn.html?user=nimojs&repo=handlebarsjs.org&type=watch&count=true&size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="131" height="30"></iframe>
@@ -40,19 +40,22 @@ var template = Handlebars.compile(source);
<script class="show">
// 数据
var data = {
- "title": "Handlebars 中文网",
- "body": "用 Handlebars 抛弃低效率的 HTML 拼接吧!"
+ title: "My New Post",
+ body: "This is my first post!"
}
// 渲染
$(function () {
var html = template(data);
$("#result,#dom").html(html);
-
- // 通过 pre 让 textarea 高度自适应,与 Handlebars 无关
- $("#expandingPre").html(Handlebars.escapeExpression(html));
})
</script>
+<style>
+#expandingPre{
+ height: 200px;
+}
+</style>
+
<!-- 渲染结果字符 -->
<div class="expandingArea">
diff --git a/execution.html b/execution.html
new file mode 100644
index 0000000..11e7aa6
--- /dev/null
+++ b/execution.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Handlebars 中文网:轻逻辑语义化的模板引擎</title>
+ <meta charset="UTF-8">
+ <link href="static/stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/sunburst.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/site.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/images/favicon.png" rel="shortcut icon" type="image/png" />
+ </head>
+ <body>
+ <div id="body">
+ <div id="header">
+ <a href="index.html">
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
+ </a>
+ </div>
+ <div id="contents">
+ <a href="http://www.devswag.com/collections/handlebars" id="callout">
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
+ </a>
+
+<div id="intro">
+<p>&#x4F20;&#x5165;&#x6570;&#x636E;&#xFF0C;&#x6267;&#x884C; Handlebars &#x8FD4;&#x56DE; &#x6E32;&#x67D3;&#x540E;&#x7684; HTML&#x3002;</p>
+<pre><code class="lang-html"><span class="hljs-keyword">var</span> source = $(<span class="hljs-string">&quot;#entry-template&quot;</span>).html();
+<span class="hljs-keyword">var</span> <span class="hljs-keyword">template</span> = <span class="hljs-type">Handlebars</span>.compile(source);
+
+<span class="hljs-keyword">var</span> context = {title: <span class="hljs-string">&quot;My New Post&quot;</span>, body: <span class="hljs-string">&quot;This is my first post!&quot;</span>}
+<span class="hljs-keyword">var</span> html = <span class="hljs-keyword">template</span>(context);
+</code></pre>
+<p>&#x6E32;&#x67D3;&#x7ED3;&#x679C;</p>
+<pre><code class="lang-html">&lt;<span class="hljs-keyword">div</span> <span class="hljs-type">class</span>=<span class="hljs-string">&quot;entry&quot;</span>&gt;
+ &lt;h1&gt;My New Post&lt;/h1&gt;
+ &lt;<span class="hljs-keyword">div</span> <span class="hljs-type">class</span>=<span class="hljs-string">&quot;body&quot;</span>&gt;
+ This <span class="hljs-keyword">is</span> <span class="hljs-keyword">my</span> <span class="hljs-keyword">first</span> post!
+ &lt;/<span class="hljs-keyword">div</span>&gt;
+&lt;/<span class="hljs-keyword">div</span>&gt;
+</code></pre>
+<p><a href="demo/execution-1.html" target="_blank">&#x793A;&#x4F8B;</a></p>
+</div>
+<h2>&#x9009;&#x9879;</h2>
+<p>&#x8FD9;&#x91CC;&#x7684; <code>template()</code> &#x5141;&#x8BB8;&#x4F20;&#x5165;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F5C;&#x4E3A;&#x9009;&#x9879; </p>
+<p>The template function can be passed an options object as the second parameter which allows for customization:</p>
+<ul>
+<li><code>data</code> Pass in an object to define custom <code>@variable</code> private variables.</li>
+<li><code>helpers</code> Pass in to provide custom helpers in addition to the globally defined helpers.
+Values defined in this object will replace any values defined in the global object for the duration of the template execution.</li>
+<li><code>partials</code> Pass in to provide custom partials in addition to the globally defined partials.
+Values defined in this object will replace any values defined in the global object for the duration of the template execution.</li>
+</ul>
+<!-- End .contents-->
+ <a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
+ 发现翻译错误?告诉我们。
+ </a>
+ </div>
+ </div>
+ <div id="credits"></div>
+ <a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
+ </a>
+ </body>
+</html>
diff --git a/expressions.html b/expressions.html
index 4f61a54..48c3058 100644
--- a/expressions.html
+++ b/expressions.html
@@ -12,12 +12,12 @@
<div id="body">
<div id="header">
<a href="index.html">
- <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="images/handlebars_logo.png"/>
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
</a>
</div>
<div id="contents">
<a href="http://www.devswag.com/collections/handlebars" id="callout">
- <img alt="Buy Handlebars swag on DevSwag!" src="images/handlebars-devswag.png"/>
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
</a>
<div id="intro">
@@ -246,7 +246,7 @@
</div>
<div id="credits"></div>
<a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
- <img alt="Fork me on GitHub" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" />
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
</a>
</body>
</html>
diff --git a/gulpfile.js b/gulpfile.js
index ba7b9d6..c6f3904 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -98,8 +98,8 @@ var compileMD = function (paths) {
html = html.replace(/(href=['"][^"']+\.)md(['"])/g,'$1html$2')
// 将 <!-- #hash_demo --> 转换为锚记 <a href="#hash_demo" name="hash_demo"></a>
// oHash 用于防止 hash 重复
- // 将 <!---<dic class="contents">--> 替换为 <dic class="contents"> (因为官方文档中存在一些带 class 的 div,此处需要兼容官方文档样式)
html = html.replace(/<!---([^-]+)-->/g,'$1')
+ // 将 <!---<div class="contents">--> 替换为 <div class="contents"> (因为官方文档中存在一些带 class 的 div,此处需要兼容官方文档样式)
var oHash = {}
html = html.replace(/<!--\s*#([^\s*]+)\s*-->/g, function () {
var hash = arguments[1];
diff --git a/index.html b/index.html
index ad8cf1c..e50232e 100644
--- a/index.html
+++ b/index.html
@@ -12,12 +12,12 @@
<div id="body">
<div id="header">
<a href="index.html">
- <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="images/handlebars_logo.png"/>
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
</a>
</div>
<div id="contents">
<a href="http://www.devswag.com/collections/handlebars" id="callout">
- <img alt="Buy Handlebars swag on DevSwag!" src="images/handlebars-devswag.png"/>
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
</a>
<div id="intro">
@@ -26,10 +26,8 @@
<p></p></div>
<a class="download" href="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v3.0.1.js" target="_blank">Download: 3.0.1</a>
<a class="download-runtime" href="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.runtime-v3.0.1.js" target="_blank">Download: runtime-3.0.1</a><p></p>
-<h2>Getting Started</h2>
-<!-- Start .contents-->
-<dic class="contents">
-<div class="bullet">
+<h2>&#x5FEB;&#x901F;&#x5165;&#x95E8;</h2>
+<dic class="contents"><!-- Start .contents-->
<p>Handlebars &#x6A21;&#x677F;&#x770B;&#x8D77;&#x6765;&#x5F88;&#x50CF; HTML &#xFF0C;Handlebars &#x8868;&#x8FBE;&#x5F0F;&#x5D4C;&#x5165;&#x5728; HTML &#x4E2D;&#x3002;</p>
<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;entry&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">title</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
@@ -39,10 +37,8 @@
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
</code></pre>
<p>Handlebars &#x8868;&#x8FBE;&#x5F0F;&#x4EE5; <code>{{</code>&#x5C5E;&#x6027;&#x540D;<code>}}</code> &#x7684;&#x65B9;&#x5F0F;&#x63D2;&#x5165;&#x6570;&#x636E;&#x3002;</p>
-<p><a href="expressions.html" class="more-info" target="_blank">&#x4E86;&#x89E3;&#x66F4;&#x591A;&#xFF1A;&#x8868;&#x8FBE;&#x5F0F;</a></p>
-</div>
-<p><a name="index-1.html" target="_blank"></a></p>
-<div class="bullet">
+<p><a href="expressions.html" class="more-info" target="_blank">&#x9AD8;&#x7EA7;&#x6559;&#x7A0B;&#xFF1A;&#x8868;&#x8FBE;&#x5F0F;</a></p>
+<hr>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x5728; HTML &#x4E2D;&#x4F7F;&#x7528; <code>&lt;script&gt;</code> &#x6807;&#x7B7E;&#x5B58;&#x653E;&#x6A21;&#x677F;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">&quot;entry-template&quot;</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/x-handlebars-template&quot;</span>&gt;</span><span class="handlebars"><span class="xml">
<span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;entry&quot;</span>&gt;</span>
@@ -53,18 +49,237 @@
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
</span></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
</code></pre>
-</div>
-<div class="bullet">
+<hr>
<p>&#x5728; JavaScript &#x4E2D;&#x83B7;&#x53D6; <code>&lt;scrit&gt;</code> &#x4E2D;&#x7684;&#x6A21;&#x677F;&#x5E76;&#x7F16;&#x8BD1;&#x6A21;&#x677F;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> source = $(<span class="hljs-string">&quot;#entry-template&quot;</span>).html();
<span class="hljs-keyword">var</span> <span class="hljs-keyword">template</span> = <span class="hljs-type">Handlebars</span>.compile(source);
</code></pre>
-<p><a href="demo/index-1.html" target="_blank">&#x793A;&#x4F8B;</a></p>
+<div class="translator">
+<p>&#x5EFA;&#x8BAE;&#x521D;&#x5B66;&#x8005;&#x8DF3;&#x8FC7;&#x9884;&#x7F16;&#x8BD1;&#x7AE0;&#x8282;
+</div></p>
<p>&#x8FD8;&#x53EF;&#x4EE5;&#x9884;&#x7F16;&#x8BD1;&#x4F60;&#x7684;&#x6A21;&#x677F;&#x3002;&#x9884;&#x7F16;&#x8BD1;&#x540E;&#x7684;&#x6A21;&#x677F;&#x53EA;&#x9700;&#x4F7F;&#x7528; <a href="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.runtime-v3.0.0.js" target="_blank">handlebars.runtime.js</a> &#x6E32;&#x67D3;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x63D0;&#x9AD8;&#x6027;&#x80FD;&#x5E76;&#x51CF;&#x5C11;&#x6587;&#x4EF6;&#x5927;&#x5C0F;&#x3002;&#x5728;&#x79FB;&#x52A8;&#x8BBE;&#x5907;&#x4E2D;&#x8FD9;&#x6837;&#x505A;&#x975E;&#x5E38;&#x6709;&#x610F;&#x4E49;&#xFF08;&#x56E0;&#x4E3A;&#x79FB;&#x52A8;&#x8BBE;&#x5907;&#x7684;&#x6027;&#x80FD;&#x548C;&#x7F51;&#x7EDC;&#x72B6;&#x6001;&#x90FD;&#x6CA1;&#x6709;PC&#x597D;&#xFF09;&#x3002;</p>
-<p><a href="#" class="more-info" target="_blank">&#x4E86;&#x89E3;&#x66F4;&#x591A;&#xFF1A;&#x9884;&#x7F16;&#x8BD1;</a></p>
-</div>
-</div>
-<!-- End .contents-->
+<p><a href="precompilation.html" class="more-info" target="_blank">&#x9AD8;&#x7EA7;&#x6559;&#x7A0B;&#xFF1A;&#x9884;&#x7F16;&#x8BD1;</a></p>
+<hr>
+<p>&#x4F20;&#x5165;&#x6570;&#x636E;&#xFF0C;&#x6267;&#x884C; Handlebars &#x8FD4;&#x56DE; &#x6E32;&#x67D3;&#x540E;&#x7684; HTML&#x3002;</p>
+<pre><code class="lang-js"><span class="hljs-keyword">var</span> source = $(<span class="hljs-string">&quot;#entry-template&quot;</span>).html();
+<span class="hljs-keyword">var</span> <span class="hljs-keyword">template</span> = <span class="hljs-type">Handlebars</span>.compile(source);
+
+<span class="hljs-keyword">var</span> context = {title: <span class="hljs-string">&quot;My New Post&quot;</span>, body: <span class="hljs-string">&quot;This is my first post!&quot;</span>};
+<span class="hljs-keyword">var</span> html = <span class="hljs-keyword">template</span>(context);
+</code></pre>
+<p>&#x6E32;&#x67D3;&#x7ED3;&#x679C;</p>
+<pre><code class="lang-html">&lt;<span class="hljs-keyword">div</span> <span class="hljs-type">class</span>=<span class="hljs-string">&quot;entry&quot;</span>&gt;
+ &lt;h1&gt;My New Post&lt;/h1&gt;
+ &lt;<span class="hljs-keyword">div</span> <span class="hljs-type">class</span>=<span class="hljs-string">&quot;body&quot;</span>&gt;
+ This <span class="hljs-keyword">is</span> <span class="hljs-keyword">my</span> <span class="hljs-keyword">first</span> post!
+ &lt;/<span class="hljs-keyword">div</span>&gt;
+&lt;/<span class="hljs-keyword">div</span>&gt;
+</code></pre>
+<p><a href="demo/execution-1.html" target="_blank">&#x793A;&#x4F8B;</a></p>
+<p><a href="execution.html" class="more-info" target="_blank">&#x9AD8;&#x7EA7;&#x6559;&#x7A0B;: &#x6267;&#x884C;</a></p>
+<h2>HTML &#x8F6C;&#x4E49;</h2>
+<p>&#x9047;&#x5230; HTML&#x6807;&#x7B7E;&#x65F6; Handlebars &#x4F1A;&#x8FD4;&#x56DE;&#x8F6C;&#x4E49;&#x540E;&#x7684; HTML&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x4E0D;&#x5E0C;&#x671B;&#x88AB;&#x8F6C;&#x4E49;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>{{{</code></p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;entry&quot;</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">title</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;body&quot;</span>&gt;</span>
+ </span><span class="hljs-expression">{{{<span class="hljs-variable">body</span>}}</span><span class="xml">}
+ <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
+</code></pre>
+<p>&#x6E32;&#x67D3;&#x6570;&#x636E;&#xFF1A;</p>
+<pre><code class="lang-js">{
+ <span class="hljs-attribute">title</span>: <span class="hljs-string">&quot;All about &lt;p&gt; Tags&quot;</span>,
+ <span class="hljs-attribute">body</span>: <span class="hljs-string">&quot;&lt;p&gt;This is a post about &amp;lt;p&amp;gt; tags&lt;/p&gt;&quot;</span>
+}
+</code></pre>
+<p>&#x6E32;&#x67D3;&#x7ED3;&#x679C;&#xFF1A;</p>
+<pre><code class="lang-html">&lt;<span class="hljs-keyword">div</span> <span class="hljs-type">class</span>=<span class="hljs-string">&quot;entry&quot;</span>&gt;
+ &lt;h1&gt;All About &amp;lt;p&amp;gt; Tags&lt;/h1&gt;
+ &lt;<span class="hljs-keyword">div</span> <span class="hljs-type">class</span>=<span class="hljs-string">&quot;body&quot;</span>&gt;
+ &lt;p&gt;This <span class="hljs-keyword">is</span> a post <span class="hljs-keyword">about</span> &amp;lt;p&amp;gt; tags&lt;/p&gt;
+ &lt;/<span class="hljs-keyword">div</span>&gt;
+&lt;/<span class="hljs-keyword">div</span>&gt;
+</code></pre>
+<p><a href="#SafeString" name="SafeString" target="_blank"></a></p>
+<p>Handlebars &#x4E0D;&#x4F1A;&#x8F6C;&#x4E49; <code>Handlebars.SafeString</code> &#x3002;&#x5982;&#x679C;&#x4F60;&#x81EA;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A; helper &#x8FD4;&#x56DE; HTML &#x4EE3;&#x7801;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x8FD4;&#x56DE; <code>new Handlebars.SafeString(result)</code> &#xFF0C;&#x90A3;&#x4E48;&#x4F60;&#x9700;&#x8981;&#x624B;&#x52A8;&#x5BF9;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x8F6C;&#x4E49;</p>
+<pre><code class="lang-js"><span class="hljs-type">Handlebars</span>.registerHelper(&apos;link&apos;, function(text, url) {
+ text = <span class="hljs-type">Handlebars</span>.<span class="hljs-type">Utils</span>.escapeExpression(text);
+ url = <span class="hljs-type">Handlebars</span>.<span class="hljs-type">Utils</span>.escapeExpression(url);
+
+ <span class="hljs-keyword">var</span> <span class="hljs-literal">result</span> = &apos;&lt;a href=<span class="hljs-string">&quot;&apos; + url + &apos;&quot;</span>&gt;&apos; + text + &apos;&lt;/a&gt;&apos;;
+
+ <span class="hljs-keyword">return</span> new <span class="hljs-type">Handlebars</span>.<span class="hljs-type">SafeString</span>(<span class="hljs-literal">result</span>);
+});
+</code></pre>
+<p><code>new Handlebars.SafeString()</code> &#x4F1A;&#x6807;&#x8BC6;&#x4F20;&#x5165;&#x53C2;&#x6570;&#x662F;&#x201C;&#x5B89;&#x5168;&#x7684;&#x201D;&#xFF0C;&#x6240;&#x4EE5;&#x5373;&#x4F7F;&#x4F60;&#x4E0D;&#x4F7F;&#x7528; <code>{{{</code> &#x3002;Handlebars &#x4E5F;&#x4E0D;&#x4F1A;&#x8F6C;&#x4E49;&#x3002;</p>
+<p><a href="demo/SafeString.html" target="_blank">&#x793A;&#x4F8B;</a></p>
+<h2>&#x5757;&#x8868;&#x8FBE;&#x5F0F;</h2>
+<p>&#x5757;&#x8868;&#x8FBE;&#x5F0F;&#x5141;&#x8BB8;&#x4F60;&#x5B9A;&#x4E49;helper&#xFF0C;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#x4E0A;&#x4E0B;&#x6587;&#xFF08;context&#xFF09;&#x8C03;&#x7528;&#x4E00;&#x6BB5;&#x6A21;&#x677F;&#x3002;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x751F;&#x6210;&#x5217;&#x8868;&#x7684;helper&#xFF1A;</p>
+<p>&#x5FEB;&#x8868;&#x8FBE;&#x5F0F;&#x5141;&#x8BB8;&#x4F60;&#x81EA;&#x5B9A;&#x4E49; helper&#xFF0C;&#x4F7F;&#x7528;&#x5F53;&#x524D;&#x4F20;&#x5165;&#x53C2;&#x6570;&#x4F5C;&#x4E3A;&#x4E0A;&#x4E0B;&#x6587;&#x8C03;&#x7528;&#x6A21;&#x677F;&#x3002;</p>
+<p>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;&#x751F;&#x4EA7;&#x5217;&#x8868;&#x7684;&#x5FEB;&#x8868;&#x8FBE;&#x5F0F;</p>
+<pre><code><span class="hljs-collection">{<span class="hljs-collection">{#list people}</span>}</span><span class="hljs-collection">{<span class="hljs-collection">{firstName}</span>}</span> <span class="hljs-collection">{<span class="hljs-collection">{lastName}</span>}</span><span class="hljs-collection">{<span class="hljs-collection">{/list}</span>}</span>
+</code></pre><p>&#x6E32;&#x67D3;&#x6570;&#x636E;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
+<pre><code class="lang-js">{
+<span class="hljs-label"> people:</span> [
+ {<span class="hljs-string">firstName:</span> <span class="hljs-string">&quot;Yehuda&quot;</span>, <span class="hljs-string">lastName:</span> <span class="hljs-string">&quot;Katz&quot;</span>},
+ {<span class="hljs-string">firstName:</span> <span class="hljs-string">&quot;Carl&quot;</span>, <span class="hljs-string">lastName:</span> <span class="hljs-string">&quot;Lerche&quot;</span>},
+ {<span class="hljs-string">firstName:</span> <span class="hljs-string">&quot;Alan&quot;</span>, <span class="hljs-string">lastName:</span> <span class="hljs-string">&quot;Johnson&quot;</span>}
+ ]
+}
+</code></pre>
+<p>we would create a helper named <code>list</code> to generate our HTML list. The helper receives the <code>people</code> as its first parameter, and an options hash as its second parameter. The options hash contains a property named <code>fn</code>, which you can invoke with a context just as you would invoke a normal Handlebars template.</p>
+<pre><code class="lang-js">Handlebars.registerHelper(&apos;<span class="hljs-keyword">list</span>&apos;, function(items, options) {
+ <span class="hljs-keyword">var</span> <span class="hljs-keyword">out</span> = <span class="hljs-string">&quot;&lt;ul&gt;&quot;</span>;
+
+ <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=0, <span class="hljs-keyword">l</span>=items.length; i&lt;<span class="hljs-keyword">l</span>; i++) {
+ <span class="hljs-keyword">out</span> = <span class="hljs-keyword">out</span> + <span class="hljs-string">&quot;&lt;li&gt;&quot;</span> + options.fn(items[i]) + <span class="hljs-string">&quot;&lt;/li&gt;&quot;</span>;
+ }
+
+ <span class="hljs-keyword">return</span> <span class="hljs-keyword">out</span> + <span class="hljs-string">&quot;&lt;/ul&gt;&quot;</span>;
+});
+</code></pre>
+<p>When executed, the template will render:</p>
+<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-title">ul</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">li</span>&gt;</span>Yehuda Katz<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">li</span>&gt;</span>Carl Lerche<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">li</span>&gt;</span>Alan Johnson<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
+<span class="hljs-tag">&lt;/<span class="hljs-title">ul</span>&gt;</span>
+</code></pre>
+<p>Block helpers have more features, such as the ability to create an else section (used, for instance, by the built-in if helper).</p>
+<p>Since the contents of a block helper are escaped when you call <code>options.fn(context)</code>, Handlebars does not escape the results of a block helper. If it did, inner content would be double-escaped!</p>
+<p><a href="block_helpers.html" class="more-info" target="_blank">Learn More: Block Helpers</a></p>
+<h2>Handlebars Paths</h2>
+<p>Handlebars supports simple paths, just like Mustache.</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">name</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span></span>
+</code></pre>
+<p>Handlebars also supports nested paths, making it possible to look up properties nested below the current context.</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;entry&quot;</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">title</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h2</span>&gt;</span>By </span><span class="hljs-expression">{{<span class="hljs-variable">author.name</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">h2</span>&gt;</span>
+
+ <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;body&quot;</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-variable">body</span>}}</span><span class="xml">
+ <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
+</code></pre>
+<p>That template works with this context</p>
+<pre><code>var context = {
+ title: <span class="hljs-string">&quot;My First Blog Post!&quot;</span>,
+ author: {
+ <span class="hljs-property">id</span>: <span class="hljs-number">47</span>,
+ <span class="hljs-property">name</span>: <span class="hljs-string">&quot;Yehuda Katz&quot;</span>
+ },
+ body: <span class="hljs-string">&quot;My first post. Wheeeee!&quot;</span>
+};
+</code></pre><p>This makes it possible to use Handlebars templates with more raw JSON objects.</p>
+<p>Nested handlebars paths can also include <code>../</code> segments, which evaluate their paths against a parent context.</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>Comments<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+
+<span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">&quot;comments&quot;</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-begin-block">#<span class="hljs-keyword">each</span> comments</span>}}</span><span class="xml">
+ <span class="hljs-tag">&lt;<span class="hljs-title">h2</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;/posts/</span></span></span><span class="hljs-expression">{{<span class="hljs-variable">..</span><span class="hljs-end-block">/permalink</span>}}</span><span class="xml"><span class="hljs-tag"><span class="hljs-value">#</span></span></span><span class="hljs-expression">{{<span class="hljs-variable">id</span>}}</span><span class="xml"><span class="hljs-tag"><span class="hljs-value">&quot;</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">title</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">h2</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">div</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">body</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-end-block">/<span class="hljs-keyword">each</span></span>}}</span><span class="xml">
+<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
+</code></pre>
+<p>Even though the link is printed while in the context of a comment, it can still go back to the main context (the post) to retrieve its permalink.</p>
+<p>The <code>../</code> path segment references the parent template scope, not one level up in the context. This is because block helpers can invoke a block with any context, so the notion of &quot;one level up&quot; isn&apos;t particularly meaningful except as a reference to the parent template scope.</p>
+<p>Handlebars also allows for name conflict resolution between helpers and data fields via a this reference:</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">.</span><span class="hljs-end-block">/name</span>}}</span><span class="xml"> or </span><span class="hljs-expression">{{<span class="hljs-variable">this</span><span class="hljs-end-block">/name</span>}}</span><span class="xml"> or </span><span class="hljs-expression">{{<span class="hljs-variable">this.name</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span></span>
+</code></pre>
+<p>Any of the above would cause the <code>name</code> field on the current context to be used rather than a helper of the same name.</p>
+<h2>Template comments with {{!-- --}} or {{! }}.</h2>
+<p>You can use comments in your handlebars code just as you would in your code. Since there is generally some level of logic, this is a good practice.</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;entry&quot;</span>&gt;</span>
+ </span><span class="hljs-expression">{{!<span class="hljs-variable">--</span> <span class="hljs-variable">only</span> <span class="hljs-variable">output</span> <span class="hljs-variable">this</span> <span class="hljs-variable">author</span> <span class="hljs-variable">names</span> <span class="hljs-variable"><span class="hljs-keyword">if</span></span> <span class="hljs-variable">an</span> <span class="hljs-variable">author</span> <span class="hljs-variable">exists</span> <span class="hljs-variable">--</span>}}</span><span class="xml">
+ </span><span class="hljs-expression">{{<span class="hljs-begin-block">#<span class="hljs-keyword">if</span> author</span>}}</span><span class="xml">
+ <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">firstName</span>}}</span><span class="xml"> </span><span class="hljs-expression">{{<span class="hljs-variable">lastName</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-end-block">/<span class="hljs-keyword">if</span></span>}}</span><span class="xml">
+<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
+</code></pre>
+<p>The comments will not be in the resulting output. If you&apos;d like the comments to show up. Just use html comments, and they will be output.</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;entry&quot;</span>&gt;</span>
+ </span><span class="hljs-expression">{{! <span class="hljs-variable">This</span> <span class="hljs-variable">comment</span> <span class="hljs-variable">will</span> <span class="hljs-variable">not</span> <span class="hljs-variable">be</span> <span class="hljs-variable"><span class="hljs-keyword">in</span></span> <span class="hljs-variable">the</span> <span class="hljs-variable">output</span> }}</span><span class="xml">
+ <span class="hljs-comment">&lt;!-- This comment will be in the output --&gt;</span>
+<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
+</code></pre>
+<p>Any comments that must contain <code>}}</code> or other handlebars tokens should use the <code>{{!-- --}}</code> syntax.</p>
+<h2>Helpers</h2>
+<p>Handlebars helpers can be accessed from any context in a template. You can register a helper with the <code>Handlebars.registerHelper</code> method.</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;post&quot;</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>By </span><span class="hljs-expression">{{<span class="hljs-variable">fullName</span> <span class="hljs-variable">author</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;body&quot;</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">body</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>Comments<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-begin-block">#<span class="hljs-keyword">each</span> comments</span>}}</span><span class="xml">
+ <span class="hljs-tag">&lt;<span class="hljs-title">h2</span>&gt;</span>By </span><span class="hljs-expression">{{<span class="hljs-variable">fullName</span> <span class="hljs-variable">author</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">h2</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;body&quot;</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">body</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-end-block">/<span class="hljs-keyword">each</span></span>}}</span><span class="xml">
+<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span></span>
+</code></pre>
+<p>when using this context and helpers:</p>
+<pre><code class="lang-js"><span class="hljs-keyword">var</span> context = {
+ author: {firstName: <span class="hljs-string">&quot;Alan&quot;</span>, lastName: <span class="hljs-string">&quot;Johnson&quot;</span>},
+ body: <span class="hljs-string">&quot;I Love Handlebars&quot;</span>,
+ comments: [{
+ author: {firstName: <span class="hljs-string">&quot;Yehuda&quot;</span>, lastName: <span class="hljs-string">&quot;Katz&quot;</span>},
+ body: <span class="hljs-string">&quot;Me too!&quot;</span>
+ }]
+};
+
+Handlebars.registerHelper(<span class="hljs-string">&apos;fullName&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(person)</span> </span>{
+ <span class="hljs-keyword">return</span> person.firstName + <span class="hljs-string">&quot; &quot;</span> + person.lastName;
+});
+</code></pre>
+<p>results in:</p>
+<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;post&quot;</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>By Alan Johnson<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;body&quot;</span>&gt;</span>I Love Handlebars<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>Comments<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">h2</span>&gt;</span>By Yehuda Katz<span class="hljs-tag">&lt;/<span class="hljs-title">h2</span>&gt;</span>
+ <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;body&quot;</span>&gt;</span>Me Too!<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
+</code></pre>
+<p>Helpers receive the current context as the <code>this</code> context of the function.</p>
+<pre><code class="lang-html"><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">ul</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-begin-block">#<span class="hljs-keyword">each</span> items</span>}}</span><span class="xml">
+ <span class="hljs-tag">&lt;<span class="hljs-title">li</span>&gt;</span></span><span class="hljs-expression">{{<span class="hljs-variable">agree</span>_<span class="hljs-variable">button</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
+ </span><span class="hljs-expression">{{<span class="hljs-end-block">/<span class="hljs-keyword">each</span></span>}}</span><span class="xml">
+<span class="hljs-tag">&lt;/<span class="hljs-title">ul</span>&gt;</span></span>
+</code></pre>
+<p>when using this context and helpers:</p>
+<pre><code class="lang-js">var context = {
+<span class="hljs-label"> items:</span> [
+ {<span class="hljs-string">name:</span> <span class="hljs-string">&quot;Handlebars&quot;</span>, <span class="hljs-string">emotion:</span> <span class="hljs-string">&quot;love&quot;</span>},
+ {<span class="hljs-string">name:</span> <span class="hljs-string">&quot;Mustache&quot;</span>, <span class="hljs-string">emotion:</span> <span class="hljs-string">&quot;enjoy&quot;</span>},
+ {<span class="hljs-string">name:</span> <span class="hljs-string">&quot;Ember&quot;</span>, <span class="hljs-string">emotion:</span> <span class="hljs-string">&quot;want to learn&quot;</span>}
+ ]
+};
+
+Handlebars.registerHelper(<span class="hljs-string">&apos;agree_button&apos;</span>, function() {
+ var emotion = Handlebars.escapeExpression(<span class="hljs-keyword">this</span>.emotion),
+ name = Handlebars.escapeExpression(<span class="hljs-keyword">this</span>.name);
+
+ <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Handlebars.SafeString(
+ <span class="hljs-string">&quot;&lt;button&gt;I agree. I &quot;</span> + emotion + <span class="hljs-string">&quot; &quot;</span> + name + <span class="hljs-string">&quot;&lt;/button&gt;&quot;</span>
+ );
+});
+</code></pre>
+<p>results in:</p>
+<pre><code class="lang-html"><span class="hljs-variable">&lt;ul&gt;</span>
+ <span class="hljs-variable">&lt;li&gt;</span><span class="hljs-variable">&lt;button&gt;</span>I agree. I love Handlebars<span class="hljs-variable">&lt;/button&gt;</span><span class="hljs-variable">&lt;/li&gt;</span>
+ <span class="hljs-variable">&lt;li&gt;</span><span class="hljs-variable">&lt;button&gt;</span>I agree. I enjoy Mustache<span class="hljs-variable">&lt;/button&gt;</span><span class="hljs-variable">&lt;/li&gt;</span>
+ <span class="hljs-variable">&lt;li&gt;</span><span class="hljs-variable">&lt;button&gt;</span>I agree. I want <span class="hljs-keyword">to</span> learn Ember<span class="hljs-variable">&lt;/button&gt;</span><span class="hljs-variable">&lt;/li&gt;</span>
+<span class="hljs-variable">&lt;/ul&gt;</span>
+</code></pre>
+<p>If your helper returns HTML that you do not want escaped, make sure to return a new Handlebars.SafeString.</p>
+<h2>Built-In Helpers</h2>
+<p>Handlebars offers a variety of built-in helpers such as the if conditional and each iterator.</p>
+<p><a href="builtin_helpers.html" class="more-info" target="_blank">Learn More: Built-In Helpers</a></p>
+<h2>API Reference</h2>
+<p>Handlebars offers a variety of APIs and utility methods for applications and helpers.</p>
+<p><a href="reference.html" class="more-info" target="_blank">Learn More: API Reference</a></p>
+<p></div>&lt;!-- End .contents</p>
+
<a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
发现翻译错误?告诉我们。
</a>
@@ -72,7 +287,7 @@
</div>
<div id="credits"></div>
<a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
- <img alt="Fork me on GitHub" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" />
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
</a>
</body>
</html>
diff --git a/posts/block_helpers.md b/posts/block_helpers.md
new file mode 100644
index 0000000..aaaf1f1
--- /dev/null
+++ b/posts/block_helpers.md
@@ -0,0 +1,19 @@
+<!--_PAGEDATA
+{
+ "title": "Handlebars 中文网:轻逻辑语义化的模板引擎",
+ "github":"nimojs/handlebarsjs.org",
+ "githubissuesid": 1,
+ "createData": "2015-04-10",
+ "keywords": "",
+ "description": "轻逻辑语义化的模板引擎",
+ "_template": "default"
+}
+_PAGEDATA-->
+
+<div id="intro">
+
+正在翻译中... ,你可以访问 [https://github.com/nimojs/handlebarsjs.org/](https://github.com/nimojs/handlebarsjs.org/) 参与翻译工作
+
+</div>
+
+<!-- End .contents--> \ No newline at end of file
diff --git a/posts/builtin_helpers.md b/posts/builtin_helpers.md
new file mode 100644
index 0000000..aaaf1f1
--- /dev/null
+++ b/posts/builtin_helpers.md
@@ -0,0 +1,19 @@
+<!--_PAGEDATA
+{
+ "title": "Handlebars 中文网:轻逻辑语义化的模板引擎",
+ "github":"nimojs/handlebarsjs.org",
+ "githubissuesid": 1,
+ "createData": "2015-04-10",
+ "keywords": "",
+ "description": "轻逻辑语义化的模板引擎",
+ "_template": "default"
+}
+_PAGEDATA-->
+
+<div id="intro">
+
+正在翻译中... ,你可以访问 [https://github.com/nimojs/handlebarsjs.org/](https://github.com/nimojs/handlebarsjs.org/) 参与翻译工作
+
+</div>
+
+<!-- End .contents--> \ No newline at end of file
diff --git a/posts/demo/SafeString.md b/posts/demo/SafeString.md
new file mode 100644
index 0000000..a999814
--- /dev/null
+++ b/posts/demo/SafeString.md
@@ -0,0 +1,34 @@
+<!--_PAGEDATA
+{
+ "title": "HTML 转义配合 SafeString",
+ "githubissuesid": 2,
+ "keywords": "js,handlebars,javascript",
+ "description":" Handlebars 中使用 helper 输出链接",
+ "doc_text":"HTML 转义配合 SafeString",
+ "doc_link":"../index.html#SafeString",
+ "_template": "demo"
+}
+_PAGEDATA-->
+
+<!-- 模板 -->
+<script class="show" id="source" type="text/x-handlebars-template" >
+{{{link "<em>html</em>" "http://www.handlebarsjs.org"}}}
+</script>
+
+<!-- 数据 -->
+<script class="show json-format-error" id="data" type="text/json">
+
+</script>
+
+<!-- helper实现 -->
+<script class="show" id="helper">
+Handlebars.registerHelper('link', function(text, url) {
+ // 将下行 text = ... 注释以查看未作安全性转义导致的文字倾斜效果
+ text = Handlebars.Utils.escapeExpression(text);
+ url = Handlebars.Utils.escapeExpression(url);
+
+ var result = '<a href="' + url + '">' + text + '</a>';
+
+ return new Handlebars.SafeString(result);
+});
+</script> \ No newline at end of file
diff --git a/posts/demo/demo.md b/posts/demo/demo.md
index bbb8833..1c7f30f 100644
--- a/posts/demo/demo.md
+++ b/posts/demo/demo.md
@@ -12,26 +12,31 @@ _PAGEDATA-->
<!-- 模板 -->
<script class="show" id="source" type="text/x-handlebars-template" >
-{{{link "See more..." story.url}}}
+{{#nimo}}
+{{.}} {{root.a.b.c}}
+{{/nimo}}
</script>
<!-- 数据 -->
<script class="show json-format-error" id="data" type="text/json">
{
- "story": {
- "url": "http://www.handlebarsjs.org"
- }
+ "a":{
+ "b":{
+ "c":"cccc"
+ }
+ },
+ "nimo": [
+ 1
+ ,
+ 2
+ ]
}
</script>
<!-- helper实现 -->
<script class="show" id="helper">
-Handlebars.registerHelper('link', function(text, url) {
- url = Handlebars.escapeExpression(url);
- text = Handlebars.escapeExpression(text);
-
- return new Handlebars.SafeString(
- "<a href='" + url + "'>" + text + "</a>"
- );
+Handlebars.registerHelper('helper-name', function(obj) {
+ return 'output'
+
});
</script> \ No newline at end of file
diff --git a/posts/demo/index-1.md b/posts/demo/execution-1.md
index 51fd90f..6be175b 100644
--- a/posts/demo/index-1.md
+++ b/posts/demo/execution-1.md
@@ -1,6 +1,6 @@
<!--_PAGEDATA
{
- "title": "Handlebars 中文网:轻逻辑语义化的模板引擎",
+ "title": "Handlebars 执行渲染",
"github":"nimojs/handlebarsjs.org",
"githubissuesid": 1,
"createData": "2015-04-10",
@@ -30,16 +30,19 @@ var template = Handlebars.compile(source);
<script class="show">
// 数据
var data = {
- "title": "Handlebars 中文网",
- "body": "用 Handlebars 抛弃低效率的 HTML 拼接吧!"
+ title: "My New Post",
+ body: "This is my first post!"
}
// 渲染
$(function () {
var html = template(data);
$("#result,#dom").html(html);
-
- // 通过 pre 让 textarea 高度自适应,与 Handlebars 无关
- $("#expandingPre").html(Handlebars.escapeExpression(html));
})
</script>
+<style>
+#expandingPre{
+ height: 200px;
+}
+</style>
+
diff --git a/posts/execution.md b/posts/execution.md
new file mode 100644
index 0000000..fc0ed4d
--- /dev/null
+++ b/posts/execution.md
@@ -0,0 +1,54 @@
+<!--_PAGEDATA
+{
+ "title": "Handlebars 中文网:轻逻辑语义化的模板引擎",
+ "github":"nimojs/handlebarsjs.org",
+ "githubissuesid": 1,
+ "createData": "2015-04-10",
+ "keywords": "",
+ "description": "轻逻辑语义化的模板引擎",
+ "_template": "default"
+}
+_PAGEDATA-->
+
+<!---<div id="intro">-->
+
+传入数据,执行 Handlebars 返回 渲染后的 HTML。
+
+```html
+var source = $("#entry-template").html();
+var template = Handlebars.compile(source);
+
+var context = {title: "My New Post", body: "This is my first post!"}
+var html = template(context);
+```
+渲染结果
+
+```html
+<div class="entry">
+ <h1>My New Post</h1>
+ <div class="body">
+ This is my first post!
+ </div>
+</div>
+```
+
+[示例](demo/execution-1.html)
+
+<!---</div>-->
+
+选项
+-------
+
+这里的 `template()` 允许传入第二个参数作为选项
+
+The template function can be passed an options object as the second parameter which allows for customization:
+
+
+- `data` Pass in an object to define custom `@variable` private variables.
+- `helpers` Pass in to provide custom helpers in addition to the globally defined helpers.
+Values defined in this object will replace any values defined in the global object for the duration of the template execution.
+- `partials` Pass in to provide custom partials in addition to the globally defined partials.
+Values defined in this object will replace any values defined in the global object for the duration of the template execution.
+
+
+<!-- End .contents--> \ No newline at end of file
diff --git a/posts/index.md b/posts/index.md
index 372b7d0..6abb796 100644
--- a/posts/index.md
+++ b/posts/index.md
@@ -19,14 +19,11 @@ Handlebars 兼容 Mustache 模板。你可以在 Handlebars 中直接使用 Must
<a class="download" href="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v3.0.1.js">Download: 3.0.1</a>
<a class="download-runtime" href="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.runtime-v3.0.1.js">Download: runtime-3.0.1</a>
-Getting Started
+快速入门
---------------
-<!-- Start .contents-->
-<!---<dic class="contents">-->
-
-<!---<div class="bullet">-->
-
+<!---<dic class="contents">--><!-- Start .contents-->
+
Handlebars 模板看起来很像 HTML ,Handlebars 表达式嵌入在 HTML 中。
```html
@@ -37,15 +34,12 @@ Handlebars 模板看起来很像 HTML ,Handlebars 表达式嵌入在 HTML 中
</div>
</div>
```
-Handlebars 表达式以 `{{`属性名`}}` 的方式插入数据。
-
-<a href="expressions.md" class="more-info">了解更多:表达式</a>
-<!---</div>-->
+Handlebars 表达式以 `{{`属性名`}}` 的方式插入数据。
-<a name="index-1.html"></a>
+<a href="expressions.md" class="more-info">高级教程:表达式</a>
-<!---<div class="bullet">-->
+---------------------
你可以在 HTML 中使用 `<script>` 标签存放模板
@@ -60,9 +54,7 @@ Handlebars 表达式以 `{{`属性名`}}` 的方式插入数据。
</script>
```
-<!---</div>-->
-
-<!---<div class="bullet">-->
+---------------------
在 JavaScript 中获取 `<scrit>` 中的模板并编译模板
@@ -71,13 +63,351 @@ var source = $("#entry-template").html();
var template = Handlebars.compile(source);
```
-[示例](demo/index-1.html)
+<!---<div class="translator">-->
+建议初学者跳过预编译章节
+<!---</div>-->
还可以预编译你的模板。预编译后的模板只需使用 [handlebars.runtime.js](http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.runtime-v3.0.0.js) 渲染,这样可以提高性能并减少文件大小。在移动设备中这样做非常有意义(因为移动设备的性能和网络状态都没有PC好)。
-<a href="#" class="more-info">了解更多:预编译</a>
-<!---</div>-->
+<a href="precompilation.md" class="more-info">高级教程:预编译</a>
-<!---</div>-->
-<!-- End .contents--> \ No newline at end of file
+---------------------
+
+传入数据,执行 Handlebars 返回 渲染后的 HTML。
+
+```js
+var source = $("#entry-template").html();
+var template = Handlebars.compile(source);
+
+var context = {title: "My New Post", body: "This is my first post!"};
+var html = template(context);
+```
+
+渲染结果
+
+```html
+<div class="entry">
+ <h1>My New Post</h1>
+ <div class="body">
+ This is my first post!
+ </div>
+</div>
+```
+
+[示例](demo/execution-1.html)
+
+<a href="execution.md" class="more-info">高级教程: 执行</a>
+
+HTML 转义
+-------------
+
+遇到 HTML标签时 Handlebars 会返回转义后的 HTML,如果你不希望被转义,可以使用 `{{{`
+
+```html
+<div class="entry">
+ <h1>{{title}}</h1>
+ <div class="body">
+ {{{body}}}
+ </div>
+</div>
+```
+
+渲染数据:
+
+```js
+{
+ title: "All about <p> Tags",
+ body: "<p>This is a post about &lt;p&gt; tags</p>"
+}
+```
+
+渲染结果:
+
+```html
+<div class="entry">
+ <h1>All About &lt;p&gt; Tags</h1>
+ <div class="body">
+ <p>This is a post about &lt;p&gt; tags</p>
+ </div>
+</div>
+```
+
+<a href="#SafeString" name="SafeString"></a>
+
+Handlebars 不会转义 `Handlebars.SafeString` 。如果你自定义了一个 helper 返回 HTML 代码,你需要返回 `new Handlebars.SafeString(result)` ,那么你需要手动对内容进行转义
+
+```js
+Handlebars.registerHelper('link', function(text, url) {
+ text = Handlebars.Utils.escapeExpression(text);
+ url = Handlebars.Utils.escapeExpression(url);
+
+ var result = '<a href="' + url + '">' + text + '</a>';
+
+ return new Handlebars.SafeString(result);
+});
+```
+
+`new Handlebars.SafeString()` 会标识传入参数是“安全的”,所以即使你不使用 `{{{` 。Handlebars 也不会转义。
+
+[示例](demo/SafeString.md)
+
+
+块表达式
+-------
+
+块表达式允许你定义helper,用不同的数据上下文(context)调用一段模板。下面我们定义一个生成列表的helper:
+
+快表达式允许你自定义 helper,使用当前传入参数作为上下文调用模板。
+
+创建一个用于生产列表的快表达式
+
+```
+{{#list people}}{{firstName}} {{lastName}}{{/list}}
+```
+
+渲染数据如下所示:
+
+```js
+{
+ people: [
+ {firstName: "Yehuda", lastName: "Katz"},
+ {firstName: "Carl", lastName: "Lerche"},
+ {firstName: "Alan", lastName: "Johnson"}
+ ]
+}
+```
+
+we would create a helper named `list` to generate our HTML list. The helper receives the `people` as its first parameter, and an options hash as its second parameter. The options hash contains a property named `fn`, which you can invoke with a context just as you would invoke a normal Handlebars template.
+
+```js
+Handlebars.registerHelper('list', function(items, options) {
+ var out = "<ul>";
+
+ for(var i=0, l=items.length; i<l; i++) {
+ out = out + "<li>" + options.fn(items[i]) + "</li>";
+ }
+
+ return out + "</ul>";
+});
+```
+
+When executed, the template will render:
+
+```html
+<ul>
+ <li>Yehuda Katz</li>
+ <li>Carl Lerche</li>
+ <li>Alan Johnson</li>
+</ul>
+```
+
+Block helpers have more features, such as the ability to create an else section (used, for instance, by the built-in if helper).
+
+Since the contents of a block helper are escaped when you call `options.fn(context)`, Handlebars does not escape the results of a block helper. If it did, inner content would be double-escaped!
+
+<a href="block_helpers.md" class="more-info">Learn More: Block Helpers</a>
+
+Handlebars Paths
+----------------
+
+Handlebars supports simple paths, just like Mustache.
+
+```html
+<p>{{name}}</p>
+```
+
+Handlebars also supports nested paths, making it possible to look up properties nested below the current context.
+
+```html
+<div class="entry">
+ <h1>{{title}}</h1>
+ <h2>By {{author.name}}</h2>
+
+ <div class="body">
+ {{body}}
+ </div>
+</div>
+```
+
+That template works with this context
+
+
+```
+var context = {
+ title: "My First Blog Post!",
+ author: {
+ id: 47,
+ name: "Yehuda Katz"
+ },
+ body: "My first post. Wheeeee!"
+};
+```
+
+This makes it possible to use Handlebars templates with more raw JSON objects.
+
+Nested handlebars paths can also include `../` segments, which evaluate their paths against a parent context.
+
+
+
+```html
+<h1>Comments</h1>
+
+<div id="comments">
+ {{#each comments}}
+ <h2><a href="/posts/{{../permalink}}#{{id}}">{{title}}</a></h2>
+ <div>{{body}}</div>
+ {{/each}}
+</div>
+```
+
+Even though the link is printed while in the context of a comment, it can still go back to the main context (the post) to retrieve its permalink.
+
+The `../` path segment references the parent template scope, not one level up in the context. This is because block helpers can invoke a block with any context, so the notion of "one level up" isn't particularly meaningful except as a reference to the parent template scope.
+
+
+
+Handlebars also allows for name conflict resolution between helpers and data fields via a this reference:
+
+```html
+<p>{{./name}} or {{this/name}} or {{this.name}}</p>
+```
+
+Any of the above would cause the `name` field on the current context to be used rather than a helper of the same name.
+
+
+Template comments with {{!-- --}} or {{! }}.
+---------------------------------------------
+
+You can use comments in your handlebars code just as you would in your code. Since there is generally some level of logic, this is a good practice.
+
+```html
+<div class="entry">
+ {{!-- only output this author names if an author exists --}}
+ {{#if author}}
+ <h1>{{firstName}} {{lastName}}</h1>
+ {{/if}}
+</div>
+```
+
+The comments will not be in the resulting output. If you'd like the comments to show up. Just use html comments, and they will be output.
+
+```html
+<div class="entry">
+ {{! This comment will not be in the output }}
+ <!-- This comment will be in the output -->
+</div>
+```
+
+Any comments that must contain `}}` or other handlebars tokens should use the `{{!-- --}}` syntax.
+
+Helpers
+-------
+
+Handlebars helpers can be accessed from any context in a template. You can register a helper with the `Handlebars.registerHelper` method.
+
+```html
+<div class="post">
+ <h1>By {{fullName author}}</h1>
+ <div class="body">{{body}}</div>
+ <h1>Comments</h1>
+ {{#each comments}}
+ <h2>By {{fullName author}}</h2>
+ <div class="body">{{body}}</div>
+ {{/each}}
+</div>
+```
+
+
+when using this context and helpers:
+
+```js
+var context = {
+ author: {firstName: "Alan", lastName: "Johnson"},
+ body: "I Love Handlebars",
+ comments: [{
+ author: {firstName: "Yehuda", lastName: "Katz"},
+ body: "Me too!"
+ }]
+};
+
+Handlebars.registerHelper('fullName', function(person) {
+ return person.firstName + " " + person.lastName;
+});
+```
+
+results in:
+
+```html
+<div class="post">
+ <h1>By Alan Johnson</h1>
+ <div class="body">I Love Handlebars</div>
+ <h1>Comments</h1>
+ <h2>By Yehuda Katz</h2>
+ <div class="body">Me Too!</div>
+</div>
+```
+
+
+Helpers receive the current context as the `this` context of the function.
+
+```html
+<ul>
+ {{#each items}}
+ <li>{{agree_button}}</li>
+ {{/each}}
+</ul>
+```
+
+when using this context and helpers:
+
+```js
+var context = {
+ items: [
+ {name: "Handlebars", emotion: "love"},
+ {name: "Mustache", emotion: "enjoy"},
+ {name: "Ember", emotion: "want to learn"}
+ ]
+};
+
+Handlebars.registerHelper('agree_button', function() {
+ var emotion = Handlebars.escapeExpression(this.emotion),
+ name = Handlebars.escapeExpression(this.name);
+
+ return new Handlebars.SafeString(
+ "<button>I agree. I " + emotion + " " + name + "</button>"
+ );
+});
+```
+
+results in:
+
+```html
+<ul>
+ <li><button>I agree. I love Handlebars</button></li>
+ <li><button>I agree. I enjoy Mustache</button></li>
+ <li><button>I agree. I want to learn Ember</button></li>
+</ul>
+```
+
+If your helper returns HTML that you do not want escaped, make sure to return a new Handlebars.SafeString.
+
+
+
+Built-In Helpers
+----------------
+
+Handlebars offers a variety of built-in helpers such as the if conditional and each iterator.
+
+<a href="builtin_helpers.md" class="more-info">Learn More: Built-In Helpers</a>
+
+
+API Reference
+-------------
+
+Handlebars offers a variety of APIs and utility methods for applications and helpers.
+
+<a href="reference.md" class="more-info">Learn More: API Reference</a>
+
+
+<!---</div>--><!-- End .contents \ No newline at end of file
diff --git a/posts/precompilation.md b/posts/precompilation.md
new file mode 100644
index 0000000..aaaf1f1
--- /dev/null
+++ b/posts/precompilation.md
@@ -0,0 +1,19 @@
+<!--_PAGEDATA
+{
+ "title": "Handlebars 中文网:轻逻辑语义化的模板引擎",
+ "github":"nimojs/handlebarsjs.org",
+ "githubissuesid": 1,
+ "createData": "2015-04-10",
+ "keywords": "",
+ "description": "轻逻辑语义化的模板引擎",
+ "_template": "default"
+}
+_PAGEDATA-->
+
+<div id="intro">
+
+正在翻译中... ,你可以访问 [https://github.com/nimojs/handlebarsjs.org/](https://github.com/nimojs/handlebarsjs.org/) 参与翻译工作
+
+</div>
+
+<!-- End .contents--> \ No newline at end of file
diff --git a/posts/reference.md b/posts/reference.md
new file mode 100644
index 0000000..aaaf1f1
--- /dev/null
+++ b/posts/reference.md
@@ -0,0 +1,19 @@
+<!--_PAGEDATA
+{
+ "title": "Handlebars 中文网:轻逻辑语义化的模板引擎",
+ "github":"nimojs/handlebarsjs.org",
+ "githubissuesid": 1,
+ "createData": "2015-04-10",
+ "keywords": "",
+ "description": "轻逻辑语义化的模板引擎",
+ "_template": "default"
+}
+_PAGEDATA-->
+
+<div id="intro">
+
+正在翻译中... ,你可以访问 [https://github.com/nimojs/handlebarsjs.org/](https://github.com/nimojs/handlebarsjs.org/) 参与翻译工作
+
+</div>
+
+<!-- End .contents--> \ No newline at end of file
diff --git a/precompilation.html b/precompilation.html
new file mode 100644
index 0000000..e4c428f
--- /dev/null
+++ b/precompilation.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Handlebars 中文网:轻逻辑语义化的模板引擎</title>
+ <meta charset="UTF-8">
+ <link href="static/stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/sunburst.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/site.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/images/favicon.png" rel="shortcut icon" type="image/png" />
+ </head>
+ <body>
+ <div id="body">
+ <div id="header">
+ <a href="index.html">
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
+ </a>
+ </div>
+ <div id="contents">
+ <a href="http://www.devswag.com/collections/handlebars" id="callout">
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
+ </a>
+
+<div id="intro">
+
+&#x6B63;&#x5728;&#x7FFB;&#x8BD1;&#x4E2D;... &#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE; <a href="https://github.com/nimojs/handlebarsjs.org/" target="_blank">https://github.com/nimojs/handlebarsjs.org/</a> &#x53C2;&#x4E0E;&#x7FFB;&#x8BD1;&#x5DE5;&#x4F5C;
+
+</div>
+
+<!-- End .contents-->
+ <a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
+ 发现翻译错误?告诉我们。
+ </a>
+ </div>
+ </div>
+ <div id="credits"></div>
+ <a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
+ </a>
+ </body>
+</html>
diff --git a/reference.html b/reference.html
new file mode 100644
index 0000000..e4c428f
--- /dev/null
+++ b/reference.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title>Handlebars 中文网:轻逻辑语义化的模板引擎</title>
+ <meta charset="UTF-8">
+ <link href="static/stylesheets/application.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/sunburst.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/stylesheets/site.css" media="all" rel="stylesheet" type="text/css"/>
+ <link href="static/images/favicon.png" rel="shortcut icon" type="image/png" />
+ </head>
+ <body>
+ <div id="body">
+ <div id="header">
+ <a href="index.html">
+ <img alt="Handlebars 中文网:轻逻辑语义化的模板引擎" src="static/images/handlebars_logo.png"/>
+ </a>
+ </div>
+ <div id="contents">
+ <a href="http://www.devswag.com/collections/handlebars" id="callout">
+ <img alt="Buy Handlebars swag on DevSwag!" src="static/images/handlebars-devswag.png"/>
+ </a>
+
+<div id="intro">
+
+&#x6B63;&#x5728;&#x7FFB;&#x8BD1;&#x4E2D;... &#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE; <a href="https://github.com/nimojs/handlebarsjs.org/" target="_blank">https://github.com/nimojs/handlebarsjs.org/</a> &#x53C2;&#x4E0E;&#x7FFB;&#x8BD1;&#x5DE5;&#x4F5C;
+
+</div>
+
+<!-- End .contents-->
+ <a class="issue-tracker" href="https://github.com/nimojs/handlebarsjs.org/issues">
+ 发现翻译错误?告诉我们。
+ </a>
+ </div>
+ </div>
+ <div id="credits"></div>
+ <a href="http://github.com/nimojs/handlebarsjs.org/" id="github">
+ <img alt="Fork me on GitHub" src="static/images/forkme_right_darkblue_121621.png" />
+ </a>
+ </body>
+</html>
diff --git a/static/css/demo.css b/static/css/demo.css
index bbd2198..0f99dbe 100644
--- a/static/css/demo.css
+++ b/static/css/demo.css
@@ -474,6 +474,9 @@ textarea#result{
margin-bottom: 2em;
padding:.5em;
}
+.ui-dom em{
+ font-style: italic;
+}
.ui-dom:before {
content: "渲染结果预览:";
display: block;
diff --git a/images/favicon.png b/static/images/favicon.png
index 3f67928..3f67928 100755
--- a/images/favicon.png
+++ b/static/images/favicon.png
Binary files differ
diff --git a/static/images/forkme_right_darkblue_121621.png b/static/images/forkme_right_darkblue_121621.png
new file mode 100644
index 0000000..146ef8a
--- /dev/null
+++ b/static/images/forkme_right_darkblue_121621.png
Binary files differ
diff --git a/images/handlebars-devswag.png b/static/images/handlebars-devswag.png
index 770fee5..770fee5 100755
--- a/images/handlebars-devswag.png
+++ b/static/images/handlebars-devswag.png
Binary files differ
diff --git a/images/handlebars-mark.png b/static/images/handlebars-mark.png
index 5701e3a..5701e3a 100755
--- a/images/handlebars-mark.png
+++ b/static/images/handlebars-mark.png
Binary files differ
diff --git a/images/handlebars_logo.png b/static/images/handlebars_logo.png
index 54f6f8a..54f6f8a 100755
--- a/images/handlebars_logo.png
+++ b/static/images/handlebars_logo.png
Binary files differ
diff --git a/images/noise.png b/static/images/noise.png
index 545d930..545d930 100755
--- a/images/noise.png
+++ b/static/images/noise.png
Binary files differ
diff --git a/static/stylesheets/application.css b/static/stylesheets/application.css
index 202200f..cfa01f9 100755
--- a/static/stylesheets/application.css
+++ b/static/stylesheets/application.css
@@ -15,12 +15,12 @@
/* line 48 */
html {
- background-image: url("../../images/noise.png"), -webkit-gradient(radial, 50% 0%, 0, 50% 0%, 750, color-stop(0%, #f7931e), color-stop(100%, #f15a24));
- background-image: url("../../images/noise.png"), -webkit-radial-gradient(top center, #f7931e, #f15a24 750px);
- background-image: url("../../images/noise.png"), -moz-radial-gradient(top center, #f7931e, #f15a24 750px);
- background-image: url("../../images/noise.png"), -o-radial-gradient(top center, #f7931e, #f15a24 750px);
- background-image: url("../../images/noise.png"), -ms-radial-gradient(top center, #f7931e, #f15a24 750px);
- background-image: url("../../images/noise.png"), radial-gradient(top center, #f7931e, #f15a24 750px);
+ background-image: url("../images/noise.png"), -webkit-gradient(radial, 50% 0%, 0, 50% 0%, 750, color-stop(0%, #f7931e), color-stop(100%, #f15a24));
+ background-image: url("../images/noise.png"), -webkit-radial-gradient(top center, #f7931e, #f15a24 750px);
+ background-image: url("../images/noise.png"), -moz-radial-gradient(top center, #f7931e, #f15a24 750px);
+ background-image: url("../images/noise.png"), -o-radial-gradient(top center, #f7931e, #f15a24 750px);
+ background-image: url("../images/noise.png"), -ms-radial-gradient(top center, #f7931e, #f15a24 750px);
+ background-image: url("../images/noise.png"), radial-gradient(top center, #f7931e, #f15a24 750px);
width: 100%;
background-color: #f7931e;
padding-top: 10px;
diff --git a/static/stylesheets/site.css b/static/stylesheets/site.css
index 2d6693f..10dd695 100644
--- a/static/stylesheets/site.css
+++ b/static/stylesheets/site.css
@@ -618,4 +618,15 @@ Ported by Fabr铆cio Tavares de Oliveira
}
.translator:before{
content: "译者注:"
+}
+hr{
+ margin-top: 1em;
+ margin-bottom: 1em;
+ height: 0;overflow: hidden;
+ border-bottom:1px dotted #582a00;
+}
+
+#contents ul{
+ list-style-type: disc;
+ padding-left: 1em;
} \ No newline at end of file