Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

An example using Flickr JSON API #4

Merged
merged 3 commits into from

2 participants

@nebulous
Collaborator

I think this shows how useful jemplate can be to render a large structure.

@ingydotnet
Owner

Hi nebby. I'll apply this, but find me on #jemplate....

@ingydotnet ingydotnet merged commit 4a08fb4 into ingydotnet:master
@ingydotnet
Owner

hmm. This test is failing both tests/ and tests/tjs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 15, 2011
  1. @nebulous

    Flickr Kittys example

    nebulous authored
  2. @nebulous

    No need to console.log

    nebulous authored
Commits on Jul 18, 2011
  1. @nebulous
This page is out of date. Refresh to see the latest.
View
5 examples/Makefile
@@ -1,6 +1,6 @@
PERL5LIB = ../lib
-all: js/ajax.js js/hello.js js/features.js
+all: js/ajax.js js/hello.js js/features.js js/kittys.js
js/ajax.js: Makefile
perl ../jemplate --compile ajax/template/* > $@
@@ -10,3 +10,6 @@ js/hello.js: Makefile
js/features.js: Makefile
perl ../jemplate --compile features/templates/* > $@
+
+js/kittys.js: Makefile
+ perl ../jemplate --compile kittys/templates/* > $@
View
1  examples/index.html
@@ -7,6 +7,7 @@
<li> <a href="hello/index.html">Hello</a></li>
<li> <a href="features/index.html">Features</a></li>
<li> <a href="ajax/index.html">Ajax</a></li>
+ <li> <a href="kittys/index.html">Kittys</a></li>
</ul>
</body>
</html>
View
20 examples/kittys/index.html
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <title>Kittys Jemplate Example</title>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
+ <script src="../js/JemplateRuntime.js" type="text/javascript"></script>
+ <script src="../js/kittys.js" type="text/javascript"></script>
+
+ <script type="text/javascript">
+$(function() {
+ $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
+ { tags: "kitty cat", tagmode: "any", format: "json" }, function(data) { Jemplate.process('kittys.html',data,'#flickr') });
+});
+ </script>
+
+ </head>
+ <body>
+Loading...
+ <div id="flickr"></div>
+ </body>
+</html>
View
6 examples/kittys/templates/kittys.html
@@ -0,0 +1,6 @@
+<h1>Flickr Kittys</h1>
+[% FOREACH kitty = items %]
+ <h2>[% kitty.title %]</h2>
+ [% kitty.author %] took this picture [% kitty.date_taken %]<br />
+ <a href="[% kitty.link %]"><img src="[% kitty.media.m %]" /></a>
+[% END %]
View
6 src/js/kernel.js
@@ -374,9 +374,9 @@ if (typeof Jemplate.Stash == 'undefined') {
Jemplate.Stash = function(stash, config) {
this.__config__ = config;
- this.data = {
- GLOBAL : this.__config__.SCOPE
- };
+ this.data = config["VARIABLES"];
+ this.data["GLOBAL"] = this.__config__.SCOPE;
+
this.LOCAL_ANCHOR = {};
this.data.LOCAL = this.LOCAL_ANCHOR;
View
3  tests/index.html
@@ -25,7 +25,8 @@
"plugins.t.html",
"set.t.html",
"stash.t.html",
- "string.t.html"
+ "string.t.html",
+ "variables.t.html"
);
</script>
</body>
View
43 tests/t/variables.t.js
@@ -0,0 +1,43 @@
+var t = new Test.Jemplate();
+
+t.plan(3);
+
+t.compile();
+
+var j = new Jemplate();
+var jVAR = new Jemplate({VARIABLES:{who:'Beaver'}});
+
+var test1 = t.state.blocks.shift();
+t.is(
+ j.process('hello', {who: 'Wally'}),
+ test1.data.output,
+ test1.name
+);
+
+var test2 = t.state.blocks.shift();
+t.is(
+ jVAR.process('hello',{}),
+ test2.data.output,
+ test2.name
+);
+
+var test3 = t.state.blocks.shift();
+t.is(
+ jVAR.process('hello', {who: 'Wally'}),
+ test3.data.output,
+ test3.name
+);
+
+
+/* Test
+=== Test without VARIABLES set in config hash
+--- output
+Hello, Wally!
+=== Test with VARIABLES set in config hash
+--- output
+Hello, Beaver!
+=== Test with VARIABLES set in config hash being overridden by local var
+--- output
+Hello, Wally!
+
+*/
Something went wrong with that request. Please try again.