Skip to content

Commit

Permalink
support for json string is added. documentation is done.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Sep 15, 2011
1 parent db73c6b commit 5a3916c
Show file tree
Hide file tree
Showing 31 changed files with 675 additions and 558 deletions.
8 changes: 6 additions & 2 deletions html/basic.html
@@ -1,4 +1,8 @@
<table><tr ><td class="functionDoc">
<table>
<tr><td>
<div class="h6">Basic</div>
</td></tr></tr>
<td class="functionDoc">
<div class="h5">JSON:</div>
<code>
{ "first_name":"Vadim", "last_name":"Kiryukhin", "state":"California"}
Expand All @@ -13,6 +17,6 @@
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('tmpl/basic.tmpl','php/basic.php');
$('#leftpanel').vkTemplate('basic.tmpl','basic.php');
</code>
</td></tr></table>
6 changes: 4 additions & 2 deletions html/callback.html
@@ -1,6 +1,8 @@
<table>
<tr><td>
<p>After template is rendered callback function (which is optional ) is called.</p>
<div class="h6">Callback</div>
<p>After template is rendered, optional callback function can be called.
With this function you can resize existing and/or loaded elements, adjust layout, hide loading image, etc. </p>
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div>
Expand All @@ -17,6 +19,6 @@
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('tmpl/basic.tmpl','php/basic.php', function(){$('#leftpanel div').css('background-color','yellow')});
$('#leftpanel').vkTemplate('basic.tmpl','basic.php',<span class="highlight"> function(){$('#leftpanel div').css('background-color','yellow')}</span>);
</code>
</td></tr></table>
27 changes: 27 additions & 0 deletions html/condition.html
@@ -0,0 +1,27 @@
<table>
<tr><td>
<div class="h6">Condition</div>
Click on "Conditions" menu item several times to see how it works.
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div><pre><code>
{"h":"04","m":"20","s":"22"}
</code></pre>
</td></tr><tr><td class="templateDoc">
<div class="h5">Template:</div>
<pre><code>
Current time is: <%=h%>:<%=m%>:<%=s%>

&lt;%if (s%2) {%&gt;
odd second
&lt;%} else {%&gt;
even second
&lt;%}%&gt;
</code></pre>
</td></tr>
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('condition.tmpl','condition.php');
</code>
</td></tr></table>
20 changes: 8 additions & 12 deletions html/csi.html
@@ -1,6 +1,8 @@
<table>
<tr><td>
<p>Similar to <b>Server Side Include</b> technology.</p>
<div class="h6">Client Side Include</div>
<p>Client Side Include <b>( CSI )</b> is similar to "Server Side Include" <b>( SSI )</b> technology. Simply include actual templates into template-container. Load this template-container either as a standalone html page or with jQuery ajax's .load() function. You don't need to use vkTemplate() plugin to load template-container itself.
</p>
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div><pre><code>
Expand All @@ -9,28 +11,22 @@
</td></tr><tr><td class="templateDoc">
<div class="h5">Template:</div>
<pre><code>
&lt;div id="tmpl_1"&gt;
&lt;div id="foo"&gt;
&lt;script type="text/javascript">
$('#tmpl_1').vkTemplate('tmpl/basic.tmpl','php/basic.php');
<span class="highlight">$('#foo').vkTemplate('basic.tmpl','basic.php');</span>
&lt;/script&gt;
&lt;/div&gt;

&lt;div id="tmpl_2"&gt;
&lt;div id="bar"&gt;
&lt;script type="text/javascript">
$('#tmpl_2').vkTemplate('tmpl/loop_and_condition.tmpl','php/loop_and_condition.php');
&lt;/script&gt;
&lt;/div&gt;

&lt;div id="tmpl_3"&gt;
&lt;script type="text/javascript">
$('#tmpl_3').vkTemplate('tmpl/nested_conditionally.tmpl','php/loop_and_condition.php');
<span class="highlight">$('#bar').vkTemplate('nested.tmpl','loop.php');</span>
&lt;/script&gt;
&lt;/div&gt;
</code></pre>
</td></tr>
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('tmpl/csi.tmpl','php/basic.php');
$('#leftpanel').load('csi.tmpl');
</code>
</td></tr></table>
53 changes: 53 additions & 0 deletions html/doc.html
@@ -0,0 +1,53 @@
<style type="text/css">
#doc {margin:1em;}
#doc ul li {margin:0.5em;}
</style>
<div id="doc">
<div class="h6">Documentation</div>
<p>

