Permalink
Browse files

simplify by deferring to search web page

closes #2
  • Loading branch information...
geemus committed Aug 20, 2012
1 parent 9f3ad54 commit e47211b7d672e06cf92647926c4352d218b89bc4
Showing with 5 additions and 10 deletions.
  1. +5 −10 init.rb
View
15 init.rb
@@ -32,18 +32,13 @@ def docs(topic, url)
when 301, 302
docs(head.headers['Location'])
when 404
- message = [
- "No #{topic} article found."
- ]
- suggestions = json_decode(Excon.get('https://devcenter.heroku.com/articles.json', :query => { :q => topic, :source => 'heroku-docs' }).body)['devcenter']
- unless suggestions.empty?
- message << "Perhaps you meant one of these:"
- longest = suggestions.map {|suggestion| suggestion['url'].split('/articles/').last.length }.max
- suggestions.each do |suggestion|
- message << " %-#{longest}s # %s" % [suggestion['url'].split('/articles/').last, suggestion['title']]
+ action("Opening search for #{topic}") do
+ require('launchy')
+ launchy = Launchy.open("https://devcenter.heroku.com/articles?q=#{topic}")
+ if launchy.respond_to?(:join)
+ launchy.join
end
end
- error(message.join("\n"))
end
end

0 comments on commit e47211b

Please sign in to comment.