Source View

Add a Source view. [Based on a suggestion by Andrew Stacey]
Fix a well-formedness bug in the list action, due to
boneheaded truncation algorithm. [Reported by Roby Bartels]
This commit is contained in:
Jacques Distler 2009-12-13 19:25:14 -06:00
parent c88a1d43dc
commit 282515d907
4 changed files with 92 additions and 6 deletions

View file

@ -13,7 +13,7 @@ class WikiController < ApplicationController
:history, :revision, :atom_with_content, :atom_with_headlines, :if => Proc.new { |c| c.send(:do_caching?) }
cache_sweeper :revision_sweeper
layout 'default', :except => [:atom_with_content, :atom_with_headlines, :atom, :tex, :s5, :export_html]
layout 'default', :except => [:atom_with_content, :atom_with_headlines, :atom, :source, :tex, :s5, :export_html]
def index
if @web_name
@ -357,6 +357,10 @@ class WikiController < ApplicationController
end
end
def source
#to template
end
def tex
if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup)
@tex_content = Maruku.new(@page.content).to_latex
@ -385,6 +389,18 @@ class WikiController < ApplicationController
end
end
def truncate(text, length = 30, truncate_string = '...')
return text if text.length <= length
len = length - truncate_string.length
text.split.inject('') do |t, word|
if t.length + word.length <= len
t << word + ' '
else
return t.chop + truncate_string
end
end
end
protected
def do_caching?
@ -503,11 +519,7 @@ class WikiController < ApplicationController
def rss_with_content_allowed?
@web.password.nil? or @web.published?
end
def truncate(text, length = 30, truncate_string = '...')
if text.length > length then text[0..(length - 3)] + truncate_string else text end
end
def filter_spam(content)
@@spam_patterns ||= load_spam_patterns
@@spam_patterns.each do |pattern|