Skip to content

Instantly share code, notes, and snippets.

@falsecz
Created March 15, 2012 12:53
Show Gist options
  • Save falsecz/2044054 to your computer and use it in GitHub Desktop.
Save falsecz/2044054 to your computer and use it in GitHub Desktop.
Formatovani entities v tweetu
formatTweet: (tweet) ->
chars = []
text = tweet.text
chars.push c for c in tweet.text
chars = @processEntity chars, tweet.entities.hashtags, (entity) ->
'<a href="#">#' + entity.text + '</a>'
chars = @processEntity chars, tweet.entities.user_mentions, (entity) ->
'<a href="#">@' + entity.screen_name + '</a>'
chars = @processEntity chars, tweet.entities.urls, (entity) ->
'<a href="#">' + entity.url + '</a>'
tweet.formattedText = chars.join ''
return tweet
processEntity: (chars, entities, callback) ->
for e in entities
for i in [e.indices[0] .. e.indices[1] - 1]
chars[i] = ''
chars[e.indices[0]] = callback(e)
return chars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment