Refactoring
Move the truncate() method into ApplicationHelper. Move another method around, for no particularly good reason. Controllers really shouldn't have public methods that don't correspond to actions.
This commit is contained in:
parent
dc3d202665
commit
2c5e5a0015
|
@ -1,7 +1,7 @@
|
||||||
# The filters added to this controller will be run for all controllers in the application.
|
# The filters added to this controller will be run for all controllers in the application.
|
||||||
# Likewise will all the methods added be available for all controllers.
|
# Likewise will all the methods added be available for all controllers.
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
# require 'dnsbl_check'
|
|
||||||
protect_forms_from_spam
|
protect_forms_from_spam
|
||||||
before_filter :connect_to_model, :check_authorization, :setup_url_generator, :set_content_type_header, :set_robots_metatag
|
before_filter :connect_to_model, :check_authorization, :setup_url_generator, :set_content_type_header, :set_robots_metatag
|
||||||
after_filter :remember_location, :teardown_url_generator
|
after_filter :remember_location, :teardown_url_generator
|
||||||
|
@ -19,6 +19,10 @@ class ApplicationController < ActionController::Base
|
||||||
Wiki.new
|
Wiki.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def xhtml_enabled?
|
||||||
|
in_a_web? and [:markdownMML, :markdownPNG, :markdown].include?(@web.markup)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def check_authorization
|
def check_authorization
|
||||||
|
@ -166,8 +170,6 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
public
|
|
||||||
|
|
||||||
def set_content_type_header
|
def set_content_type_header
|
||||||
response.charset = 'utf-8'
|
response.charset = 'utf-8'
|
||||||
if %w(atom_with_content atom_with_headlines).include?(action_name)
|
if %w(atom_with_content atom_with_headlines).include?(action_name)
|
||||||
|
@ -190,12 +192,6 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def xhtml_enabled?
|
|
||||||
in_a_web? and (@web.markup == :markdownMML or @web.markup == :markdownPNG or @web.markup == :markdown)
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_robots_metatag
|
def set_robots_metatag
|
||||||
if controller_name == 'wiki' and %w(show published s5).include? action_name and !(params[:mode] == 'diff')
|
if controller_name == 'wiki' and %w(show published s5).include? action_name and !(params[:mode] == 'diff')
|
||||||
@robots_metatag_value = 'index,follow'
|
@robots_metatag_value = 'index,follow'
|
||||||
|
|
|
@ -389,19 +389,6 @@ class WikiController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def truncate(text, length = 30, truncate_string = '...')
|
|
||||||
return text if text.length <= length
|
|
||||||
len = length - truncate_string.length
|
|
||||||
t = ''
|
|
||||||
text.split.collect do |word|
|
|
||||||
if t.length + word.length <= len
|
|
||||||
t << word + ' '
|
|
||||||
else
|
|
||||||
return t.chop + truncate_string
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def do_caching?
|
def do_caching?
|
||||||
|
|
|
@ -111,4 +111,17 @@ module ApplicationHelper
|
||||||
PageRenderer.new(page.revisions.last).display_content
|
PageRenderer.new(page.revisions.last).display_content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def truncate(text, length = 30, truncate_string = '...')
|
||||||
|
return text if text.length <= length
|
||||||
|
len = length - truncate_string.length
|
||||||
|
t = ''
|
||||||
|
text.split.collect do |word|
|
||||||
|
if t.length + word.length <= len
|
||||||
|
t << word + ' '
|
||||||
|
else
|
||||||
|
return t.chop + truncate_string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
<%- @pages_in_category.each do |page| -%>
|
<%- @pages_in_category.each do |page| -%>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to_existing_page page, truncate(page.plain_name, :length => 35) %>
|
<%= link_to_existing_page page, truncate(page.plain_name, 35) %>
|
||||||
</li>
|
</li>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
<ul style="margin-bottom: 10px">
|
<ul style="margin-bottom: 10px">
|
||||||
<%- @page_names_that_are_wanted.each do |wanted_page_name| -%>
|
<%- @page_names_that_are_wanted.each do |wanted_page_name| -%>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to_page(wanted_page_name, @web, truncate(WikiWords.separate(wanted_page_name), :length => 35)) %>
|
<%= link_to_page(wanted_page_name, @web, truncate(WikiWords.separate(wanted_page_name), 35)) %>
|
||||||
wanted by
|
wanted by
|
||||||
<%= @web.select.pages_that_reference(wanted_page_name).collect { |referring_page|
|
<%= @web.select.pages_that_reference(wanted_page_name).collect { |referring_page|
|
||||||
link_to_existing_page referring_page
|
link_to_existing_page referring_page
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
<ul style="margin-bottom: 35px">
|
<ul style="margin-bottom: 35px">
|
||||||
<%- @pages_that_are_orphaned.each do |orphan_page| -%>
|
<%- @pages_that_are_orphaned.each do |orphan_page| -%>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to_existing_page orphan_page, truncate(orphan_page.plain_name, :length => 35) %>
|
<%= link_to_existing_page orphan_page, truncate(orphan_page.plain_name, 35) %>
|
||||||
</li>
|
</li>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -19,6 +19,7 @@ class WikiControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@controller = WikiController.new
|
@controller = WikiController.new
|
||||||
|
@controller.extend ApplicationHelper
|
||||||
@request = ActionController::TestRequest.new
|
@request = ActionController::TestRequest.new
|
||||||
@response = ActionController::TestResponse.new
|
@response = ActionController::TestResponse.new
|
||||||
class << @request.session
|
class << @request.session
|
||||||
|
|
Loading…
Reference in a new issue