Simplified code in github refference linking

This commit is contained in:
Lukasz Sarnacki 2013-07-21 23:41:18 +02:00 committed by Piotr Sarnacki
parent 44c7c627fb
commit 4ab6a90b66

View File

@ -70,24 +70,17 @@ require 'config/emoij'
if result.length > 0 then result.join(' ') else '-' if result.length > 0 then result.join(' ') else '-'
githubify: (text, owner, repo) -> githubify: (text, owner, repo) ->
refferences = text.match(@_githubRefferenceRegexp('g'))
if !!refferences
self = this self = this
for refference in refferences text = text.replace @_githubRefferenceRegexp, (refference, matchedOwner, matchedRepo, matchedNumber) ->
do (refference) -> self._githubRefferenceLink(refference, { owner: owner, repo: repo }, { owner: matchedOwner, repo: matchedRepo, number: matchedNumber } )
text = text.replace refference, (refference) ->
self._githubRefferenceLink(refference, owner, repo)
text text
_githubRefferenceLink: (refference, owner, repo) -> _githubRefferenceLink: (refference, current, matched) ->
[newOwner, newRepo, issue] = refference.match(@_githubRefferenceRegexp())[1..3] owner = matched.owner || current.owner
actualOwner = if newOwner? then newOwner else owner repo = matched.repo || current.repo
actualRepo = if newRepo? then newRepo else repo "<a href=\"http://github.com/#{owner}/#{repo}/issues/#{matched.number}\">#{refference}</a>"
"<a href=\"http://github.com/#{actualOwner}/#{actualRepo}/issues/#{issue}\">#{refference}</a>"
_githubRefferenceRegexp: (flags) -> _githubRefferenceRegexp: new RegExp("([\\w-]+)?\\/?([\\w-]+)?#(\\d+)", 'g')
new RegExp("([\\w-]+)?\\/?([\\w-]+)?#(\\d+)", flags)
_normalizeDateString: (string) -> _normalizeDateString: (string) ->
if window.JHW if window.JHW