0
@@ -3,83 +3,3 @@ Dir[File.dirname(__FILE__) + "/awesomeness/**/*.rb"].each {|f| require f }
0
Dir[File.dirname(__FILE__) + "/test/**/*.rb"].each {|f| require f }
0
-# Disambiguate URLs by removing trailing slashes
0
-# Idea from http://fleetingideas.com/post/6539239
0
-# This version works with query strings.
0
-module CollectiveIdea #:nodoc:
0
- module ActionController
0
- module TrailingSlash #:nodoc:
0
- def self.included(base) #:nodoc:
0
- base.before_filter :remove_trailing_slash
0
- base.send :include, InstanceMethods
0
- module InstanceMethods
0
- def remove_trailing_slash
0
- url = request.url.sub(/(.+)\/(\?.+)?$/, '\1\2')
0
- if request.request_uri.length > 1 && url != request.url
0
- headers['Status'] = '301 Moved Permanently'
0
- redirect_to url and return false
0
- # First regex truncates to the length, plus the rest of that word, if any.
0
- # Second regex removes any trailing whitespace or punctuation (except ;).
0
- # Unlike the regular truncate method, this avoids the problem with cutting
0
- # in the middle of an entity ex.: truncate("this & that",9) => "this &am..."
0
- # though it will not be the exact length.
0
- def awesome_truncate(text, length = 30, truncate_string = "…")
0
- l = length - truncate_string.chars.length
0
- text.chars.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
0
- def truncate_with_title(text, length = 30, truncate_string = "…")
0
- if text.chars.length > length
0
- content_tag :span, truncate(text), :title => text
0
- # Better versions of standard truncate and excerpt
0
- def truncate_with_better_default(text, length = 30, truncate_string = "…")
0
- truncate_without_better_default(text, length, truncate_string)
0
- alias_method_chain :truncate, :better_default
0
- def excerpt_with_better_default(text, phrase, radius = 100, excerpt_string = "…")
0
- excerpt_without_better_default(text, phrase, radius, excerpt_string)
0
- alias_method_chain :excerpt, :better_default
0
- # We use this method instead of String#widont directly because textilize is often called with nil.
0
- # This duplicates textilize's solution of returning the empty string if blank.
0
- text.blank? ? '' : text.widont
0
- def textilize_with_widont(text)
0
- textilize_without_widont widont(text)
0
- alias_method_chain :textilize, :widont
0
- def textilize_without_paragraph_with_widont(text)
0
- textilize_without_paragraph_without_widont widont(text)
0
- alias_method_chain :textilize_without_paragraph, :widont
0
\ No newline at end of file
Comments
No one has commented yet.