Last active
August 29, 2015 14:24
-
-
Save piyushrajput/3c8abb0ee073d4107b29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # helper that takes a feedItem hash and converts it to HTML, including | |
| # properly structuring any included message segments like @mentions. | |
| def message_segments(msg_segments) | |
| # an array of hashes - each hash a segment | |
| html = '' | |
| msg_segments.each do |segment| | |
| html << case segment['type'] | |
| when 'Text' | |
| segment['text'] | |
| when 'Link' | |
| %Q(<a href="#{segment['url']}">#{segment['text']}</a>) | |
| when 'Mention' | |
| %Q(<a href="/users/#{segment['user']['id']}">#{segment['text']}</a>) | |
| when 'Hashtag' | |
| %Q(<a class="hashtag">#{segment['text']}</a>) | |
| else # every segment has a text field, this ensures that new unknown segments don't break the app. | |
| segment['text'] | |
| end | |
| end | |
| html | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment