Skip to content
Browse files

Opensearch basic setup (Closes #85)

  • Loading branch information...
1 parent 90517df commit c1ae94e1781f6cb8a25f6e1af7cff63027e220ce @stanguy committed
View
18 app/controllers/home_controller.rb
@@ -172,7 +172,7 @@ def search
:type => :stop,
:name => stop.name,
:id => stop.id,
- :schedule_url => stop_schedule_path(@agency,stop),
+ :schedule_url => stop_schedule_url(@agency,stop),
:times => nil,
:others => nil,
:accessible => stop.accessible
@@ -192,11 +192,25 @@ def search
end
}
respond_to do |format|
- format.html
+ format.html { render :layout => 'container'}
+ format.rss { render :layout => false }
+ format.suggestions {
+ render :json => [ params[:term],
+ @results.collect {|r| r[:name] },
+ @results.collect { "" },
+ @results.collect {|r| r[:type] == :stop ? r[:schedule_url] : home_line_url(@agency,r[:short])}
+ ]
+ }
format.json { render :json => @results }
end
end
+ def opensearch
+ response.headers["Content-Type"] = 'application/opensearchdescription+xml'
+ render :layout => false
+ end
+
+
private
def check_old_ids
if params[:line_id].nil? && params[:stop_id].match(/^[0-9]*$/)
View
17 app/views/home/opensearch.erb
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+ <ShortName>Bus de <%= @agency.city %> en ligne</ShortName>
+ <Description>Recherche de bus à <%= @agency.city %></Description>
+ <InputEncoding>UTF-8</InputEncoding>
+ <!--Image width="16" height="16"></Image-->
+ <!--moz:SearchForm "http://yerwebbersite.com/searchFormer"/-->
+
+ <Url type="application/x-suggestions+json"
+ rel="suggestions"
+ template="<%= search_url(@agency) %>.suggestions?term={searchTerms}"/>
+ <Url type="application/rss+xml"
+ template="<%= search_url(@agency) %>.rss?term={searchTerms}"/>
+ <Url type="text/html"
+ template="<%= search_url(@agency) %>?term={searchTerms}"/>
+
+</OpenSearchDescription>
View
16 app/views/home/search.rss.builder
@@ -0,0 +1,16 @@
+xml.instruct! :xml, :version => "1.0"
+xml.rss :version => "2.0" do
+ xml.channel do
+ xml.title "Bus de #{@agency.city} en ligne"
+ xml.description "Carte et horaires des bus de #{@agency.city}"
+ xml.link agency_url(@agency)
+ if @results.length > 0
+ @results.each do |result|
+ xml.item do
+ xml.title result[:name]
+ xml.link result[:type] == :stop ? result[:schedule_url] : home_line_url( @agency, result[:short] )
+ end
+ end
+ end
+ end
+end
View
3 app/views/layouts/application.html.erb
@@ -10,6 +10,9 @@
<meta name="viewport" content="user-scalable=no, width=device-width" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<link rel="apple-touch-startup-image" href="<%= image_path "Default.png" %>" />
+ <link href='<%= opensearch_path(@agency) %>'
+ rel='search' title='Recherche de bus à <%= @agency.city %>'
+ type='application/opensearchdescription+xml'>
<meta name="format-detection" content="telephone=no">
</head>
<body>
View
2 config/initializers/mime_types.rb
@@ -3,3 +3,5 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
+
+Mime::Type.register_alias "application/x-suggestions+json", :suggestions
View
1 config/routes.rb
@@ -15,6 +15,7 @@
match "city/:agency_id/schedule/legacy/:route_id/at/:stop_id" => "home#schedule"
match "city/:agency_id/schedule/at/:stop_id/" => "home#schedule", :as => :stop_schedule
match "city/:agency_id/search" => "home#search", :as => :search
+ match "city/:agency_id/opensearch" => "home#opensearch", :as => :opensearch
# match "line/:id" => "home#line", :as => :home_line
# match "line/:id/at/:stop_id" => "home#line"

0 comments on commit c1ae94e

Please sign in to comment.
Something went wrong with that request. Please try again.