From 13c76b52f109f10f1055d6cbeaaacbb0bb19a9c2 Mon Sep 17 00:00:00 2001 From: schodet Date: Thu, 6 Oct 2005 21:56:25 +0000 Subject: Ajout du filtre par responsable de tâche. Ajout de la sortie texte. --- p/tools/todo.html.tt | 8 ++++---- p/tools/todo.pl | 58 +++++++++++++++++++++++++++++++++++----------------- p/tools/todo.text.tt | 26 ++++++++++++++--------- 3 files changed, 59 insertions(+), 33 deletions(-) (limited to 'p') diff --git a/p/tools/todo.html.tt b/p/tools/todo.html.tt index fe25164..285c7e8 100644 --- a/p/tools/todo.html.tt +++ b/p/tools/todo.html.tt @@ -26,19 +26,19 @@ [% IF t.key %] [% IF t.value.value.exists ('text') %] prout - [% ELSE %] + [% ELSE +%]
  • [% t.key %]

  • - [% END %] + [%+ END %] [% ELSE %] [% PROCESS task tasks = t.value %] [% END %] [% END %] [% END %] - [% ELSE %] + [% ELSE +%]
  • Aucune Tache

  • - [% END %] + [%+ END %] [% END %] diff --git a/p/tools/todo.pl b/p/tools/todo.pl index 13be3cb..c0fed89 100644 --- a/p/tools/todo.pl +++ b/p/tools/todo.pl @@ -9,9 +9,9 @@ use Getopt::Long; # Parse a todo file and add tasks to \%todos. sub parse_todo { - my ($todos, $path, $file) = @_; + my ($todos, $path, $file, $filter) = @_; #print "$path...\n"; - my $owner; + my $owners; local $_; local *FILE; # Check for duplicates and create task list. @@ -26,10 +26,10 @@ sub parse_todo chomp; # Task line. /^([-+=x]) (?:\[(\d\d\/\d\d\/\d{4})\] |)(?:\(([^)]+)\) |)(.+)$/ and do { - my ($state, $deadline, $owner, $text) = - ($1, $2, $3 || $owner, $4); + my ($state, $deadline, $owners, $text) = + ($1, $2, $3 || $owners, $4); my @owners; - @owners = split /, */, $owner if defined $owner; + @owners = split /, */, $owners if defined $owners; # Read next lines. while () { @@ -41,17 +41,18 @@ sub parse_todo last; } # Add task. - push @$tasks, { + my %task = ( state => $state, deadline => $deadline, - owner => [ @owners ], - text => $text - }; + owners => [ @owners ], + text => $text, + ); + push @$tasks, \%task if &$filter (%task); last unless defined $_; redo; }; # Default owner line. - /^\(([^)]+)\)$/ and $owner = $1, next; + /^\(([^)]+)\)$/ and $owners = $1, next; # Subtask line. /^[-\w\d]+$/ and do { my $path = $path . '/' . $_; @@ -74,7 +75,7 @@ sub parse_todo # Read dir and parse each todo files it contains. sub parse_dir { - my ($todos, $path, $dir) = @_; + my ($todos, $path, $dir, $filter) = @_; local $_; local @_; local *DIR; @@ -89,22 +90,29 @@ sub parse_dir # Create empty hashes. $$todos{$_} ||= { } foreach @todofiles, @tododirs; # Process each todo files. - parse_todo ($$todos{$_}, "$path/$_", "$dir/$_.todo") foreach @todofiles; + parse_todo ($$todos{$_}, "$path/$_", "$dir/$_.todo", $filter) + foreach @todofiles; # Recurse into each dirs. - parse_dir ($$todos{$_}, "$path/$_", "$dir/$_") foreach @tododirs; + parse_dir ($$todos{$_}, "$path/$_", "$dir/$_", $filter) + foreach @tododirs; } # Output todo tree file. sub output_tree { - my ($d, $f, $t) = @_; + my ($config, $t) = @_; my $tt = new Template ({ - INCLUDE_PATH => $d, + INCLUDE_PATH => $$config{'template-dir'}, PRE_CHOMP => 1, POST_CHOMP => 1, INTERPOLATE => 1, }); - $tt->process ("todo.$f.tt", { 'tasks' => $t }) or die $tt->error; + $tt->process ('todo.' . $$config{'format'} . '.tt', { + 'tasks' => $t, + 'keep' => $$config{'keep-empty'}, + 'owner' => !defined $$config{'owner'}, + }) + or die $tt->error; } # Print short help. @@ -120,6 +128,8 @@ Options: -T, --template-dir=DIR Set the template directory (defaults to '.'). -f, --format=FORMAT Set the output format ('text' or 'html', defaults to 'text'). + -k, --keep-empty Keep empty sections. + -o, --owner=OWNER Output only task for OWNER -d, --dump Dump todo hash instead of normal output. -h, --help Print this help screen. EOF @@ -137,7 +147,9 @@ sub config 'todo-dir=s', 'template-dir|T=s', 'format=s', - 'dump', + 'keep-empty', + 'owner=s', + 'dump|d', 'help', ) or die; usage () and exit 0 if (exists ($config{help})); @@ -147,7 +159,15 @@ sub config my %todos; my %config = config (); -parse_dir (\%todos, '', $config{'todo-dir'}); +my $filter = sub { + my %t = @_; + if ($config{'owner'}) + { + return 0 unless grep { $_ eq $config{'owner'} } @{$t{'owners'}}; + } + 1; +}; +parse_dir (\%todos, '', $config{'todo-dir'}, $filter); if (exists ($config{'dump'})) { use Data::Dumper; @@ -155,5 +175,5 @@ if (exists ($config{'dump'})) } else { - output_tree ($config{'template-dir'}, $config{'format'}, \%todos); + output_tree (\%config, \%todos); } diff --git a/p/tools/todo.text.tt b/p/tools/todo.text.tt index 610b385..9982766 100644 --- a/p/tools/todo.text.tt +++ b/p/tools/todo.text.tt @@ -1,16 +1,22 @@ -[% BLOCK subtask %] -[% END %] - [% BLOCK task %] - [% FOREACH t = tasks.keys %] - [% IF t == '' %] - [% INCLUDE subtask FOREACH tasks.$t %] - [% ELSE %] -$indent$t +$indent${s.state} [%+ +"(${s.owners.join (', ')}) " IF s.owners.size && owner +%] +${s.text} +[%+ END %] + +[% BLOCK tasks %] + [% FOREACH t = tasks %] + [% IF t.value.size || keep %] + [% IF t.key %] +$indent${t.key} [%+ %] - [% INCLUDE task tasks = tasks.$t indent = "$indent " %] + [% INCLUDE tasks tasks = t.value indent = "$indent " %] + [% ELSE %] + [% PROCESS task FOREACH s = t.value %] + [% END %] [% END %] [% END %] [% END %] -[% INCLUDE task tasks = tasks indent = '' %] +[% INCLUDE tasks tasks = tasks indent = '' %] -- cgit v1.2.3