Browse Source

用mustache 模版渲染文章

visuddhinanda@gmail.com 4 years ago
parent
commit
ff7004d5e2

+ 10 - 2
public/app/article/article.js

@@ -51,8 +51,14 @@ function articel_load(id, collection_id) {
 						$("#contents").html(note_init(result.content,"",result.owner,result.lang));
 						//处理<code>标签作为气泡注释
 						popup_init();
-						guide_init();						
-						note_refresh_new();
+						guide_init();
+						note_refresh_new(function(){
+                            $.get('templiates/glossary.tpf',function(data){
+                                let TermData = term_get_used();
+                                let rendered = Mustache.render(data,TermData);
+                                $("#glossary").html(rendered);                                
+                            });
+                        });
 
 
 					}
@@ -66,6 +72,8 @@ function articel_load(id, collection_id) {
 	);
 }
 
+
+
 function collect_load(id) {
 	if (id == "") {
 		return;

+ 3 - 2
public/app/article/index.php

@@ -147,8 +147,8 @@ require_once "../pcdl/html_head.php";
 <link href="../../node_modules/jquery.fancytree/dist/skin-win7/ui.fancytree.css" rel="stylesheet" type="text/css" class="skinswitcher">
 <script src="../tree/jquery.fancytree.js" type="text/javascript"></script>
 <script src="../article/my_collect.js" type="text/javascript"></script>
-<script language="javascript" src="../article/article_add_dlg.js"></script>
-
+<script src="../article/article_add_dlg.js"></script>
+<script src="../../node_modules/mustache/mustache.js"></script>
 
 <style>
 ul.fancytree-container{
@@ -388,6 +388,7 @@ function set_toc_visible(isVisible){
 			<div id="contents" class="content_inner <?php echo $contentClass;?>">
 				<?php echo $_local->gui->loading; ?>...
 			</div>
+            <div id="glossary"></div>
 			<div id="contents_foot">
 				<div id="contents_nav" style="display:flex;justify-content: space-between;">
 					<div id="contents_nav_left" class="nav_bnt nav_left" onclick="goto_prev()">

+ 6 - 0
public/app/article/templiates/glossary.tpl

@@ -0,0 +1,6 @@
+<h2>Glossary</h2>
+{{#glossary}}
+<div>
+<b>{{pali}}</b>:{{meaning}}
+</div>
+{{/glossary}}

+ 22 - 0
public/app/article/templiates/main.tpl

@@ -0,0 +1,22 @@
+<div>
+{{title}}
+</div>
+<div>
+{{subtitle}}
+</div>
+<div>
+{{editor.name}} at {{updated_at}}
+</div>
+<div class="content">
+{{content}}
+</div>
+
+<h2>Glossary</h2>
+{{#glossary}}
+<b>{{pali}}</b>:{{meaning}}
+{{/glossary}}
+
+<h2>ref</h2>
+{{#ref}}
+{{path}}
+{{/ref}}

+ 55 - 0
public/app/article/templiates/readme.md

@@ -0,0 +1,55 @@
+# 标题
+
+正文
+
+{{1-2-3-4}}
+
+<h1>标题</h1>
+<p></p>
+<p>{{1-2-3-4}}</p>
+
+<h1>标题</h1>
+<p></p>
+<p>
+<div class='sent'>
+    <div class='org'>
+        {{1-2-3-4.org}}
+    </div>
+    <div class='translation'>
+        {{#1-2-3-4.translation}}
+            <div>{{text}}</div>
+        {{/1-2-3-4.translation}}
+    </div>
+</div>
+</p>
+
+{
+    1-2-3-4:{
+        org:"pali text"
+        translation:[
+            {
+                text:"一句译文[[bhikkhu]]",
+                channel:"channel1"
+            },
+            {
+                text:"另一句译文[[bhikkhu]]",
+                channel:"channel2"
+            },
+        ]
+    }
+}
+
+<h1>标题</h1>
+<p></p>
+<p>
+<div class='sent'>
+    <div class='org'>
+        pali text
+    </div>
+    <div class='translation'>
+        <div>一句译文{{term.bhikkhu.channel1}}</div>
+        <div>一句译文{{term.bhikkhu.channel2}}</div>
+    </div>
+</div>
+</p>
+

+ 10 - 0
public/app/article/templiates/sent.tpl

@@ -0,0 +1,10 @@
+<div class='sent'>
+    <div class='org'>
+        {{org}}
+    </div>
+    <div class='translation'>
+        {{#translation}}
+            <div>{{text}}</div>
+        {{/translation}}
+    </div>
+</div>