Use a view to build the trace RSS feed and get rid of OSM::GeoRSS
This commit is contained in:
parent
5bb751ca26
commit
40b452ac74
7 changed files with 76 additions and 114 deletions
|
@ -203,27 +203,19 @@ class TraceController < ApplicationController
|
|||
end
|
||||
|
||||
def georss
|
||||
traces = Trace.public.visible
|
||||
@traces = Trace.public.visible
|
||||
|
||||
if params[:display_name]
|
||||
traces = traces.joins(:user).where(:users => {:display_name => params[:display_name]})
|
||||
@traces = @traces.joins(:user).where(:users => {:display_name => params[:display_name]})
|
||||
end
|
||||
|
||||
if params[:tag]
|
||||
traces = traces.tagged(params[:tag])
|
||||
@traces = @traces.tagged(params[:tag])
|
||||
end
|
||||
|
||||
traces = traces.order("timestamp DESC")
|
||||
traces = traces.limit(20)
|
||||
traces = traces.includes(:user)
|
||||
|
||||
rss = OSM::GeoRSS.new
|
||||
|
||||
traces.each do |trace|
|
||||
rss.add(trace.latitude, trace.longitude, trace.name, trace.user.display_name, url_for({:controller => 'trace', :action => 'view', :id => trace.id, :display_name => trace.user.display_name}), "<img src='#{url_for({:controller => 'trace', :action => 'icon', :id => trace.id, :display_name => trace.user.display_name})}'> GPX file with #{trace.size} points from #{trace.user.display_name}", trace.timestamp)
|
||||
end
|
||||
|
||||
render :text => rss.to_s, :content_type => "application/rss+xml"
|
||||
@traces = @traces.order("timestamp DESC")
|
||||
@traces = @traces.limit(20)
|
||||
@traces = @traces.includes(:user)
|
||||
end
|
||||
|
||||
def picture
|
||||
|
|
6
app/views/trace/_description.html.erb
Normal file
6
app/views/trace/_description.html.erb
Normal file
|
@ -0,0 +1,6 @@
|
|||
<%= image_tag(url_for(:controller => :trace, :action => :icon, :id => description.id, :display_name => description.user.display_name)) %>
|
||||
<% if description.size -%>
|
||||
<%= t "trace.description.description_with_count", :count => description.size, :user => description.user.display_name %>
|
||||
<% else -%>
|
||||
<%= t "trace.description.description_without_count", :user => description.user.display_name %>
|
||||
<% end -%>
|
43
app/views/trace/georss.rss.builder
Normal file
43
app/views/trace/georss.rss.builder
Normal file
|
@ -0,0 +1,43 @@
|
|||
xml.instruct!
|
||||
|
||||
xml.rss("version" => "2.0",
|
||||
"xmlns:dc" => "http://purl.org/dc/elements/1.1/",
|
||||
"xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
|
||||
"xmlns:georss" => "http://www.georss.org/georss") do
|
||||
xml.channel do
|
||||
xml.title t("trace.georss.title")
|
||||
xml.description t("trace.georss.title")
|
||||
xml.link url_for(:controller => :trace, :action => :list, :only_path => false)
|
||||
|
||||
xml.image do
|
||||
xml.url image_path("mag_map-rss2.0.png")
|
||||
xml.title t("trace.georss.title")
|
||||
xml.width 100
|
||||
xml.height 100
|
||||
xml.link url_for(:controller => :trace, :action => :list, :only_path => false)
|
||||
end
|
||||
|
||||
@traces.each do |trace|
|
||||
xml.item do
|
||||
xml.title trace.name
|
||||
|
||||
xml.link url_for(:controller => :trace, :action => :view, :id => trace.id, :display_name => trace.user.display_name, :only_path => false)
|
||||
xml.guid url_for(:controller => :trace, :action => :view, :id => trace.id, :display_name => trace.user.display_name, :only_path => false)
|
||||
|
||||
xml.description do
|
||||
xml.cdata! render(:partial => "description", :object => trace, :formats => [ :html ])
|
||||
end
|
||||
|
||||
xml.dc :creator, trace.user.display_name
|
||||
|
||||
xml.pubDate trace.timestamp.to_s(:rfc822)
|
||||
|
||||
if trace.latitude and trace.longitude
|
||||
xml.geo :lat, trace.latitude
|
||||
xml.geo :long, trace.longitude
|
||||
xml.georss :point, "#{trace.latitude} #{trace.longitude}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1570,6 +1570,13 @@ en:
|
|||
offline:
|
||||
heading: "GPX Storage Offline"
|
||||
message: "The GPX file storage and upload system is currently unavailable."
|
||||
georss:
|
||||
title: "OpenStreetMap GPS Traces"
|
||||
description:
|
||||
description_with_count:
|
||||
one: "GPX file with %{count} point from %{user}"
|
||||
other: "GPX file with %{count} points from %{user}"
|
||||
description_without_count: "GPX file from %{user}"
|
||||
application:
|
||||
require_cookies:
|
||||
cookies_needed: "You appear to have cookies disabled - please enable cookies in your browser before continuing."
|
||||
|
|
|
@ -162,8 +162,8 @@ OpenStreetMap::Application.routes.draw do
|
|||
match '/user/:display_name/traces/tag/:tag' => 'trace#list', :via => :get
|
||||
match '/user/:display_name/traces/page/:page' => 'trace#list', :via => :get
|
||||
match '/user/:display_name/traces' => 'trace#list', :via => :get
|
||||
match '/user/:display_name/traces/tag/:tag/rss' => 'trace#georss', :via => :get
|
||||
match '/user/:display_name/traces/rss' => 'trace#georss', :via => :get
|
||||
match '/user/:display_name/traces/tag/:tag/rss' => 'trace#georss', :via => :get, :format => :rss
|
||||
match '/user/:display_name/traces/rss' => 'trace#georss', :via => :get, :format => :rss
|
||||
match '/user/:display_name/traces/:id' => 'trace#view', :via => :get
|
||||
match '/user/:display_name/traces/:id/picture' => 'trace#picture', :via => :get
|
||||
match '/user/:display_name/traces/:id/icon' => 'trace#icon', :via => :get
|
||||
|
@ -171,8 +171,8 @@ OpenStreetMap::Application.routes.draw do
|
|||
match '/traces/tag/:tag' => 'trace#list', :via => :get
|
||||
match '/traces/page/:page' => 'trace#list', :via => :get
|
||||
match '/traces' => 'trace#list', :via => :get
|
||||
match '/traces/tag/:tag/rss' => 'trace#georss', :via => :get
|
||||
match '/traces/rss' => 'trace#georss', :via => :get
|
||||
match '/traces/tag/:tag/rss' => 'trace#georss', :via => :get, :format => :rss
|
||||
match '/traces/rss' => 'trace#georss', :via => :get, :format => :rss
|
||||
match '/traces/mine/tag/:tag/page/:page' => 'trace#mine', :via => :get
|
||||
match '/traces/mine/tag/:tag' => 'trace#mine', :via => :get
|
||||
match '/traces/mine/page/:page' => 'trace#mine', :via => :get
|
||||
|
|
86
lib/osm.rb
86
lib/osm.rb
|
@ -417,92 +417,6 @@ module OSM
|
|||
end
|
||||
end
|
||||
|
||||
class GeoRSS
|
||||
def initialize(feed_title='OpenStreetMap GPS Traces', feed_description='OpenStreetMap GPS Traces', feed_url='http://www.openstreetmap.org/traces/')
|
||||
@doc = XML::Document.new
|
||||
@doc.encoding = XML::Encoding::UTF_8
|
||||
|
||||
rss = XML::Node.new 'rss'
|
||||
@doc.root = rss
|
||||
rss['version'] = "2.0"
|
||||
rss['xmlns:geo'] = "http://www.w3.org/2003/01/geo/wgs84_pos#"
|
||||
@channel = XML::Node.new 'channel'
|
||||
rss << @channel
|
||||
title = XML::Node.new 'title'
|
||||
title << feed_title
|
||||
@channel << title
|
||||
description_el = XML::Node.new 'description'
|
||||
@channel << description_el
|
||||
|
||||
description_el << feed_description
|
||||
link = XML::Node.new 'link'
|
||||
link << feed_url
|
||||
@channel << link
|
||||
image = XML::Node.new 'image'
|
||||
@channel << image
|
||||
url = XML::Node.new 'url'
|
||||
url << 'http://www.openstreetmap.org/images/mag_map-rss2.0.png'
|
||||
image << url
|
||||
title = XML::Node.new 'title'
|
||||
title << "OpenStreetMap"
|
||||
image << title
|
||||
width = XML::Node.new 'width'
|
||||
width << '100'
|
||||
image << width
|
||||
height = XML::Node.new 'height'
|
||||
height << '100'
|
||||
image << height
|
||||
link = XML::Node.new 'link'
|
||||
link << feed_url
|
||||
image << link
|
||||
end
|
||||
|
||||
def add(latitude=0, longitude=0, title_text='dummy title', author_text='anonymous', url='http://www.example.com/', description_text='dummy description', timestamp=DateTime.now)
|
||||
item = XML::Node.new 'item'
|
||||
|
||||
title = XML::Node.new 'title'
|
||||
item << title
|
||||
title << title_text
|
||||
link = XML::Node.new 'link'
|
||||
link << url
|
||||
item << link
|
||||
|
||||
guid = XML::Node.new 'guid'
|
||||
guid << url
|
||||
item << guid
|
||||
|
||||
description = XML::Node.new 'description'
|
||||
description << description_text
|
||||
item << description
|
||||
|
||||
author = XML::Node.new 'author'
|
||||
author << author_text
|
||||
item << author
|
||||
|
||||
pubDate = XML::Node.new 'pubDate'
|
||||
pubDate << timestamp.to_s(:rfc822)
|
||||
item << pubDate
|
||||
|
||||
if latitude
|
||||
lat_el = XML::Node.new 'geo:lat'
|
||||
lat_el << latitude.to_s
|
||||
item << lat_el
|
||||
end
|
||||
|
||||
if longitude
|
||||
lon_el = XML::Node.new 'geo:long'
|
||||
lon_el << longitude.to_s
|
||||
item << lon_el
|
||||
end
|
||||
|
||||
@channel << item
|
||||
end
|
||||
|
||||
def to_s
|
||||
return @doc.to_s
|
||||
end
|
||||
end
|
||||
|
||||
class API
|
||||
def get_xml_doc
|
||||
doc = XML::Document.new
|
||||
|
|
|
@ -88,19 +88,19 @@ class TraceControllerTest < ActionController::TestCase
|
|||
|
||||
assert_routing(
|
||||
{ :path => "/traces/rss", :method => :get },
|
||||
{ :controller => "trace", :action => "georss" }
|
||||
{ :controller => "trace", :action => "georss", :format => :rss }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/traces/tag/tagname/rss", :method => :get },
|
||||
{ :controller => "trace", :action => "georss", :tag => "tagname" }
|
||||
{ :controller => "trace", :action => "georss", :tag => "tagname", :format => :rss }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/user/username/traces/rss", :method => :get },
|
||||
{ :controller => "trace", :action => "georss", :display_name => "username" }
|
||||
{ :controller => "trace", :action => "georss", :display_name => "username", :format => :rss }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/user/username/traces/tag/tagname/rss", :method => :get },
|
||||
{ :controller => "trace", :action => "georss", :display_name => "username", :tag => "tagname" }
|
||||
{ :controller => "trace", :action => "georss", :display_name => "username", :tag => "tagname", :format => :rss }
|
||||
)
|
||||
|
||||
assert_routing(
|
||||
|
@ -205,16 +205,16 @@ class TraceControllerTest < ActionController::TestCase
|
|||
|
||||
# Check that the rss loads
|
||||
def test_rss
|
||||
get :georss
|
||||
get :georss, :format => :rss
|
||||
check_trace_feed Trace.public
|
||||
|
||||
get :georss, :tag => "London"
|
||||
get :georss, :tag => "London", :format => :rss
|
||||
check_trace_feed Trace.tagged("London").public
|
||||
|
||||
get :georss, :display_name => users(:public_user).display_name
|
||||
get :georss, :display_name => users(:public_user).display_name, :format => :rss
|
||||
check_trace_feed users(:public_user).traces.public
|
||||
|
||||
get :georss, :display_name => users(:public_user).display_name, :tag => "Birmingham"
|
||||
get :georss, :display_name => users(:public_user).display_name, :tag => "Birmingham", :format => :rss
|
||||
check_trace_feed users(:public_user).traces.tagged("Birmingham").public
|
||||
end
|
||||
|
||||
|
@ -345,7 +345,7 @@ private
|
|||
|
||||
def check_trace_feed(traces)
|
||||
assert_response :success
|
||||
assert_template nil
|
||||
assert_template "georss"
|
||||
assert_equal "application/rss+xml", @response.content_type
|
||||
assert_select "rss", :count => 1 do
|
||||
assert_select "channel", :count => 1 do
|
||||
|
@ -359,7 +359,7 @@ private
|
|||
assert_select item, "link", "http://test.host/user/#{trace.user.display_name}/traces/#{trace.id}"
|
||||
assert_select item, "guid", "http://test.host/user/#{trace.user.display_name}/traces/#{trace.id}"
|
||||
assert_select item, "description"
|
||||
assert_select item, "author", trace.user.display_name
|
||||
# assert_select item, "dc:creator", trace.user.display_name
|
||||
assert_select item, "pubDate", trace.timestamp.rfc822
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue