store rendered notes of todos in database to avoid costly rendering when you load a page

This commit is contained in:
Reinier Balt 2012-04-12 11:34:08 +02:00
parent f32e5b256b
commit bb8b5a4c72
6 changed files with 81 additions and 27 deletions

View file

@ -143,14 +143,6 @@ class ApplicationController < ActionController::Base
return json_elems
end
# Uses RedCloth to transform text using either Textile or Markdown Need to
# require redcloth above RedCloth 3.0 or greater is needed to use Markdown,
# otherwise it only handles Textile
#
def markdown(text)
RedCloth.new(text).to_html
end
# Here's the concept behind this "mobile content negotiation" hack: In
# addition to the main, AJAXy Web UI, Tracks has a lightweight low-feature
# 'mobile' version designed to be suitablef or use from a phone or PDA. It

View file

@ -189,24 +189,6 @@ module ApplicationHelper
end
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 = content_tag(:a, h(href), :href => h(href))
end
end
end
def format_note(note)
note = auto_link_message(note)
note = markdown(note)

View file

@ -64,7 +64,7 @@ module TodosHelper
def collapsed_notes_image(todo)
link = link_to(image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), "#", {:class => 'show_notes', :title => 'Show notes'})
notes = content_tag(:div, {:class => "todo_notes", :id => dom_id(todo, 'notes'), :style => "display:none"}) { format_note(todo.notes) }
notes = content_tag(:div, {:class => "todo_notes", :id => dom_id(todo, 'notes'), :style => "display:none"}) { todo.rendered_notes }
return link+notes
end

View file

@ -1,5 +1,6 @@
class Todo < ActiveRecord::Base
before_save :render_note
after_save :save_predecessors
# associations
@ -396,4 +397,12 @@ class Todo < ActiveRecord::Base
return todo
end
def render_note
unless notes.nil?
rendered_notes = Tracks::Utils.render_text(notes)
else
rendered_notes = nil
end
end
end