#### -*- coding: utf-8 -*-
## pylint: disable-msg=W0201
## -----------------------------------------------------------------------------
## Getting Things Gnome! - a personal organizer for the GNOME desktop
## Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
##
## 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 3 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, see <http://www.gnu.org/licenses/>.
## -----------------------------------------------------------------------------
##
##So you want to write your own template for Getting things GNOME?
## Read template_simple.html for a quick tutorial, this one is a bit 
## harder to understand, as it cannot be indented
##
##
##
#import re
#def remove_html_tags($data):
##Removing subtask anchor points
#set $p = $re.compile(r'^.*<subtask>[0-9]*@[0-9]*</subtask>\n*',$re.MULTILINE)
#set $data = $p.sub('', $data)
##Removing tags
#set $p = $re.compile(r'@[a-z,0-9]*',$re.IGNORECASE)
#set $data = $p.sub('', $data)
##Removing <something> and </something>
#set $p = $re.compile(r'<.*?>')
#set $data = $p.sub('', $data)
##Removing lines only with commas (tags lines)
#set $p = $re.compile(r'^[\s,\,]*$')
#return $p.sub('', $data)
#end def
##
##
#import htmllib
#def html_unescape($text):
#set $p = $htmllib.HTMLParser(None)
$p.save_bgn()
$p.feed($text)
#return $p.save_end()
#end def
##
##
#def task_template($task, $space_num):
#set spaces = " " * $space_num
#if $task.has_title
$html_unescape($task.title)#slurp 
#if $task.has_tags
(#slurp 
#for $tag in $task.tags:
$tag #slurp
#end for
)#slurp
#if $task.has_due_date
 due: $task.due_date
#end if
#end if
#end if

#if $task.has_text
#set $text =$remove_html_tags($task.text)
#set $text = $html_unescape($text)
##
## Formatting the text to be shorter than 80 chars
##
#while $len($text)>0:
#set $text = $text.lstrip('\n')
#if $len($text)<=80:
#set next_len = $len($text)
#else:
#set next_len = max([80 - $space_num,50])
#end if
#set $next_cr = $text.find('\n')
#if $next_cr < $next_len and $next_cr >0:
$spaces#slurp
 $text[:$next_cr]
#set $text = $text[$next_cr:]
#else:
$spaces#slurp
 $text[:$next_len]
#set $text = $text[$next_len:]
#end if
#end while
##
##
##
#end if
##
#if $task.has_subtasks
#for $subtask in $task.subtasks:
$spaces - $task_template($subtask, $space_num + 2)
#end for
#end if
#end def
##
##
##
TODO LIST:
#for $task in $tasks:
* $task_template($task, 3)
#end for
##
##
