a friendly human readable location instead of some coordinates.
module ApplicationHelper
+ require 'rexml/document'
+
def htmlize(text)
return linkify(sanitize(simple_format(text)))
end
return js
end
+ def describe_location(lat, lon, zoom, language)
+ zoom = zoom || 14
+ language = language || request.user_preferred_languages.join(',')
+ url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
+ response = REXML::Document.new(Net::HTTP.get(URI.parse(url)))
+
+ return response.get_text("reversegeocode/result").to_s
+ end
+
private
def javascript_strings_for_key(key)
expire_action(:controller => 'diary_entry', :action => 'rss', :language => nil, :display_name => nil)
expire_action(:controller => 'diary_entry', :action => 'rss', :language => entry.language_code, :display_name => nil)
expire_action(:controller => 'diary_entry', :action => 'rss', :language => nil, :display_name => entry.user.display_name)
+
+ if record.is_a?(DiaryEntry)
+ expire_fragment(:controller => 'diary_entry', :action => 'view', :display_name => entry.user.display_name, :id => entry.id, :part => "location")
+ end
end
end
<b><%= link_to h(diary_entry.title), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></b><br />
<%= htmlize(diary_entry.body) %>
<% if diary_entry.latitude and diary_entry.longitude %>
-<%= t 'map.coordinates' %> <div class="geo" style="display: inline"><span class="latitude"><%= diary_entry.latitude %></span>; <span class="longitude"><%= diary_entry.longitude %></span></div> (<%=link_to (t 'map.view'), :controller => 'site', :action => 'index', :lat => diary_entry.latitude, :lon => diary_entry.longitude, :zoom => 14 %> / <%=link_to (t 'map.edit'), :controller => 'site', :action => 'edit', :lat => diary_entry.latitude, :lon => diary_entry.longitude, :zoom => 14 %>)<br/>
+<%= render :partial => "location", :object => diary_entry %>
+<br />
<% end %>
<%= t 'diary_entry.diary_entry.posted_by', :link_user => (link_to h(diary_entry.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_entry.user.display_name), :created => l(diary_entry.created_at), :language_link => (link_to h(diary_entry.language.name), :controller => 'diary_entry', :action => 'list', :language => diary_entry.language_code) %>
<% if params[:action] == 'list' %>
--- /dev/null
+<% cache(:controller => 'diary_entry', :action => 'view', :display_name => location.user.display_name, :id => location.id, :part => "location") do %>
+<%= t 'diary_entry.location.location' %>
+
+<abbr class="geo" title="<%= number_with_precision(location.latitude, :precision => 4) %>; <%= number_with_precision(location.longitude, :precision => 4) %>">
+<%= describe_location location.latitude, location.longitude, 14, location.language_code %>
+</abbr>
+
+(<%=link_to t('diary_entry.location.view'), :controller => 'site', :action => 'index', :lat => location.latitude, :lon => location.longitude, :zoom => 14 %>
+/
+<%=link_to t('diary_entry.location.edit'), :controller => 'site', :action => 'edit', :lat => location.latitude, :lon => location.longitude, :zoom => 14 %>)
+<% end %>
with_id: "{{id}}"
with_version: "{{id}}, v{{version}}"
with_name: "{{name}} ({{id}})"
- map:
- view: View
- edit: Edit
- coordinates: "Coordinates:"
browse:
changeset:
title: "Changeset"
comment_from: "Comment from {{link_user}} at {{comment_created_at}}"
hide_link: Hide this comment
confirm: Confirm
+ location:
+ location: "Location:"
+ view: "View"
+ edit: "Edit"
feed:
user:
title: "OpenStreetMap diary entries for {{user}}"
top: 15px;
left: 15px
}
+
+abbr.geo {
+ border-bottom: none;
+}
class DiaryEntryControllerTest < ActionController::TestCase
fixtures :users, :diary_entries, :diary_comments
+ include ActionView::Helpers::NumberHelper
+
def test_showing_new_diary_entry
get :new
assert_response :redirect
# This next line won't work if the text has been run through the htmlize function
# due to formatting that could be introduced
assert_select "p", :text => /#{new_body}/, :count => 1
- assert_select "span.latitude", :text => new_latitude, :count => 1
- assert_select "span.longitude", :text => new_longitude, :count => 1
+ assert_select "abbr[class=geo][title=#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}]", :count => 1
# As we're not logged in, check that you cannot edit
#print @response.body
assert_select "a[href='/user/#{users(:normal_user).display_name}/diary/#{diary_entries(:normal_user_entry_1).id}/edit']", :text => "Edit this entry", :count => 1
# This next line won't work if the text has been run through the htmlize function
# due to formatting that could be introduced
assert_select "p", :text => /#{new_body}/, :count => 1
- assert_select "span.latitude", :text => new_latitude, :count => 1
- assert_select "span.longitude", :text => new_longitude, :count => 1
+ assert_select "abbr[class=geo][title=#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}]", :count => 1
# As we're not logged in, check that you cannot edit
assert_select "a[href='/user/#{users(:normal_user).display_name}/diary/#{diary_entries(:normal_user_entry_1).id}/edit']", :text => "Edit this entry", :count => 0
end