Permalink
Browse files

Add export to html.

  • Loading branch information...
1 parent cdac283 commit 92a89922cf62a6fade1d202d151a2dd796ffd0a5 @KirillTemnov committed Mar 2, 2011
Showing with 30 additions and 3 deletions.
  1. +1 −1 .strack
  2. +16 −1 lib/export.coffee
  3. +13 −1 lib/util.coffee
View
@@ -4,7 +4,7 @@
"0c520fa874e0214d22e41463493a64ce": {"created":"2011-02-25T15:07:51.549Z","modified":"2011-02-25T15:25:32.825Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@todo +archive for tickets","id":"0c520fa874e0214d22e41463493a64ce","comments":[],"log":[],"state":"todo"},
"b90ea6db72184a5da1b5ba687ed1dfdc": {"created":"2011-02-25T15:08:11.777Z","modified":"2011-02-25T15:16:11.970Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@fixed Not print Tickets 0/0 if tracker is empty +log","id":"b90ea6db72184a5da1b5ba687ed1dfdc","comments":[],"log":[],"state":"fixed"},
"a2ed65e5c06cd611d8077b92982243ac": {"created":"2011-02-25T15:08:30.760Z","modified":"2011-02-25T17:01:39.254Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@done Create Readme.md","id":"a2ed65e5c06cd611d8077b92982243ac","comments":[],"log":[],"state":"done"},
-"220dd79504b4383bd6d10e28835c35fc": {"created":"2011-02-25T15:08:49.346Z","modified":"2011-02-28T18:42:30.641Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@todo +export to html\n","id":"220dd79504b4383bd6d10e28835c35fc","comments":[],"log":[],"state":"todo"},
+"220dd79504b4383bd6d10e28835c35fc": {"created":"2011-02-25T15:08:49.346Z","modified":"2011-03-02T11:01:57.358Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@done +export to html\n","id":"220dd79504b4383bd6d10e28835c35fc","comments":[{"date":"2011-03-02T11:01:45.104Z","author":{"user":"selead","email":"allselead@gmail.com"},"comment":"Create a basic html5 template\n","id":"57916e724c60cfb1fe075a8d4dbc7be7","sign":"7a2e34abcef12677b8dc93249fc819d1"}],"log":[],"state":"todo"},
"d9b76b4839b0662f7a242ddef9c1bbec": {"created":"2011-02-25T15:08:52.547Z","modified":"2011-03-02T10:16:47.698Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@done +export to org","id":"d9b76b4839b0662f7a242ddef9c1bbec","comments":[],"log":[],"state":"done"},
"9f7a1ccc1109ca37eff095e3151ed2c9": {"created":"2011-02-25T15:08:55.269Z","modified":"2011-03-01T20:37:24.283Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@done +export to txt","id":"9f7a1ccc1109ca37eff095e3151ed2c9","comments":[],"log":[],"state":"done"},
"bc7815df8b4b45efa9322e295b318ebb": {"created":"2011-02-25T15:09:13.697Z","modified":"2011-02-25T20:52:17.558Z","author":{"user":"selead","email":"allselead@gmail.com"},"text":"@fixed Update +usage message","id":"bc7815df8b4b45efa9322e295b318ebb","comments":[],"log":[],"state":"fixed"},
View
@@ -63,4 +63,19 @@ Export tracker to html file
@api public
###
exports.toHtml = (tracker, filename) ->
- "export to html"
+ out = '<html><head><meta charset="utf-8"><title>' +
+ "#{tracker.name || tracker.config.get('user') + '\'s project' &mdash config.get 'user'}" +
+ '</title><body><ul style="list-style:none;">\n'
+ for t in tracker._sortTickets()
+ [text, tags] = util.searchAndReplaceTags t.text, (tag) ->
+ "<a href=\"#\">#{tag}</a>"
+
+ text = text.replace /\n/g, "<br />"
+ if util.getState(t.text, tracker.config) in tracker.states.final
+ styles = 'style="color:grey"'
+ text = "<s>#{text}</s>"
+ else
+ styles = ""
+ out += "<li #{styles}>#{text} </li>\n"
+ out += "</ul>\n</body></html>\n"
+ fs.writeFileSync filename, out
View
@@ -559,4 +559,16 @@ If line longer, than length, do nothing
exports.makeLineLonger = (line, len=80, chr=" ") ->
while len > line.length
line += chr
- line
+ line
+
+exports.searchAndReplaceTags = (text, replaceFn, tagsRe=/(\+\S+)/g) ->
+ tags = []
+ result = text
+ match = text.match tagsRe
+ if match
+ for t in match
+ # todo add escape for other regexp characters
+ re = new RegExp t.replace( /\+/g, "\\+"), "g"
+ result = result.replace re, replaceFn t.substring 1
+ tags.push t.substring
+ [result, tags]

0 comments on commit 92a8992

Please sign in to comment.