Browse files

dzilify Jemplate

  • Loading branch information...
1 parent 04fabf1 commit 0fc7577798a9fe04a2116bec4e969990036bad53 @ingydotnet committed Feb 8, 2014
Showing with 312 additions and 281 deletions.
  1. +2 −0 .gitignore
  2. +26 −0 .travis.yml
  3. +0 −30 Makefile.PL
  4. +0 −249 README
  5. +251 −0 ReadMe.md
  6. +31 −0 dist.ini
  7. +2 −2 lib/Jemplate.pm
View
2 .gitignore
@@ -1,3 +1,5 @@
+.build
+Jemplate-*
tests/tjs/var
Makefile
Makefile.old
View
26 .travis.yml
@@ -0,0 +1,26 @@
+language: perl
+perl:
+- 5.18
+- 5.16
+- 5.14
+- 5.12
+- 5.10
+- 5.8
+
+install:
+- git clone --depth=1 --branch=master
+ git://github.com/ingydotnet/test-base-pm ../testml-pm
+- cpanm --quiet --notest
+ File::Find::Rule
+ Spiffy
+ Template
+ Devel::Cover::Report::Coveralls
+
+script:
+- PERL5OPT=-MDevel::Cover=-coverage,statement,branch,condition,path,subroutine
+ PERL5LIB=../testml-pm/lib
+ prove -lv t/
+- cover
+
+after_success:
+- cover -report coveralls
View
30 Makefile.PL
@@ -1,30 +0,0 @@
-use inc::Module::Package 'Ingy:modern 0.13';
-
-{
- require ExtUtils::MakeMaker;
- use strict;
- no strict 'refs';
-
- my $libscan = \&{"ExtUtils::MM_Any::libscan"};
- *{"ExtUtils::MM_Any::libscan"} = sub {
- return '' unless $libscan->(@_);
- return '' if $_[1] =~ /\.sw[p-z]$/;
- return $_[1];
- };
-}
-
-#build_requires 'Directory::Scratch';
-
-if (-e 'inc/.author') {
- my $all_from = join '/', 'lib', split m/-/, name . '.pm';
- `perldoc -tF $all_from > README` if ! -e 'README' || (stat $all_from)[9] > (stat 'README')[9];
-}
-
-requires 'Template' => '2.19';
-requires 'File::Find::Rule' => '0.30';
-
-tests_recursive;
-
-no_index directory => 'examples';
-
-clean_files 't/Jemplate.js t/a.js t/b.js t/check.js';
View
249 README
@@ -1,249 +0,0 @@
-NAME
- Jemplate - JavaScript Templating with Template Toolkit
-
-SYNOPSIS
- var data = Ajax.get('url/data.json');
- var elem = document.getElementById('some-div');
- elem.innerHTML = Jemplate.process('my-template.html', data);
-
- or:
-
- var data = Ajax.get('url/data.json');
- var elem = document.getElementById('some-div');
- Jemplate.process('my-template.html', data, elem);
-
- or simply:
-
- Jemplate.process('my-template.html', 'url/data.json', '#some-div');
-
- or, with jQuery.js:
-
- jQuery.getJSON("url/data.json", function(data) {
- Jemplate.process('my-template.html', data, '#some-div');
- });
-
- From the commandline:
-
- jemplate --runtime --compile path/to/jemplate/directory/ > jemplate.js
-
-DESCRIPTION
- Jemplate is a templating framework for JavaScript that is built over
- Perl's Template Toolkit (TT2).
-
- Jemplate parses TT2 templates using the TT2 Perl framework, but with a
- twist. Instead of compiling the templates into Perl code, it compiles
- them into JavaScript.
-
- Jemplate then provides a JavaScript runtime module for processing the
- template code. Presto, we have full featured JavaScript templating
- language!
-
- Combined with JSON and xmlHttpRequest, Jemplate provides a really simple
- and powerful way to do Ajax stuff.
-
-HOWTO
- Jemplate comes with a command line tool call "jemplate" that you use to
- precompile your templates into a JavaScript file. For example if you
- have a template directory called "templates" that contains:
-
- > ls templates/
- body.html
- footer.html
- header.html
-
- You might run this command:
-
- > jemplate --compile template/* > js/jemplates.js
-
- This will compile all the templates into one JavaScript file.
-
- You also need to generate the Jemplate runtime.
-
- > jemplate --runtime > js/Jemplate.js
-
- Now all you need to do is include these two files in your HTML:
-
- <script src="js/Jemplate.js" type="text/javascript"></script>
- <script src="js/jemplates.js" type="text/javascript"></script>
-
- Now you have Jemplate support for these templates in your HTML document.
-
-PUBLIC API
- The Jemplate.js JavaScript runtime module has the following API method:
-
- Jemplate.process(template-name, data, target);
- The "template-name" is a string like 'body.html' that is the name of
- the top level template that you wish to process.
-
- The optional "data" specifies the data object to be used by the
- templates. It can be an object, a function or a url. If it is an
- object, it is used directly. If it is a function, the function is
- called and the returned object is used. If it is a url, an
- asynchronous <Ajax.get> is performed. The result is expected to be a
- JSON string, which gets turned into an object.
-
- The optional "target" can be an HTMLElement reference, a function or
- a string beginning with a "#" char. If the target is omitted, the
- template result is returned. If it is a function, the function is
- called with the result. If it is a string, the string is used as an
- id to find an HTMLElement.
-
- If an HTMLElement is used (by id or directly) then the innerHTML
- property is set to the template processing result.
-
- The Jemplate.pm Perl module has the following public class methods,
- although you won't likely need to use them directly. Normally, you just
- use the "jemplate" command line tool.
-
- Jemplate->compile_template_files(@template_file_paths);
- Take a list of template file paths and compile them into a module of
- functions. Returns the text of the module.
-
- Jemplate->compile_template_content($content, $template_name);
- Compile one template whose content is in memory. You must provide a
- unique template name. Returns the JavaScript text result of the
- compilation.
-
- Jemplate->compile_module($module_path, \@template_file_paths);
- Similar to `compile_template_files`, but prints to result to the
- $module_path. Returns 1 if successful, undef if error.
-
- Jemplate->compile_module_cached($module_path, \@template_file_paths);
- Similar to `compile_module`, but only compiles if one of the
- templates is newer than the module. Returns 1 if successful compile,
- 0 if no compile due to cache, undef if error.
-
-AJAX AND JSON METHODS
- Jemplate comes with builtin Ajax and JSON support.
-
- Ajax.get(url, [callback]);
- Does a GET operation to the url.
-
- If a callback is provided, the operation is asynchronous, and the
- data is passed to the callback. Otherwise, the operation is
- synchronous and the data is returned.
-
- Ajax.post(url, data, [callback]);
- Does a POST operation to the url.
-
- Same callback rules as "get" apply.
-
- JSON.stringify(object);
- Return the JSON serialization of an object.
-
- JSON.parse(jsonString);
- Turns a JSON string into an object and returns the object.
-
-CURRENT SUPPORT
- The goal of Jemplate is to support all of the Template Toolkit features
- that can possibly be supported.
-
- Jemplate now supports almost all the TT directives, including:
-
- * Plain text
- * [% [GET] variable %]
- * [% CALL variable %]
- * [% [SET] variable = value %]
- * [% DEFAULT variable = value ... %]
- * [% INCLUDE [arguments] %]
- * [% PROCESS [arguments] %]
- * [% BLOCK name %]
- * [% FILTER filter %] text... [% END %]
- * [% JAVASCRIPT %] code... [% END %]
- * [% WRAPPER template [variable = value ...] %]
- * [% IF condition %]
- * [% ELSIF condition %]
- * [% ELSE %]
- * [% SWITCH variable %]
- * [% CASE [{value|DEFAULT}] %]
- * [% FOR x = y %]
- * [% WHILE expression %]
- * [% RETURN %]
- * [% THROW type message %]
- * [% STOP %]
- * [% NEXT %]
- * [% LAST %]
- * [% CLEAR %]
- * [%# this is a comment %]
- * [% MACRO name(param1, param2) BLOCK %] ... [% END %]
-
- ALL of the string virtual functions are supported.
-
- ALL of the array virtual functions are supported:
-
- ALL of the hash virtual functions are supported:
-
- MANY of the standard filters are implemented.
-
- The remaining features will be added very soon. See the DESIGN document
- in the distro for a list of all features and their progress.
-
-BROWSER SUPPORT
- Tested successfully in:
-
- * Firefox Mac/Win32/Linux
- * IE 6.0
- * Safari
- * Opera
- * Konqueror
-
- All tests run 100% successful in the above browsers.
-
-DEVELOPMENT
- The bleeding edge code is available via Git at
- git://github.com/ingydotnet/jemplate.git
-
- You can run the runtime tests directly from
- http://svn.jemplate.net/repo/trunk/tests/run/index.html or from the
- corresponding CPAN or JSAN directories.
-
- Jemplate development is being discussed at
- irc://irc.freenode.net/#jemplate
-
- If you want a committer bit, just ask ingy on the irc channel.
-
-CREDIT
- This module is only possible because of Andy Wardley's mighty Template
- Toolkit. Thanks Andy. I will gladly give you half of any beers I receive
- for this work. (As long as you are in the same room when I'm drinking
- them ;)
-
-AUTHORS
- Ingy döt Net <ingy@cpan.org>
-
- (Note: I had to list myself first so that this line would go into
- META.yml)
-
- Jemplate is truly a community authored project:
-
- Ingy döt Net <ingy@cpan.org>
-
- Tatsuhiko Miyagawa <miyagawa@bulknews.net>
-
- Yann Kerherve <yannk@cpan.org>
-
- David Davis <xantus@xantus.org>
-
- Cory Bennett <coryb@corybennett.org>
-
- Cees Hek <ceeshek@gmail.com>
-
- Christian Hansen
-
- David A. Coffey <dacoffey@cogsmith.com>
-
- Robert Krimen <robertkrimen@gmail.com>
-
- Nickolay Platonov <nickolay8@gmail.com>
-
-AUTHOR
- Ingy döt Net <ingy@cpan.org>
-
-COPYRIGHT AND LICENSE
- Copyright (c) 2006-2008, 2011. Ingy döt Net.
-
- This program is free software; you can redistribute it and/or modify it
- under the same terms as Perl itself.
-
- See http://www.perl.com/perl/misc/Artistic.html
-
View
251 ReadMe.md
@@ -0,0 +1,251 @@
+# SYNOPSIS
+
+ var data = Ajax.get('url/data.json');
+ var elem = document.getElementById('some-div');
+ elem.innerHTML = Jemplate.process('my-template.html', data);
+
+or:
+
+ var data = Ajax.get('url/data.json');
+ var elem = document.getElementById('some-div');
+ Jemplate.process('my-template.html', data, elem);
+
+or simply:
+
+ Jemplate.process('my-template.html', 'url/data.json', '#some-div');
+
+or, with jQuery.js:
+
+ jQuery.getJSON("url/data.json", function(data) {
+ Jemplate.process('my-template.html', data, '#some-div');
+ });
+
+From the commandline:
+
+ jemplate --runtime --compile path/to/jemplate/directory/ > jemplate.js
+
+# DESCRIPTION
+
+Jemplate is a templating framework for JavaScript that is built over
+Perl's Template Toolkit (TT2).
+
+Jemplate parses TT2 templates using the TT2 Perl framework, but with a
+twist. Instead of compiling the templates into Perl code, it compiles
+them into JavaScript.
+
+Jemplate then provides a JavaScript runtime module for processing
+the template code. Presto, we have full featured JavaScript
+templating language!
+
+Combined with JSON and xmlHttpRequest, Jemplate provides a really simple
+and powerful way to do Ajax stuff.
+
+# HOWTO
+
+Jemplate comes with a command line tool call `jemplate` that you use to
+precompile your templates into a JavaScript file. For example if you have
+a template directory called `templates` that contains:
+
+ > ls templates/
+ body.html
+ footer.html
+ header.html
+
+You might run this command:
+
+ > jemplate --compile template/* > js/jemplates.js
+
+This will compile all the templates into one JavaScript file.
+
+You also need to generate the Jemplate runtime.
+
+ > jemplate --runtime > js/Jemplate.js
+
+Now all you need to do is include these two files in your HTML:
+
+ <script src="js/Jemplate.js" type="text/javascript"></script>
+ <script src="js/jemplates.js" type="text/javascript"></script>
+
+Now you have Jemplate support for these templates in your HTML document.
+
+# PUBLIC API
+
+The Jemplate.js JavaScript runtime module has the following API method:
+
+- Jemplate.process(template-name, data, target);
+
+ The `template-name` is a string like `'body.html'` that is the name of
+ the top level template that you wish to process.
+
+ The optional `data` specifies the data object to be used by the
+ templates. It can be an object, a function or a url. If it is an object,
+ it is used directly. If it is a function, the function is called and the
+ returned object is used. If it is a url, an asynchronous <Ajax.get> is
+ performed. The result is expected to be a JSON string, which gets turned
+ into an object.
+
+ The optional `target` can be an HTMLElement reference, a function or a
+ string beginning with a `#` char. If the target is omitted, the
+ template result is returned. If it is a function, the function is called
+ with the result. If it is a string, the string is used as an id to find
+ an HTMLElement.
+
+ If an HTMLElement is used (by id or directly) then the innerHTML
+ property is set to the template processing result.
+
+The Jemplate.pm Perl module has the following public class methods,
+although you won't likely need to use them directly. Normally, you just
+use the `jemplate` command line tool.
+
+- Jemplate->compile\_template\_files(@template\_file\_paths);
+
+ Take a list of template file paths and compile them into a module of
+ functions. Returns the text of the module.
+
+- Jemplate->compile\_template\_content($content, $template\_name);
+
+ Compile one template whose content is in memory. You must provide a
+ unique template name. Returns the JavaScript text result of the
+ compilation.
+
+- Jemplate->compile\_module($module\_path, \\@template\_file\_paths);
+
+ Similar to \`compile\_template\_files\`, but prints to result to the
+ $module\_path. Returns 1 if successful, undef if error.
+
+- Jemplate->compile\_module\_cached($module\_path, \\@template\_file\_paths);
+
+ Similar to \`compile\_module\`, but only compiles if one of the templates
+ is newer than the module. Returns 1 if successful compile, 0 if no
+ compile due to cache, undef if error.
+
+# AJAX AND JSON METHODS
+
+Jemplate comes with builtin Ajax and JSON support.
+
+- Ajax.get(url, \[callback\]);
+
+ Does a GET operation to the url.
+
+ If a callback is provided, the operation is asynchronous, and the data
+ is passed to the callback. Otherwise, the operation is synchronous and
+ the data is returned.
+
+- Ajax.post(url, data, \[callback\]);
+
+ Does a POST operation to the url.
+
+ Same callback rules as `get` apply.
+
+- JSON.stringify(object);
+
+ Return the JSON serialization of an object.
+
+- JSON.parse(jsonString);
+
+ Turns a JSON string into an object and returns the object.
+
+# CURRENT SUPPORT
+
+The goal of Jemplate is to support all of the Template Toolkit features
+that can possibly be supported.
+
+Jemplate now supports almost all the TT directives, including:
+
+ * Plain text
+ * [% [GET] variable %]
+ * [% CALL variable %]
+ * [% [SET] variable = value %]
+ * [% DEFAULT variable = value ... %]
+ * [% INCLUDE [arguments] %]
+ * [% PROCESS [arguments] %]
+ * [% BLOCK name %]
+ * [% FILTER filter %] text... [% END %]
+ * [% JAVASCRIPT %] code... [% END %]
+ * [% WRAPPER template [variable = value ...] %]
+ * [% IF condition %]
+ * [% ELSIF condition %]
+ * [% ELSE %]
+ * [% SWITCH variable %]
+ * [% CASE [{value|DEFAULT}] %]
+ * [% FOR x = y %]
+ * [% WHILE expression %]
+ * [% RETURN %]
+ * [% THROW type message %]
+ * [% STOP %]
+ * [% NEXT %]
+ * [% LAST %]
+ * [% CLEAR %]
+ * [%# this is a comment %]
+ * [% MACRO name(param1, param2) BLOCK %] ... [% END %]
+
+ALL of the string virtual functions are supported.
+
+ALL of the array virtual functions are supported:
+
+ALL of the hash virtual functions are supported:
+
+MANY of the standard filters are implemented.
+
+The remaining features will be added very soon. See the DESIGN document
+in the distro for a list of all features and their progress.
+
+# BROWSER SUPPORT
+
+Tested successfully in:
+
+ * Firefox Mac/Win32/Linux
+ * IE 6.0
+ * Safari
+ * Opera
+ * Konqueror
+
+All tests run 100% successful in the above browsers.
+
+# DEVELOPMENT
+
+The bleeding edge code is available via Git at
+git://github.com/ingydotnet/jemplate.git
+
+You can run the runtime tests directly from
+http://svn.jemplate.net/repo/trunk/tests/run/index.html or from the
+corresponding CPAN or JSAN directories.
+
+Jemplate development is being discussed at irc://irc.freenode.net/#jemplate
+
+If you want a committer bit, just ask ingy on the irc channel.
+
+# CREDIT
+
+This module is only possible because of Andy Wardley's mighty Template
+Toolkit. Thanks Andy. I will gladly give you half of any beers I
+receive for this work. (As long as you are in the same room when I'm
+drinking them ;)
+
+# AUTHORS
+
+Ingy döt Net <ingy@cpan.org>
+
+(Note: I had to list myself first so that this line would go into META.yml)
+
+Jemplate is truly a community authored project:
+
+Ingy döt Net <ingy@cpan.org>
+
+Tatsuhiko Miyagawa <miyagawa@bulknews.net>
+
+Yann Kerherve <yannk@cpan.org>
+
+David Davis <xantus@xantus.org>
+
+Cory Bennett <coryb@corybennett.org>
+
+Cees Hek <ceeshek@gmail.com>
+
+Christian Hansen
+
+David A. Coffey <dacoffey@cogsmith.com>
+
+Robert Krimen <robertkrimen@gmail.com>
+
+Nickolay Platonov <nickolay8@gmail.com>
View
31 dist.ini
@@ -0,0 +1,31 @@
+name = Jemplate
+author = Ingy döt Net <ingy@cpan.org>
+license = Perl_5
+copyright_holder = Ingy döt Net
+version = 0.27
+
+[@Basic]
+[OurPkgVersion]
+; [ChangesFromYaml] ; Changes file needs ♥
+[ReadmeFromPod]
+[MetaNoIndex]
+directory = examples
+
+[@Git]
+[GithubMeta]
+user = ingydotnet
+issues = 1
+
+[Prereqs]
+perl = v5.8.1
+File::Find::Rule = 0.30
+Template = 2.19
+
+[TestBaseIncluder]
+[PodSyntaxTests]
+
+[PruneFiles]
+filename = dist.ini
+filename = ReadMe.md
+filename = ToDo
+filename = js
View
4 lib/Jemplate.pm
@@ -10,14 +10,14 @@
# - Stardoc
# - Use TT:Simple in Makefiles
+# ABSTRACT: JavaScript Templating with Template Toolkit
package Jemplate;
-use 5.006001;
use strict;
use warnings;
use Template 2.14;
use Getopt::Long;
-our $VERSION = '0.27';
+# VERSION
use Jemplate::Parser;

0 comments on commit 0fc7577

Please sign in to comment.