2010-06-14 22:19:28 +00:00
|
|
|
require 'rubypants'
|
2010-02-04 02:38:35 +00:00
|
|
|
|
2010-01-30 05:50:07 +00:00
|
|
|
module WezM
|
|
|
|
module Helpers
|
|
|
|
module Articles
|
|
|
|
|
|
|
|
def personal_articles
|
|
|
|
sorted_articles.select { |a| a.identifier =~ %r{^/personal/} }
|
|
|
|
end
|
|
|
|
|
|
|
|
def technical_articles
|
|
|
|
sorted_articles.select { |a| a.identifier =~ %r{^/technical/} }
|
|
|
|
end
|
|
|
|
|
|
|
|
def article_to_json(article)
|
|
|
|
{
|
2010-06-14 22:19:12 +00:00
|
|
|
:title => RubyPants.new(article[:title]).to_html,
|
2010-01-30 05:50:07 +00:00
|
|
|
:path => article.identifier,
|
2010-02-01 01:58:26 +00:00
|
|
|
:date => Time.parse(article[:created_at]).rfc2822,
|
2010-06-14 22:19:12 +00:00
|
|
|
:text => RubyPants.new(article[:title]).to_html,
|
|
|
|
:extra => RubyPants.new(article[:extra] || " ").to_html
|
2010-01-30 05:50:07 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2010-02-04 02:38:35 +00:00
|
|
|
def short_url(url)
|
2010-06-14 22:19:28 +00:00
|
|
|
require 'bitly'
|
2010-03-02 21:03:51 +00:00
|
|
|
begin
|
|
|
|
@bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7')
|
|
|
|
@cache ||= {}
|
|
|
|
unless u = @cache[url]
|
|
|
|
u = @bitly.shorten(url)
|
|
|
|
else
|
|
|
|
puts "Cache hit on #{url}"
|
|
|
|
end
|
|
|
|
u.short_url
|
|
|
|
rescue BitlyError
|
|
|
|
nil
|
2010-02-04 02:38:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-30 05:50:07 +00:00
|
|
|
end
|
|
|
|
end
|
2010-03-02 21:03:51 +00:00
|
|
|
end
|