Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring of util.coffee

  • Loading branch information...
commit dbd1b7e08000c7449fdaa331b9b336b01d21f8d4 1 parent 92a8992
@KirillTemnov authored
Showing with 13 additions and 23 deletions.
  1. +1 −1  lib/export.coffee
  2. +12 −22 lib/util.coffee
View
2  lib/export.coffee
@@ -39,7 +39,7 @@ exports.toOrg = (tracker, filename) ->
out += "\n#+AUTHOR: #{tracker.config.get 'user'}\n#+EMAIL: #{tracker.config.get 'email'}\n"
out +="\n\n* #{tracker.name || tracker.config.get('user') + '\'s project'}[/]\n"
for t in tracker._sortTickets()
- [text, tags] = util.searchAndDeactivateTags t.text, ""
+ [text, tags] = util.searchAndReplaceTags t.text, (tag) -> tag
text = text.replace('@' + t.state, '').replace /\n/g, '\n '
text = text.split "\n"
firstLine = text[0]
View
34 lib/util.coffee
@@ -526,27 +526,6 @@ exports.colorizeCommentNumber = (num, id, len=12) ->
return "#{num} #{id}"
###
-Search tags in text and remove tag prefixes
-
-@param {String} text Text with tags
-@param {String} tagPrefix Tag prefix. All tags in result will have this prefix. Default - ""
-@param {RegExp} tagsRe Regulat Expression for searching tags. Default bings to "+tag"
-@return {Array} result Result consists of new text at 0 position and tags list at 1 pos
-@api public
-###
-exports.searchAndDeactivateTags = (text, tagPrefix="", 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, t.substring 1
- tags.push "#{tagPrefix}#{t.substring 1}"
- [result, tags]
-
-###
Make line longer. Increase line length with spaces to len.
If line longer, than length, do nothing
@@ -561,6 +540,17 @@ exports.makeLineLonger = (line, len=80, chr=" ") ->
line += chr
line
+###
+Search tags in text and replace them
+
+@param {String} text Text with tags
+@param {Function} replaceFn Replace function, call on every tag and must return new string
+ that replace old tagstring
+@param {RegExp} tagsRe Regular Expression for searching tags. Default bings to "+tag"
+@return {Array} result Result consists of new text at 0 position and tags list at 1 pos
+@api public
+###
+
exports.searchAndReplaceTags = (text, replaceFn, tagsRe=/(\+\S+)/g) ->
tags = []
result = text
@@ -570,5 +560,5 @@ exports.searchAndReplaceTags = (text, replaceFn, tagsRe=/(\+\S+)/g) ->
# 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
+ tags.push t.substring 1
[result, tags]
Please sign in to comment.
Something went wrong with that request. Please try again.