mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Linkify message:// URLs in notes. Those links are used by Mail.app on
Mac OS X to link to a mail message by message id.
This commit is contained in:
parent
e844b5aa5b
commit
5299490c83
5 changed files with 69 additions and 5 deletions
|
|
@ -325,4 +325,28 @@ module TodosHelper
|
|||
return entries.map{|e| e.specification()}.join("\n") rescue ''
|
||||
end
|
||||
|
||||
AUTO_LINK_MESSAGE_RE = %r{message://<[^>]+>} unless const_defined?(:AUTO_LINK_MESSAGE_RE)
|
||||
|
||||
# Converts message:// links to href. This URL scheme is used on Mac OS X
|
||||
# to link to a mail message in Mail.app.
|
||||
def auto_link_message(text)
|
||||
text.gsub(AUTO_LINK_MESSAGE_RE) do
|
||||
href = $&
|
||||
left, right = $`, $'
|
||||
# detect already linked URLs and URLs in the middle of a tag
|
||||
if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
|
||||
# do not change string; URL is alreay linked
|
||||
href
|
||||
else
|
||||
content_tag(:a, h(href), :href => h(href))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def format_note(note)
|
||||
note = auto_link_message(note)
|
||||
note = auto_link(note)
|
||||
note = markdown(note)
|
||||
note = sanitize(note)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<div id="<%= dom_id(note, 'container') %>">
|
||||
<h2><%= link_to("Note #{note.id}", note_path(note), :title => "Show note #{note.id}" ) %></h2>
|
||||
<div class="project_notes" id="<%= dom_id(note) %>">
|
||||
<%= sanitize(markdown(auto_link(note.body))) %>
|
||||
<%= format_note(note.body) %>
|
||||
|
||||
<div class="note_footer">
|
||||
<%= link_to_remote(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<%= link_to(image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), "#", {:class => 'show_notes', :title => 'Show notes'}) %>
|
||||
|
||||
<div class="todo_notes" id="<%= dom_id(item, 'notes') %>" style="display:none">
|
||||
<%= sanitize(markdown( auto_link(item.notes)) ) %>
|
||||
<%= format_note(item.notes) %>
|
||||
</div>
|
||||
|
|
@ -58,7 +58,7 @@ Rails::Initializer.run do |config|
|
|||
# allow other protocols in urls for sanitzer. Add to your liking, for example
|
||||
# config.action_view.sanitized_allowed_protocols = 'onenote', 'blah', 'proto'
|
||||
# to enable "link":onenote://... or "link":blah://... hyperlinks
|
||||
config.action_view.sanitized_allowed_protocols = 'onenote'
|
||||
config.action_view.sanitized_allowed_protocols = 'onenote', 'message'
|
||||
|
||||
# See Rails::Configuration for more options
|
||||
end
|
||||
|
|
|
|||
|
|
@ -510,4 +510,44 @@ class TodosControllerTest < ActionController::TestCase
|
|||
assert_select("a[href=#{url}]")
|
||||
end
|
||||
|
||||
def test_format_note_normal
|
||||
login_as(:admin_user)
|
||||
todo = users(:admin_user).todos.first
|
||||
todo.notes = "A normal description."
|
||||
todo.save!
|
||||
get :index
|
||||
assert_select("div#notes_todo_#{todo.id}", "A normal description.")
|
||||
end
|
||||
|
||||
def test_format_note_markdown
|
||||
login_as(:admin_user)
|
||||
todo = users(:admin_user).todos.first
|
||||
todo.notes = "A *bold description*."
|
||||
todo.save!
|
||||
get :index
|
||||
assert_select("div#notes_todo_#{todo.id}", "A bold description.")
|
||||
assert_select("div#notes_todo_#{todo.id} strong", "bold description")
|
||||
end
|
||||
|
||||
def test_format_note_link
|
||||
login_as(:admin_user)
|
||||
todo = users(:admin_user).todos.first
|
||||
todo.notes = "A link to http://github.com/."
|
||||
todo.save!
|
||||
get :index
|
||||
assert_select("div#notes_todo_#{todo.id}", 'A link to http://github.com/.')
|
||||
assert_select("div#notes_todo_#{todo.id} a[href=http://github.com/]", 'http://github.com/')
|
||||
end
|
||||
|
||||
def test_format_note_link_message
|
||||
login_as(:admin_user)
|
||||
todo = users(:admin_user).todos.first
|
||||
todo.notes = "A Mail.app message://<ABCDEF-GHADB-123455-FOO-BAR@example.com> link"
|
||||
todo.save!
|
||||
get :index
|
||||
# puts css_select("div#notes_todo_#{todo.id}")
|
||||
assert_select("div#notes_todo_#{todo.id}", 'A Mail.app message://<ABCDEF-GHADB-123455-FOO-BAR@example.com> link')
|
||||
assert_select("div#notes_todo_#{todo.id} a", 'message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>')
|
||||
assert_select("div#notes_todo_#{todo.id} a[href=message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>]", 'message://<ABCDEF-GHADB-123455-FOO-BAR@example.com>')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue