diff options
author | nimojs <imhadley@163.com> | 2015-04-19 23:14:19 +0800 |
---|---|---|
committer | nimojs <imhadley@163.com> | 2015-04-19 23:14:19 +0800 |
commit | cbaf08642e63b1dc50b99ba5ac41ea1ecc4b7163 (patch) | |
tree | 2d2d55cfbd5e9b89a99223d2e30037ed4ba14cae /posts/demo | |
parent | 720cb5a6ba938cb9864bd24d6df5527b5cdbfa91 (diff) | |
download | handlebarsjs.org-master.zip handlebarsjs.org-master.tar.gz handlebarsjs.org-master.tar.bz2 |
增加章节,静态资源文件目录调整
Diffstat (limited to 'posts/demo')
-rw-r--r-- | posts/demo/SafeString.md | 34 | ||||
-rw-r--r-- | posts/demo/demo.md | 27 | ||||
-rw-r--r-- | posts/demo/execution-1.md (renamed from posts/demo/index-1.md) | 15 |
3 files changed, 59 insertions, 17 deletions
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> + |