diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 31f377ea..95667bae 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -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| diff --git a/app/views/wiki/page.rhtml b/app/views/wiki/page.rhtml index e276354a..ec5dbce9 100644 --- a/app/views/wiki/page.rhtml +++ b/app/views/wiki/page.rhtml @@ -45,6 +45,9 @@ {:id => 'view_S5'} %> <%- end -%> <%- end -%> + | + <%= link_to 'Source', {:web => @web.address, :action => 'source', :id => @page.name}, + {:id => 'view_source', :rel => 'nofollow' } %> <%= render :partial => 'inbound_links' %> diff --git a/app/views/wiki/source.html.erb b/app/views/wiki/source.html.erb new file mode 100644 index 00000000..952cf56a --- /dev/null +++ b/app/views/wiki/source.html.erb @@ -0,0 +1,64 @@ + + + + + <%- if @page and (@page.name == 'HomePage') -%> + <%= h(@web.name) %> + <%- else @web -%> + <%= @page.plain_name %> in <%= h @web.name %> + <%- end -%> + + + + + + + <%= stylesheet_link_tag 'instiki', :media => 'all' unless @inline_style %> + <%= "" if @style_additions %> + + <%= javascript_include_tag :defaults %> + + + + + +
+ +
+ + + \ No newline at end of file diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 3d0ce78c..30517f77 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -36,6 +36,13 @@ class WikiControllerTest < ActionController::TestCase set_tex_header end + def test_truncate_page_name + wanted_page_name = 'This is a very, very, very, very, VERY long page name' + evil_page_name = 'This page name has lots of fun & games' + assert_equal 'This is a very, very, very,...', @controller.truncate(WikiWords.separate(wanted_page_name), 35) + assert_equal 'This page name has lots of...', @controller.truncate(WikiWords.separate(evil_page_name)) + end + def test_authenticate set_web_property :password, 'pswd'