<ul>
<li>No configuration is needed</li>
<li>Include in the page head: <code>&lt;script type="text/javascript" src="vktemplate.js"&gt;&lt;/script&gt;</code>

<li>Usage format: <code>$('#container').vkTemplate(urlTemplate, jsonData [, callback]);</code>

</li>
<li>Parameters:
<ul>
<li><code>@urlTemplate</code> - URL address to get template;</li>

<li><code>@jsonData</code>:<br/>
- URL address to get data.<br/>
- JSON string;
</li>
<li><code>@callback</code> - callback function (optional)</li>
</ul>
</li>

<li>Usage Examples:
<ul>
<li><code>$('#container').vkTemplate(urlTemplate, urlJsonData);</code></li>
<li><code>$('#container').vkTemplate(urlTemplate, '{"foo":"bar"}');</code></li>
<li><code>$('#container').vkTemplate(urlTemplate, urlJsonData, function(){...});</code></li>
</ul>
</li>
<li>Template syntax:
<ul>
<li>javascript logic is wrapped with <b>&lt;% ... &gt;</b><br/></li>
<li>stuff which should be printed is wrapped with <b>&lt;%= ... &gt;</b></li>
</ul>
</li>
<li>Template Examples:
<ul>
<li><code>&lt;%=first_name%> &lt;%=last_name%&gt;></code></li>
<li><pre><code>&lt;%for(var ix=0;ix&lt;time.length;ix++) {%&gt;
time is: &lt;%=time[ix].h%&gt;:&lt;%=time[ix].m%&gt;:&lt;%=time[ix].s%&gt;
&lt;%}%&gt;</code></pre>
</li>
</ul>
</li>
</ul>

</p>
</div>
23 changes: 23 additions & 0 deletions html/empty_string.html
@@ -0,0 +1,23 @@
<table>
<tr><td>
<div class="h6">Empty String</div>
<p>Parameter "state" in JSON is empty, but it doesn't crash application.</p>
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div>
<code>
{ "first_name":"Vadim", "last_name":"Kiryukhin", <span class="highlight">"state":""</span>}
</code>
</td></tr><tr><td class="templateDoc">
<div class="h5">Template:</div>
<code>
My name is &lt;%=first_name%> &lt;%=last_name%&gt;.
Greeting from &lt;%=state%&gt;!
</code>
</td></tr>
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('basic.tmpl','empty_string.php');
</code>
</td></tr></table>
33 changes: 33 additions & 0 deletions html/integration.html
@@ -0,0 +1,33 @@
<table>
<tr><td>
<div class="h6">Integration</div>
<p>
This is an example of a very simple web application, which performs periodical updating functionality. Every 2 seconds it takes time from a server and display it. I use jQuery <a href="http://eslinstructor.net/smartupdater3/" target="_blank">Smartupdater</a> plugin to implement polling mechanism.
</p>
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div><pre><code>
{"h":"06","m":"10","s":"05"}
</code></pre>
</td></tr><tr><td class="templateDoc">
<div class="h5">Template:</div>
<pre><code>
&lt;%=h%&gt;:&lt;%=m%&gt;:&lt;%=s%&gt;
</code></pre>
</td></tr>
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<pre><code>
&lt;div id="timedisplay"&gt;&lt;/div&gt;

&lt;script type="text/javascript"&gt;
$("#timedisplay").<span class="highlight">smartupdater</span>({
url: 'php/get_time.php',<span class="comment"> // url to data </span>
minTimeout: 2000 <span class="comment"> // 2 seconds</span>
}, function (data) {
<span class="highlight">$('#timedisplay').vkTemplate('tmpl/time.tmpl',data);</span>
}
);
&lt;/script&gt;
</code></pre>
</td></tr></table>
10 changes: 2 additions & 8 deletions html/loop_and_condition.html → html/loop.html
@@ -1,6 +1,6 @@
<table>
<tr><td>

<div class="h6">Loop</div>
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div><pre><code>
Expand All @@ -16,17 +16,11 @@
&lt;%for(var ix=0;ix&lt;time.length;ix++) {%&gt;
Current time is: &lt;%=time[ix].h%&gt;:&lt;%=time[ix].m%&gt;:&lt;%=time[ix].s%&gt;
&lt;%}%&gt;

