public
Description: Collective Idea's Awesomeness. A collection of useful Rails bits and pieces.
Clone URL: git://github.com/collectiveidea/awesomeness.git
Click here to lend your support to: awesomeness and make a donation at www.pledgie.com !
cap 2 fixes and general cleanup
brandon (author)
Fri Sep 14 14:20:29 -0700 2007
commit  90dc9ef699015653fcffdbf84ba5343ed989c034
tree    e83ee814fd1781ad9e3f8d408bb13f19dd07a300
parent  c7439e7ddac4c339aa16a7a7963ec8988fe007e4
...
1
2
3
4
5
...
1
 
 
 
2
0
@@ -1,4 +1 @@
0
 require 'awesomeness'
0
-if defined? ActionController::AbstractRequest.new.url
0
- ActionController::Base.send :include, CollectiveIdea::ActionController::TrailingSlash
0
-end
0
\ No newline at end of file
...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
...
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
0
@@ -3,83 +3,3 @@ Dir[File.dirname(__FILE__) + "/awesomeness/**/*.rb"].each {|f| require f }
0
 if RAILS_ENV == 'test'
0
   Dir[File.dirname(__FILE__) + "/test/**/*.rb"].each {|f| require f }
0
 end
0
-
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
- end
0
-
0
- module InstanceMethods
0
- private
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
- end
0
- end
0
- end
0
- end
0
- end
0
-end
0
-
0
-module ActionView
0
- module Helpers
0
- module TextHelper
0
-
0
- # Awesome truncate
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
- return if text.nil?
0
- l = length - truncate_string.chars.length
0
- text.chars.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
0
- end
0
-
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
- else
0
- text
0
- end
0
- end
0
-
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
- end
0
- alias_method_chain :truncate, :better_default
0
-
0
- def excerpt_with_better_default(text, phrase, radius = 100, excerpt_string = "…")
0
- excerpt_without_better_default(text, phrase, radius, excerpt_string)
0
- end
0
- alias_method_chain :excerpt, :better_default
0
-
0
- # Widon't
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
- def widont(text)
0
- text.blank? ? '' : text.widont
0
- end
0
-
0
- def textilize_with_widont(text)
0
- textilize_without_widont widont(text)
0
- end
0
- alias_method_chain :textilize, :widont
0
-
0
- def textilize_without_paragraph_with_widont(text)
0
- textilize_without_paragraph_without_widont widont(text)
0
- end
0
- alias_method_chain :textilize_without_paragraph, :widont
0
- end
0
- end
0
-end
0
\ No newline at end of file
...
5
6
7
8
9
10
11
12
 
 
 
 
 
 
 
 
13
14
15
...
5
6
7
 
 
 
 
 
8
9
10
11
12
13
14
15
16
17
18
0
@@ -5,11 +5,14 @@
0
 # don't do a fresh checkout, just svn update
0
 set :deploy_via, :remote_cache
0
 
0
-after "deploy:update_code", "deploy:web:disable"
0
-after "deploy:restart", "deploy:web:enable"
0
-after "deploy:start", "deploy:web:enable"
0
-after "deploy", "deploy:cleanup"
0
-after "deploy:migrations", "deploy:cleanup"
0
+after "deploy:update_code", "deploy:web:disable"
0
+before "deploy:stop", "deploy:web:disable"
0
+before "deploy:restart", "deploy:web:disable"
0
+after "deploy:restart", "deploy:web:enable"
0
+after "deploy:start", "deploy:web:enable"
0
+
0
+after "deploy", "deploy:cleanup"
0
+after "deploy:migrations", "deploy:cleanup"
0
 
0
 load 'logs'
0
 load 'backup'

Comments

    No one has commented yet.