Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added bin/tte, updated TODO, added Status docs, misc tweaks

  • Loading branch information...
commit 1e867fc1d1aca759ab8f568bd7c2e9a06d9ba9b4 1 parent 8881d2d
@abw authored
View
16 bin/tt3
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+#
+# Command line application driver for TT3.
+#
+# Written by Andy Wardley http://wardley.org/
+#
+# December 2009
+#
+
+use lib '/home/abw/projects/badger/lib'; # abw testing
+use Badger; # lib => '../lib'; # just while testing
+use Template::TT3::App;
+
+Template::TT3::App
+ ->args(@ARGV)
+ ->run;
View
4 bin/tt3-html
@@ -15,8 +15,10 @@ use Template::TT3::HTML;
use Template::TT3::Template;
use constant TEMPLATE => 'Template::TT3::Template';
+$| = 1;
+
my $file = shift || die usage();
-my $template = Template3->template( file => $file );
+my $template = Template3->template($file);
my $tree = $template->tree;
my $source = $template->tokens->view_HTML;
my $vars = $template->vars_HTML;
View
236 docs/pod/Template/TT3/Status.pod
@@ -0,0 +1,236 @@
+=head1 NAME
+
+Template::TT3::Status - TT3 Development Status
+
+=head1 INTRODUCTION
+
+This document contains information relating to the current development status
+of the Template Toolkit.
+
+TT3 is still at the pre-alpha stage. Nothing is guaranteed to work at present
+(although most things do). You should I<not> use it any any production code
+unless you're extremely brave or somewhat foolhardy.
+
+Although most of the code is working and tested (albeit incompletely),
+the documentation is mostly incomplete or completely missing.
+
+=head1 WHAT'S HAPPENING RIGHT NOW?
+
+I've started working through the element modules to clean them up, thoroughly
+test and documentation them, and generally get things ready for a first
+release.
+
+=head1 ELEMENT MODULES
+
+Elements are the basic nodes that comprise a parsed template tree. They're
+rather like DOM elements except that they can generate dynamic content. So
+they're more like opcodes, or perhaps somewhere in between.
+
+I've begun the process of working through the element modules doing a final
+cleanup and adding documentation. Modules marked with an C<[X]> in the
+lists below have been done and should be ready for release. Those marked
+with C<[ ]> are eagerly awaiting their turn.
+
+=head2 Old Elements Libraries
+
+I started off writing a smaller number of C<Template::TT3::Elements::*>
+libraries that included many different element class definitions. However, it
+quickly became difficult to manage. Most elements have now been moved to
+individual module files. This makes it easier to subclass from existing
+element module (otherwise you have to know which library module the base class
+element is in and ensure that it has been pre-loaded). It also gives us
+somewhere to put the documentation for each element class instead of cramming
+it all into one monstrous file.
+
+These are the current element library modules. This list should eventually
+dwindle to nothing as they are split up and replaced by individual element
+modules.
+
+ [ ] Template::TT3::Element::Boolean
+ [ ] Template::TT3::Element::Core
+ [ ] Template::TT3::Element::Number
+ [ ] Template::TT3::Element::Operator
+ [ ] Template::TT3::Element::Punctuation
+ [ ] Template::TT3::Element::Structure
+ [ ] Template::TT3::Element::Text
+ [ ] Template::TT3::Element::Whitespace
+
+=head2 Core Elements
+
+ [ ] Template::TT3::Element::Block
+ [ ] Template::TT3::Element::Filename
+ [ ] Template::TT3::Element::Keyword
+ [ ] Template::TT3::Element::Literal
+ [ ] Template::TT3::Element::Sub
+ [ ] Template::TT3::Element::Text
+ [ ] Template::TT3::Element::Word
+
+=head2 Variable Elements
+
+These elements are used to represent variables and operations relating to
+variables (e.g. application of a function bound to a variable).
+
+ [ ] Template::TT3::Element::Variable::Apply
+ [ ] Template::TT3::Element::Variable
+
+=head2 Construct
+
+These elements implement data constructs, including hash definitions, list
+definitions and parenthesised expressions. e.g.
+
+ [% list = [10, 20, 30] %]
+ [% hash = {a=10, b=20, c=30} %]
+
+The modules implementing constructs are:
+
+ [ ] Template::TT3::Element::Construct::Args
+ [ ] Template::TT3::Element::Construct::Hash
+ [ ] Template::TT3::Element::Construct::List
+ [ ] Template::TT3::Element::Construct::Parens
+ [ ] Template::TT3::Element::Construct
+
+=head2 Operators
+
+These elements implement various operators of the language.
+
+ [ ] Template::TT3::Element::Operator::Assign
+ [ ] Template::TT3::Element::Operator::Dot
+ [ ] Template::TT3::Element::Operator::Pair
+ [ ] Template::TT3::Element::Operator::Ternary
+
+=head2 Sigils
+
+These elements implement the sigil prefix operators: C<$>, C<@> and C<%>.
+
+ [ ] Template::TT3::Element::Sigil
+ [ ] Template::TT3::Element::Sigil::Hash
+ [ ] Template::TT3::Element::Sigil::Item
+ [ ] Template::TT3::Element::Sigil::List
+
+=head2 Commands
+
+These elements implement the runtime command keywords.
+
+ [ ] Template::TT3::Element::Command::As
+ [ ] Template::TT3::Element::Command::Block
+ [ ] Template::TT3::Element::Command::Decode
+ [ ] Template::TT3::Element::Command::Do
+ [ ] Template::TT3::Element::Command::Dot
+ [ ] Template::TT3::Element::Command::Else
+ [ ] Template::TT3::Element::Command::Elsif
+ [ ] Template::TT3::Element::Command::Encode
+ [ ] Template::TT3::Element::Command::Fill
+ [ ] Template::TT3::Element::Command::For
+ [ ] Template::TT3::Element::Command::Hello
+ [ ] Template::TT3::Element::Command::If
+ [ ] Template::TT3::Element::Command::Include
+ [ ] Template::TT3::Element::Command::Into
+ [ ] Template::TT3::Element::Command::Is
+ [ ] Template::TT3::Element::Command::Just
+ [ ] Template::TT3::Element::Command::Raw
+ [ ] Template::TT3::Element::Command::Slot
+ [ ] Template::TT3::Element::Command::Sub
+ [ ] Template::TT3::Element::Command::Unless
+ [ ] Template::TT3::Element::Command::With
+ [ ] Template::TT3::Element::Command::Wrapper
+
+=head2 Controls
+
+There's some work needed here to tidy up the command loading code. We should
+support command libraries so that we can merge the current (temporary)
+L<HTML_CMDS|Template::TT3::Element::Template::TT3::Element::Control::HtmlCmds> into
+L<COMMANDS|Template::TT3::Element::Template::TT3::Element::Control::Commands>.
+
+e.g.
+
+ [? COMMANDS HTML.ul HTML.li HTML.div ?]
+ [? COMMANDS HTML.['ul' 'li' 'div'] ?]
+ [? COMMANDS HTML.{ul li div} ?]
+
+These are the current modules implementing compile time controls:
+
+ [ ] Template::TT3::Element::Control::Commands
+ [ ] Template::TT3::Element::Control::Html
+ [ ] Template::TT3::Element::Control::HtmlCmds
+ [ ] Template::TT3::Element::Control::Meta
+ [ ] Template::TT3::Element::Control::Tags
+
+
+=head2 Mixin Roles
+
+These elements define roles that other elements can mix in to add
+functionality. They need organising into a proper hierarchy roughly
+corresponding to the methods that they implement. e.g.
+
+ Template::TT3::Element::Role::Expr::Args # parse_expr() reads args
+ Template::TT3::Element::Role::Infix::Args # parse_infix() reads args
+
+The badly named C<as> import hook defined by C<Template::TT3::Class> should
+be renamed (it's a throwback to a time when the C<parse_XXX()> methods were
+called C<as_XXX()> so it made more sense then). In fact, it's probably
+worth adding a new L<Template:TT3::Element::Class> module specialised to
+the task of creating element modules.
+
+ use Template::TT3::Element::Class
+ expr => 'args', # adds T~Role::Expr::Args
+ infix => 'args'; # adds T~Role::Infix::Args
+
+These are the modules as they currently stand:
+
+ [ ] Template::TT3::Element::Role::ArgsBlockExpr
+ [ ] Template::TT3::Element::Role::ArgsExpr
+ [ ] Template::TT3::Element::Role::Block
+ [ ] Template::TT3::Element::Role::BlockExpr
+ [ ] Template::TT3::Element::Role::ExprBlockExpr
+ [ ] Template::TT3::Element::Role::Filename
+ [ ] Template::TT3::Element::Role::NameBlockExpr
+ [ ] Template::TT3::Element::Role::NameExpr
+ [ ] Template::TT3::Element::Role::NullExpr
+ [ ] Template::TT3::Element::Role::Pair
+
+=head2 WTF Elements
+
+These are the elements that I'm not sure about. Some are junk that was thrown
+together for testing and are no longer required. Some have been deprecated or
+replaced but not yet deleted. Others I've just put here to remind me to look
+at them.
+
+ [ ] Template::TT3::Element::HTML::Table
+ [ ] Template::TT3::Element::HTML
+
+=head1 Other Modules
+
+Until I get a chance to properly organise a list of the other modules, I'll
+just dump everything else here.
+
+The following modules are believed to be complete, clean, tested and
+documented.
+
+ [X] Template::TT3::Factory
+ [X] Template::TT3::Factory::Class
+ [X] Template::TT3::Engines
+ [X] Template::TT3::Dialects
+ [X] Template::TT3::Providers
+
+=head1 AUTHOR
+
+Andy Wardley L<http://wardley.org/>
+
+=head1 COPYRIGHT
+
+Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.
+
+This module is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
+
+# Local Variables:
+# mode: perl
+# perl-indent-level: 4
+# indent-tabs-mode: nil
+# End:
+#
+# vim: expandtab shiftwidth=4:
+
+
View
59 docs/pod/Template/TT3/TODO.pod
@@ -6,8 +6,39 @@ Template::TT3::TODO - TT3 To-Do List
This is the To-Do list for TT3. It is incomplete and in no particular order.
+Please also consult L<Template::TT3::Status> which summarises the current
+status of TT3 and lists the various modules that are done, doing and todo.
+
=head1 Language Elements
+There are some fundamental issues relating to elements that need to be
+addressed. Most importantly, the current approach for determining if an
+element should generate output is incomplete. At present, an assignment
+inside a block (e.g. if, for, etc) will not have its output suppressed.
+
+The C<value()> method returns the value of an expression (which for an
+assignment will be the value of the RHS. The C<text()> method does the
+same thing but (possibly) with optional processing. In the case of an
+assignment, the C<text()> method suppresses the output. The C<text()>
+method will (or should) also complain if the value is undefined.
+
+However, elements that contain a block always evaluate the content by calling
+the C<value()> method on the child elements. In essence, these directives fail
+to propagate to their children the fact that they're being called in text
+context. The obvious solution is to add the additional methods that allow
+a block to be called in value or text context. However, it's not as simple
+as that. We also want to support other modes like HTML. Again, a call to
+C<html()> on a parent element should call the corresponding C<html()> method
+on its children. Adding a third method to every block directive is a
+possibility, but it's starting to smell of code bloat. A better solution
+would be to find some way to implement this generically.
+
+Another issue relating to the above is that too many C<value()> methods
+are throwing errors on undefined values. This is probably due to the fact
+that many elements simple alias C<values()> to C<text()> or rely on the
+default implementation inherited from the L<Template::TT3::Element> base
+class.
+
=head2 Loop Iterator
There's no equivalent of TT2's 'loop' iterator. I want to have a little
@@ -216,6 +247,7 @@ attaching to a prototype hub. I'm concerned that creating a "leaf node"
template for temporary use in a subroutine might pull the whole framework
into persistence.
+
=head1 Template Services
I'm not sure about the service pipeline architecture as it stands. On one
@@ -277,22 +309,20 @@ headers, footers, etc., based on certain conditions (which would be the
hard bit to make generic). A good start would be to demonstrate a simple
CODE ref that does this.
-=head2 Other Services
-
-Other services that may be worth investigating are timers, debug controls,
-sitemap, etc.
+=head2 Environment Service
+The environment service is a quick hack to explore the kind of things that
+can be done when you can easily change the environment (e.g. changing or
+removing the layout template based on file extension so that .css and .js
+files get passed through without HTML headers, and so on).
-=head1 Final Cleanup
+It would probably be better to pass the C<env> variable to the C<before>
+template and kill two birds with one stone.
-The following modules are believed to be complete, clean, tested and
-documented.
+=head2 Other Services
- Template::TT3::Factory
- Template::TT3::Factory::Class
- Template::TT3::Engines
- Template::TT3::Dialects
- Template::TT3::Providers
+Other services that may be worth investigating are timers, debug controls,
+sitemap, etc.
=head1 AUTHOR
@@ -305,6 +335,11 @@ Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
+=head1 SEE ALSO
+
+L<Template::TT3::Status> which summarises the current status of TT3 and
+lists the component modules that are done, doing and todo.
+
=cut
# Local Variables:
View
92 html/hello.html
@@ -1,40 +1,68 @@
<html>
<head>
- <title>TT3 Template Tokens: examples/hello.tt3</title>
- <style>
-div.template {
- font-family: Courier, monospace;
- font-size: 14px;
- color: #444;
-}
+ <title>TT3 Template Tree: examples/hello.tt3</title>
+ <link rel="stylesheet" type="text/css" href="tt3.css">
+ <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
+ <script type="text/javascript" src="tt3.js"></script>
-span.text {
- color: #aaf;
-}
-
-span.keyword {
- color: #a44;
-}
-
-span.word {
- color: #4a4;
-}
-
-span.whitespace,
-span.comment {
- color: #888;
-}
-
-span.tag_start,
-span.tag_end {
- color: #44a;
-}
- </style>
</head>
<body>
- <div class="template tt3">
-<span class="text">Hello </span><span class="tag_start">[%</span><span class="whitespace"> </span><span class="word">name</span><span class="whitespace"> </span><span class="binop">or</span><span class="whitespace"> </span><span class="squote">'World'</span><span class="whitespace"> </span><span class="tag_end">%]</span><span class="text">!
-</span>
+ <h1>TT3: examples/hello.tt3</h1>
+
+ <div class="tabset" id="tabset">
+ <ul class="tabs">
+ <li class="warm"><a href="#source">Source</a></li>
+ <li><a href="#tokens">Tokens</a></li>
+ <li><a href="#tree">Tree</a></li>
+ <li><a href="#vars">Variables</a></li>
+ <li><a href="#output">Output</a></li>
+ </ul>
+ <div class="panels">
+ <div class="panel warm" id="source">
+ <h2>Template Source</h2>
+ <div class="content">
+<span class="text">Hello </span><span class="tag"><span class="tag_start">[%</span><span class="whitespace"> </span><span class="variable">name</span><span class="whitespace"> </span><span class="binary">or</span><span class="whitespace"> </span><span class="squote">'World'</span><span class="whitespace"> </span><span class="tag_end">%]</span></span><span class="text">!
+</span><span class="eof">--EOF--</span>
+ </div>
+ </div>
+ <div class="panel" id="tokens">
+ <h2>Source Tokens</h2>
+ <div class="content">
+<div class="text element"><div class="head"><span class="info type">text</span><span class="info posn">@0</span><span class="source">Hello </span></div></div><div class="tag_start element"><div class="head"><span class="info type">tag_start</span><span class="info posn">@6</span><span class="source">[%</span></div></div><div class="whitespace element"><div class="head"><span class="info type">whitespace</span><span class="info posn">@8</span><span class="source"> </span></div></div><div class="variable element"><div class="head"><span class="info type">variable</span><span class="info posn">@9</span><span class="source">name</span></div></div><div class="whitespace element"><div class="head"><span class="info type">whitespace</span><span class="info posn">@13</span><span class="source"> </span></div></div><div class="binary operator element"><div class="head"><span class="info type">binary operator</span><span class="info posn">@14</span><span class="source">or</span></div></div><div class="whitespace element"><div class="head"><span class="info type">whitespace</span><span class="info posn">@16</span><span class="source"> </span></div></div><div class="squote string element"><div class="head"><span class="info type">squote string</span><span class="info posn">@17</span><span class="source">'World'</span></div></div><div class="whitespace element"><div class="head"><span class="info type">whitespace</span><span class="info posn">@24</span><span class="source"> </span></div></div><div class="tag_end element"><div class="head"><span class="info type">tag_end</span><span class="info posn">@25</span><span class="source">%]</span></div></div><div class="text element"><div class="head"><span class="info type">text</span><span class="info posn">@27</span><span class="source">!\n</span></div></div><div class="eof element"><div class="head"><span class="info type">eof</span><span class="info posn">@29</span><span class="source"></span></div></div>
+ </div>
+ </div>
+ <div class="panel" id="tree">
+ <h2>Parse Tree</h2>
+ <div class="content">
+<div class="block"><div class="text element"><div class="head"><span class="info type">text</span><span class="info posn">@0</span><span class="source">Hello </span></div></div>
+<div class="binary expr element"><div class="head"><span class="info type">binary expr</span><span class="info posn">@14</span><span class="source">name or 'World'</span></div><div class="body"><div class="lhs "><div class="variable element element"><div class="head"><span class="info type">variable element</span><span class="info posn">@9</span><span class="source">name</span></div></div></div><div class="operator element">or</div><div class="rhs "><div class="squote string element element"><div class="head"><span class="info type">squote string element</span><span class="info posn">@17</span><span class="source">'World'</span></div></div></div></div></div>
+<div class="text element"><div class="head"><span class="info type">text</span><span class="info posn">@27</span><span class="source">!\n</span></div></div></div>
+ </div>
+ </div>
+ <div class="panel" id="vars">
+ <h2>Variables Used</h2>
+ <div class="content">
+<div class="variable element"><div class="head">name</div><div class="body"><div class="uses"><span class="branch">Uses</span><div class="block"><div class="element"><div class="head"><span class="info line">@ line 1</span><span class="source">Hello [% <span class="used_here">name</span> or 'World' %]!</span></div></div></div></div></div></div>
+ </div>
+ </div>
+ <div class="panel" id="output">
+ <h2>Generated Output</h2>
+ <div class="content">
+Hello World!
+
+ </div>
+ </div>
+ </div>
</div>
</body>
+ <script type="text/javascript">
+ $(document).ready(
+ function() {
+ $('#tabset').tt3_tabset();
+ $('#tree').tt3_tree();
+ $('#vars').tt3_tree();
+ }
+ );
+ </script>
</html>
+
View
21 t/expressions/hash.t
@@ -15,7 +15,7 @@ use Badger
lib => '../../lib';
use Template::TT3::Test
- tests => 13,
+ tests => 14,
debug => 'Template::TT3::Element::Construct::Hash
Template::TT3::Element::Construct::List
Template::TT3::Element::Sigil::Hash',
@@ -173,6 +173,25 @@ hash.keys.sort.join ': ' hash.twenty
<ERROR:Cannot make pairs from an odd number (1) of items: twenty>
#twenty: 20
+-- test nested hash definitions --
+questions = [
+ { title = 'Date of Birth' }
+ { title = 'Date of Death' }
+ { title = 'Partner' }
+ { title = 'Children'
+ answers = [
+ { text = 'Alex, Clint &amp; Matthew'
+ added = 'Frances, Julian &amp; Miles'
+ }
+ ]
+ }
+ { title = 'Grandchildren' }
+ { title = 'Mother' }
+ { title = 'Fother' }
+]
+questions.size
+-- expect --
+7
__END__
Please sign in to comment.
Something went wrong with that request. Please try again.