Skip to content
Browse files

Merge branch 'master' of https://github.com/mitemitreski/blog-examples

  • Loading branch information...
2 parents 61b7ada + a050f53 commit e869fe09da7852e97de9c7ef6218f89eac03d5fc @mitemitreski committed Jul 13, 2012
Showing with 80 additions and 1 deletion.
  1. +39 −1 mustache-js/example.html
  2. +41 −0 mustache-js/example.js
View
40 mustache-js/example.html
@@ -3,9 +3,47 @@
<head>
<meta charset="utf-8" />
<title>Mustache JS examples</title>
+ <!-- vendor js -->
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>
+ <script src="http://code.jquery.com/jquery-latest.min.js"></script>
+ <!-- app code-->
+ <script src="example.js"></script>
+ <script id="book-template" type="text/x-mustache-template">
+ <div class="book-box">
+ <h3>{{title}}</h3>
+ <span> is awesome book get it on <a href="{{associateUrl}}">Amazon</a> </span>
+ </div>
+ </script>
+ <script id="book-template-full" type="text/x-mustache-template">
+ <div class="book-box">
+ <h3>{{title}} by {{author.name}}</h3>
+ <p> is awesome book get it on <a href="{{associateUrl}}">Amazon</a> </p>
+ <p>{{#haveInStock}} Is available get one now {{/haveInStock}} </p>
+ <ul>
+ {{#similarBooks}}
+ <li>{{title}}</li>
+ {{/similarBooks}}
+ </ul>
+ <ol>
+ {{#comments}}
+ <li>{{comment}}</li>
+ {{/comments}}
+ {{^comments}}
+ <li>No comments add one</li>
+ {{/comments}}
+ </ol>
+ </div>
+ </script>
</head>
<body>
-
+ <div id="content-mustache-full">
+ None
+ </div>
+ <div id="content-mustache">
+ None
+ </div>
+ <div id="content-jquery">
+ None
+ </div>
</body>
</html>
View
41 mustache-js/example.js
@@ -0,0 +1,41 @@
+var book = {
+ id : 12,
+ title : "A Game of Thrones",
+ url : "http://www.amazon.com/gp/product/0553573403/",
+ amazonId : "mitemitreskic-20",
+ associateUrl : function() {
+ return this.url + '?tag=' + this.amazonId;
+ },
+ author : {
+ name : 'George R. R. Martin',
+ imdbUrl : 'http://www.imdb.com/name/nm0552333/',
+ wikiUrl : 'https://en.wikipedia.org/wiki/George_R._R._Martin'
+ },
+ haveInStock : true,
+ similarBooks : [{
+ id : 13,
+ title : "Decision Points"
+ }, {
+ id : 13,
+ title : "Spoken from the Heart"
+ }],
+ comments : []
+};
+
+jQuery(document).ready(function() {
+ var template = jQuery('#book-template-full').html();
+ var renderedData = Mustache.render(template, book);
+ jQuery('#content-mustache-full').html(renderedData);
+});
+
+jQuery(document).ready(function() {
+ var template = jQuery('#book-template').html();
+ var renderedData = Mustache.render(template, book);
+ jQuery('#content-mustache').html(renderedData);
+});
+
+jQuery(document).ready(function() {
+ var out = '<div class="book-box"><h3>' + book.title + '</h3><span> is awesome book get it on <a href="' + book.associateUrl() + '">Amazon</a></span></div>';
+ jQuery('#content-jquery').html(out);
+});
+

0 comments on commit e869fe0

Please sign in to comment.
Something went wrong with that request. Please try again.