Permalink
Browse files

Merge branch 'master' of github:brandur/facts-twitter

Conflicts:
	config/schedule.rb
  • Loading branch information...
brandur committed Sep 26, 2011
2 parents e50ff4c + faeae65 commit 42f5a84b142328083b7880cac922e522eb9a7059
Showing with 33 additions and 5 deletions.
  1. +2 −2 README.md
  2. +1 −1 config/schedule.rb
  3. +9 −1 lib/facts/filters/markdown.rb
  4. +2 −0 lib/facts/twitter_formatter.rb
  5. +19 −1 spec/facts/filters/markdown_spec.rb
View
@@ -1,7 +1,7 @@
facts-twitter
=============
-A simple program that pulls a random fact from a Facts installation, and pushes it to Twitter. Provides an easy way to program a schedule for these pushes.
+A simple program that pulls a random fact from a Facts installation, and pushes it to Twitter. Provides an easy way to program a schedule for these pushes. See a sample of the running application at [@factsproject](http://twitter.com/factsproject).
Setup
-----
@@ -41,4 +41,4 @@ Run Whenever to get the corresponding Cron configuration:
whenever
-Add the given configuration to your crontab using `crontab -e`.
+Add the printed configuration to your crontab using `crontab -e`.
View
@@ -1,5 +1,5 @@
every 30.minutes do
- command "cd #{File.expand_path('../../', __FILE__)} && bin/facts-twitter"
+ command "cd #{File.expand_path('../..', __FILE__)} && bin/facts-twitter"
end
# Use this file to easily define all of your cron jobs.
@@ -7,7 +7,15 @@ def filter(str)
# Replace Markdown links with just the link target
str = str.gsub(/\[(.*?)\]\((.*?)\)/, '\2')
- str
+ # Remove emphasis and strong emphasis -- it doesn't look very good on
+ # Twitter and takes up previous character space
+ str = str.gsub(/\*\*(.*?)\*\*/, '\1')
+ str = str.gsub(/__(.*?)__/, '\1')
+ str = str.gsub(/\*(.*?)\*/, '\1')
+ str = str.gsub(/_(.*?)_/, '\1')
+
+ # Lastly, strip all HTML tags (which are allowed in Markdown)
+ str.gsub(/<\/?[^>]*>/, '').strip
end
end
end
@@ -24,6 +24,8 @@ def format(fact, category)
# List of filters to apply to a fact's content. Applied in order.
FILTERS = [
Filters::HtmlEntities.new,
+ Filters::Math.new,
+ # Keep Markdown last, as it will perform the most extensive filtering
Filters::Markdown.new,
].freeze
@@ -5,7 +5,25 @@
@filter = Facts::Filters::Markdown.new
end
- it "should replace Markdown links with just the link target" do
+ it "should replace links with just the link target" do
@filter.filter("A link to [example.com](http://example.com).").should == "A link to http://example.com."
end
+
+ it "should remove emphasis" do
+ @filter.filter("an *emphasized* word").should == "an emphasized word"
+ @filter.filter("an _emphasized_ word").should == "an emphasized word"
+ end
+
+ it "should remove strong emphasis" do
+ @filter.filter("a **strongly emphasized** word").should == "a strongly emphasized word"
+ @filter.filter("a __strongly emphasized__ word").should == "a strongly emphasized word"
+ end
+
+ it "should remove any HTML" do
+ @filter.filter(<<-eos).should == "This is a paragraph with a nested tag."
+ <p>
+ This is a paragraph with a <strong>nested tag</strong>.
+ </p>
+ eos
+ end
end

0 comments on commit 42f5a84

Please sign in to comment.