diff --git a/src/custom.cpp b/src/custom.cpp index d0f766620..3df210391 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -224,9 +224,14 @@ int runCustomReport ( table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::left); + std::string value; int row = 0; foreach (task, tasks) - table.addCell (row++, columnCount, task->get ("project")); + { + value = task->get ("project"); + context.hooks.trigger ("format-project", "project", value); + table.addCell (row++, columnCount, value); + } } else if (*col == "priority") @@ -417,6 +422,7 @@ int runCustomReport ( { Date dt (::atoi (created.c_str ())); age = formatSeconds ((time_t) (now - dt)); + context.hooks.trigger ("format-age", "age", age); table.addCell (row, columnCount, age); } } @@ -438,6 +444,7 @@ int runCustomReport ( { Date dt (::atoi (created.c_str ())); age = formatSecondsCompact ((time_t) (now - dt)); + context.hooks.trigger ("format-age_compact", "age_compact", age); table.addCell (row, columnCount, age); } } @@ -467,6 +474,7 @@ int runCustomReport ( { task->getTags (all); join (tags, " ", all); + context.hooks.trigger ("format-tags", "tags", tags); table.addCell (row++, columnCount, tags); } } @@ -477,9 +485,14 @@ int runCustomReport ( table.setColumnWidth (columnCount, Table::flexible); table.setColumnJustification (columnCount, Table::left); + std::string desc; int row = 0; foreach (task, tasks) - table.addCell (row++, columnCount, task->get ("description")); + { + desc = task->get ("description"); + context.hooks.trigger ("format-description_only", "description_only", desc); + table.addCell (row++, columnCount, desc); + } } else if (*col == "description") @@ -488,9 +501,14 @@ int runCustomReport ( table.setColumnWidth (columnCount, Table::flexible); table.setColumnJustification (columnCount, Table::left); + std::string desc; int row = 0; foreach (task, tasks) - table.addCell (row++, columnCount, getFullDescription (*task, report)); + { + desc = getFullDescription (*task, report); + context.hooks.trigger ("format-description", "description", desc); + table.addCell (row++, columnCount, desc); + } } else if (*col == "recur") diff --git a/src/tests/hook.format-age.t b/src/tests/hook.format-age.t new file mode 100755 index 000000000..b1e0df4e0 --- /dev/null +++ b/src/tests/hook.format-age.t @@ -0,0 +1,82 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.format-age=" . $ENV{'PWD'} . "/hook:age\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +# Create the hook functions. +if (open my $fh, '>', 'hook') +{ + print $fh "function age (name, value)\n", + " value = '<' .. value .. '>'\n", + " return value, 0, nil\n", + "end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + qx{../task rc:hook.rc add foo}; + sleep 1; + $output = qx{../task rc:hook.rc list}; + + like ($output, qr/<\d\ssec>/, 'format-age hook age -> '); +} +else +{ + pass ('format-age hook age -> - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.format-age_compact.t b/src/tests/hook.format-age_compact.t new file mode 100755 index 000000000..409970f13 --- /dev/null +++ b/src/tests/hook.format-age_compact.t @@ -0,0 +1,83 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.format-age_compact=" . $ENV{'PWD'} . "/hook:age\n", + "report.list.columns=id,project,priority,due,active,age_compact,description\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +# Create the hook functions. +if (open my $fh, '>', 'hook') +{ + print $fh "function age (name, value)\n", + " value = '<' .. value .. '>'\n", + " return value, 0, nil\n", + "end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + qx{../task rc:hook.rc add foo}; + sleep 1; + $output = qx{../task rc:hook.rc list}; + + like ($output, qr/<\ds>/, 'format-age_compact hook age -> '); +} +else +{ + pass ('format-age_compact hook age -> - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.format-description.t b/src/tests/hook.format-description.t new file mode 100755 index 000000000..898a45605 --- /dev/null +++ b/src/tests/hook.format-description.t @@ -0,0 +1,81 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.format-description=" . $ENV{'PWD'} . "/hook:description\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +# Create the hook functions. +if (open my $fh, '>', 'hook') +{ + print $fh "function description (name, value)\n", + " value = '<' .. value .. '>'\n", + " return value, 0, nil\n", + "end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc ls}; + + like ($output, qr//, 'format-description hook foo -> '); +} +else +{ + pass ('format-description hook foo -> - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.format-description_only.t b/src/tests/hook.format-description_only.t new file mode 100755 index 000000000..4d1ed24c4 --- /dev/null +++ b/src/tests/hook.format-description_only.t @@ -0,0 +1,82 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.format-description_only=" . $ENV{'PWD'} . "/hook:description_only\n", + "report.ls.columns=id,project,priority,description_only\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +# Create the hook functions. +if (open my $fh, '>', 'hook') +{ + print $fh "function description_only (name, value)\n", + " value = '<' .. value .. '>'\n", + " return value, 0, nil\n", + "end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc ls}; + + like ($output, qr//, 'format-description_only hook foo -> '); +} +else +{ + pass ('format-description_only hook foo -> - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.format-project.t b/src/tests/hook.format-project.t new file mode 100755 index 000000000..6c2049f8e --- /dev/null +++ b/src/tests/hook.format-project.t @@ -0,0 +1,81 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.format-project=" . $ENV{'PWD'} . "/hook:project\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +# Create the hook functions. +if (open my $fh, '>', 'hook') +{ + print $fh "function project (name, value)\n", + " value = '<' .. value .. '>'\n", + " return value, 0, nil\n", + "end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + qx{../task rc:hook.rc add foo project:bar}; + $output = qx{../task rc:hook.rc list}; + + like ($output, qr//, 'format-project hook project -> '); +} +else +{ + pass ('format-project hook project -> - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.format-tags.t b/src/tests/hook.format-tags.t new file mode 100755 index 000000000..3f87504e2 --- /dev/null +++ b/src/tests/hook.format-tags.t @@ -0,0 +1,81 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'hook.rc') +{ + print $fh "data.location=.\n", + "hooks=on\n", + "hook.format-tags=" . $ENV{'PWD'} . "/hook:tags\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +# Create the hook functions. +if (open my $fh, '>', 'hook') +{ + print $fh "function tags (name, value)\n", + " value = '<' .. value .. '>'\n", + " return value, 0, nil\n", + "end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + qx{../task rc:hook.rc add foo +t1 +t2}; + $output = qx{../task rc:hook.rc long}; + + like ($output, qr//, 'format-tags hook t1 t2 -> '); +} +else +{ + pass ('format-tags hook t1 t2 -> - skip: no Lua support'); +} + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; +