Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

michaelherold/tweet_pretty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TweetPretty

Build Status Dependency Status Code Climate Coverage Status

As the missing formatting tool for the Twitter gem, TweetPretty allows you to easily replace entities in tweets with properly encoded HTML to conform to Twitter's Display Requirements.

Installation

Add this line to your application's Gemfile:

gem 'tweet_pretty'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tweet_pretty

Usage

If you're not working in an environment where gems are auto-loaded, then require the gem to monkey patch the Twitter::Tweet class:

require 'tweet_pretty'

Use the Twitter gem to pull a tweet:

> tweet = Twitter.status(379713438806597632)

Then use the to_html method to convert its text attribute into a properly converted HTML snippet:

> tweet.text
=> "Pardon this test tweet. It's hard to find tweets containing at least one of each entity. #devtest @mherold https://t.co/CbYo8pjDDO"
> tweet.to_html
=> "Pardon this test tweet. It&#39;s hard to find tweets containing at least one of each entity. <a class="hashtag" href="http://twitter.com/search?q=#devtest">#devtest</a> <a class="user-mention" title="Michael Herold" href="http://twitter.com/mherold">@mherold</a> <a class="link" href="https://t.co/CbYo8pjDDO">twitter.com/mherold</a>"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Acknowledgments

  • The original algorithm used to do the text replacements was based on some Javascript code in a gist by @wadey. This little snippet inspired me to encapsulate the functionality for use with the Twitter Ruby gem. This algorithm has since been replaced by a more Ruby-ish approach.
  • The configuration class is based off of that from Geocoder, which is a pretty awesome library for geocoding in Ruby.

Supported Ruby Versions

This library aims to support the same set of Ruby implementations as the twitter gem, which it is extending. Currently, those are:

  • Ruby 1.8.7
  • Ruby 1.9.2
  • Ruby 1.9.3
  • Ruby 2.0.0

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Thus, you should specify a gem dependency using the Pessimistic Version Constraint with two digits of precision:

# In Gemfile
gem 'tweet_pretty', '~> 1.0'

# In .gemspec
spec.add_dependency 'tweet_pretty', '~> 1.0'

Copyright

Copyright (c) 2013 Michael Herold. Open sourced under the terms of the MIT license.

About

Replace hashtags, links, media, and user mentions in Twitter::Tweets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages