Commits

shl...@7081e830-ea04-0410-ae62-fb6148e2d9db  committed 194611c

Now the wml file is generated using Template Toolkit. Commited the other
changes.

  • Participants
  • Parent commits 9db2c76

Comments (0)

Files changed (4)

File xhtml/1.x/Install.bash

 #!/bin/bash
 
+perl compile.pl
 dest_dir="$HOME/apps/wml/xhtml/1.x/std/"
 mkdir -p "$dest_dir"
 cp std/toc/toc.wml "$dest_dir"

File xhtml/1.x/compile.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Template;
+
+my @files = ("std/toc/toc");
+
+sub get_file_mtime
+{
+    my $path = shift;
+
+    return (stat($path))[9];
+}
+
+foreach my $f (@files)
+{
+    my $wml_f = "$f.wml";
+    my $wml_source = "$wml_f.tt2";
+    my $src_mtime = get_file_mtime($wml_source);
+    my $dest_mtime = get_file_mtime($wml_f);
+    if ((! -e $wml_f) ||
+        ($src_mtime > $dest_mtime)
+       )
+    {
+        my $t = Template->new();
+        $t->process($wml_source, +{}, $wml_f);
+    }
+}
+

File xhtml/1.x/std/toc/toc.wml

-## 
-##  wml::xhtml1::std::toc - Table of Conents Generator
-##  Copyright (c) 2005 Shlomi Fish
-##  Distributed under the MIT X11 License
-##  http://www.opensource.org/licenses/mit-license.php
-
-<:{
-use HTML::TokeParser::Simple;
-use vars qw($wml_xhtml_std_toc_section);
-$wml_xhtml_std_toc_section = [];
-}:>
-
-<define-tag h2 whitespace="delete" endtag="required">
-<preserve id />
-<h2*<attributes-quote %attributes /> >%body</h2*>
-<set-var %attributes />
-<:{
-
-my $id = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
-<get-var id />
-EOCMMFINVBOWVNIANFINLNGINWNOF
-
-my $tag_body = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
-%body
-EOCMMFINVBOWVNIANFINLNGINWNOF
-
-chomp($id);
-chomp($tag_body);
-my $parser = HTML::TokeParser::Simple->new(\$tag_body);
-my $my_body;
-while ($token = $parser->get_token())
-{
-    if ($token->is_start_tag("a") || $token->is_end_tag("a"))
-    {
-        # Do nothing - we throw away links.
-    }
-    else
-    {
-        $my_body .= $token->as_is();
-    }
-}
-push @$wml_xhtml_std_toc_section, { 'id' => $id, 'body' => $my_body, 'subs' => [],};
-}:>
-<restore id />
-</define-tag>
-
-<define-tag h3 whitespace="delete" endtag="required">
-<preserve id />
-<h3*<attributes-quote %attributes /> >%body</h3*>
-<set-var %attributes />
-<:{
-
-my $id = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
-<get-var id />
-EOCMMFINVBOWVNIANFINLNGINWNOF
-
-my $tag_body = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
-%body
-EOCMMFINVBOWVNIANFINLNGINWNOF
-
-chomp($id);
-chomp($tag_body);
-
-my $parser = HTML::TokeParser::Simple->new(\$tag_body);
-my $my_body;
-while ($token = $parser->get_token())
-{
-    if ($token->is_start_tag("a") || $token->is_end_tag("a"))
-    {
-        # Do nothing - we throw away links.
-    }
-    else
-    {
-        $my_body .= $token->as_is();
-    }
-}
-push @{$wml_xhtml_std_toc_section->[-1]->{subs}}, { 'id' => $id, 'body' => $my_body, 'subs' => [],};
-}:>
-<restore id />
-</define-tag>
-
-<define-tag toc>
-{#WML_XSTD_TOC_ToC#}
-</define-tag>
-
-<define-tag toc_finale>
-<:{
-sub myfunc
-{
-my $elem = shift;
-return ("<li>", "<a href=\"#" . $elem->{id} . "\">", $elem->{body}, "</a>",
-        (@{$_->{subs}} ? 
-            ("<br />", "<ul>", 
-                (map { myfunc($_)
-                    }
-                @{$_->{subs}}),
-                "</ul>",
-            ) :
-            ()
-        ),
-        "</li>");
-}
-END 
-{
-my $text;
-$text = join ("\n", 
-    "<ul>",
-    (map { myfunc($_) } @$wml_xhtml_std_toc_section),
-    "</ul>",
-    );
-print "{#WML_XSTD_TOC_ToC#:$text:##}";
-}
-}:>
-</define-tag>
-
-<toc_finale />
-

File xhtml/1.x/std/toc/toc.wml.tt2

+## 
+##  wml::xhtml1::std::toc - Table of Conents Generator
+##  Copyright (c) 2005 Shlomi Fish
+##  Distributed under the MIT X11 License
+##  http://www.opensource.org/licenses/mit-license.php
+
+<:{
+use HTML::TokeParser::Simple;
+use vars qw($wml_xhtml_std_toc_section);
+$wml_xhtml_std_toc_section = { 'subs' => [] };
+}:>
+[% SET inner_refs = "" %]
+[% FOREACH index IN [2,3,4,5,6] %]
+<define-tag h[% index %] whitespace="delete" endtag="required">
+<preserve id />
+<h[% index %]*<attributes-quote %attributes /> >%body</h[% index %]*>
+<set-var %attributes />
+<:{
+
+my $id = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
+<get-var id />
+EOCMMFINVBOWVNIANFINLNGINWNOF
+
+my $tag_body = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
+%body
+EOCMMFINVBOWVNIANFINLNGINWNOF
+
+chomp($id);
+chomp($tag_body);
+my $parser = HTML::TokeParser::Simple->new(\$tag_body);
+my $my_body;
+while ($token = $parser->get_token())
+{
+    if ($token->is_start_tag("a") || $token->is_end_tag("a"))
+    {
+        # Do nothing - we throw away links.
+    }
+    else
+    {
+        $my_body .= $token->as_is();
+    }
+}
+push @{$wml_xhtml_std_toc_section[% inner_refs %]->{'subs'}}, { 'id' => $id, 'body' => $my_body, 'subs' => [],};
+}:>
+<restore id />
+</define-tag>
+[% SET inner_refs = inner_refs _ "->{'subs'}->[-1]" %]
+[% END %]
+
+<define-tag toc>
+{#WML_XSTD_TOC_ToC#}
+</define-tag>
+
+<define-tag toc_finale>
+<:{
+sub myfunc
+{
+my $elem = shift;
+return ("<li>", "<a href=\"#" . $elem->{id} . "\">", $elem->{body}, "</a>",
+        (@{$_->{subs}} ? 
+            ("<br />", "<ul>", 
+                (map { myfunc($_)
+                    }
+                @{$_->{subs}}),
+                "</ul>",
+            ) :
+            ()
+        ),
+        "</li>");
+}
+END 
+{
+my $text;
+$text = join ("\n", 
+    "<ul>",
+    (map { myfunc($_) } @{$wml_xhtml_std_toc_section->{subs}}),
+    "</ul>",
+    );
+print "{#WML_XSTD_TOC_ToC#:$text:##}";
+}
+}:>
+</define-tag>
+
+<toc_finale />
+