&lt;%if (time[0].s%2) {%&gt;
odd second
&lt;%} else {%&gt;
even second
&lt;%}%&gt;
</code></pre>
</td></tr>
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('tmpl/loop_and_condition.tmpl','php/loop_and_condition.php');
$('#leftpanel').vkTemplate('loop.tmpl','loop.php');
</code>
</td></tr></table>
11 changes: 6 additions & 5 deletions html/nested.html
@@ -1,6 +1,7 @@
<table>
<tr><td>
<p>Parent template <code>tmpl/nested.tmpl</code> calls childe template <code>tmpl/basic.tmpl</code>.</p>
<div class="h6">Nested Templates</div>
<p>Parent template <code>nested.tmpl</code> calls childe template <code>basic.tmpl</code>.</p>
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div>
Expand All @@ -19,15 +20,15 @@
&lt;%}%&gt;

&lt;div id="subcontainer"&gt;&lt;/div&gt;

<span class="highlight">
&lt;script type="text/javascript"&gt;
$('#subcontainer').vkTemplate('tmpl/basic.tmpl','php/basic.php');
&lt;/script&gt;
$('#subcontainer').vkTemplate('basic.tmpl','basic.php');
&lt;/script&gt;</span>
</code></pre>
</td></tr>
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('tmpl/nested.tmpl','php/loop_and_condition.php');
$('#leftpanel').vkTemplate('nested.tmpl','loop.php');
</code>
</td></tr></table>
25 changes: 11 additions & 14 deletions html/nested_conditionally.html
@@ -1,27 +1,24 @@
<table>
<tr><td>
<p>Template<code>tmpl/basic.tmpl</code> is loaded only if seconds is odd number.</p>
<div class="h6">Conditionally Nested</div>
<p>Template <code>basic.tmpl</code> is loaded only if seconds is odd number.
Click on "Conditionally Nested" menu item several times to see how it works.
</p>
</td></tr>
<tr ><td class="functionDoc">
<div class="h5">JSON:</div><pre><code>
{ "time":[
{"h":"04","m":"20","s":"22"},
{"h":"04","m":"20","s":"22"},
{"h":"04","m":"20","s":"22"}
] }
{"h":"06","m":"10","s":"05"}
</code></pre>
</td></tr><tr><td class="templateDoc">
<div class="h5">Template:</div>
<pre><code>
&lt;%for(var ix=0;ix&lt;time.length;ix++) {%&gt;
Current time is: &lt;%=time[ix].h%&gt;:&lt;%=time[ix].m%&gt;:&lt;%=time[ix].s%&gt;
&lt;%}%&gt;
Current time is: &lt;%=h%&gt;:&lt;%=m%&gt;:&lt;%=s%&gt;

&lt;%if (time[0].s%2) {%&gt;
odd second
&lt;%if (s%2) {%&gt;
odd second<span class="highlight">
&lt;script type="text/javascript"&gt;
$('#subcontainer').vkTemplate('tmpl/basic.tmpl','php/basic.php');
&lt;/script&gt;
$('#subcontainer').vkTemplate('basic.tmpl','basic.php');
&lt;/script&gt;</span>
&lt;%} else {%&gt;
even second
&lt;%}%&gt;
Expand All @@ -30,6 +27,6 @@
<tr ><td class="jsonDoc">
<div class="h5">Function:</div>
<code>
$('#leftpanel').vkTemplate('tmpl/nested_conditionally.tmpl','php/loop_and_condition.php');
$('#leftpanel').vkTemplate('nested_conditionally.tmpl','condition.php');
</code>
</td></tr></table>
21 changes: 21 additions & 0 deletions html/overview.html
@@ -0,0 +1,21 @@
<table>
<tr><td>
<div class="h6">Overview</div>
<p>
vkTemplate is a very small, very simple and very powerful template solution for web applications.
<ul>
<li> <b>Small:</b> 65 lines of code, 1.1 k if minified<br/><br/></li>
<li><b>Simple interface:</b> only one function with 2 parameters: <i>template</i> and <i>data</i> (the third parameter: <i>callback function</i> is optional)<br/><br/></li>
<li> <b>Power:</b> well known and popular micro-template engin written by John Resig ( http://ejohn.org ) is used in this plugin as a core function. </li>
</ul>

Template syntax:
<ul>
<li>javascript logic is wrapped with <b>&lt;% ... &gt;</b><br/><br/></li>
<li>stuff which should be printed is wrapped with <b>&lt;%= ... &gt;</b></li>
</ul>

Data format is: <b>JSON</b>
</p>

</td></tr></table>

0 comments on commit 5a3916c

Please sign in to comment.