falsecz
3/15/2012 - 12:53 PM

Formatovani entities v tweetu

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