permalink_fu 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/README.markdown +64 -0
  2. data/lib/data/x00.yml +257 -0
  3. data/lib/data/x01.yml +257 -0
  4. data/lib/data/x02.yml +256 -0
  5. data/lib/data/x03.yml +256 -0
  6. data/lib/data/x04.yml +256 -0
  7. data/lib/data/x05.yml +256 -0
  8. data/lib/data/x06.yml +256 -0
  9. data/lib/data/x07.yml +256 -0
  10. data/lib/data/x09.yml +256 -0
  11. data/lib/data/x0a.yml +256 -0
  12. data/lib/data/x0b.yml +256 -0
  13. data/lib/data/x0c.yml +256 -0
  14. data/lib/data/x0d.yml +256 -0
  15. data/lib/data/x0e.yml +256 -0
  16. data/lib/data/x0f.yml +256 -0
  17. data/lib/data/x10.yml +256 -0
  18. data/lib/data/x11.yml +256 -0
  19. data/lib/data/x12.yml +257 -0
  20. data/lib/data/x13.yml +256 -0
  21. data/lib/data/x14.yml +257 -0
  22. data/lib/data/x15.yml +257 -0
  23. data/lib/data/x16.yml +256 -0
  24. data/lib/data/x17.yml +256 -0
  25. data/lib/data/x18.yml +256 -0
  26. data/lib/data/x1e.yml +256 -0
  27. data/lib/data/x1f.yml +256 -0
  28. data/lib/data/x20.yml +256 -0
  29. data/lib/data/x21.yml +256 -0
  30. data/lib/data/x22.yml +256 -0
  31. data/lib/data/x23.yml +256 -0
  32. data/lib/data/x24.yml +256 -0
  33. data/lib/data/x25.yml +256 -0
  34. data/lib/data/x26.yml +256 -0
  35. data/lib/data/x27.yml +256 -0
  36. data/lib/data/x28.yml +257 -0
  37. data/lib/data/x2e.yml +256 -0
  38. data/lib/data/x2f.yml +256 -0
  39. data/lib/data/x30.yml +256 -0
  40. data/lib/data/x31.yml +256 -0
  41. data/lib/data/x32.yml +256 -0
  42. data/lib/data/x33.yml +256 -0
  43. data/lib/data/x4d.yml +256 -0
  44. data/lib/data/x4e.yml +257 -0
  45. data/lib/data/x4f.yml +257 -0
  46. data/lib/data/x50.yml +257 -0
  47. data/lib/data/x51.yml +257 -0
  48. data/lib/data/x52.yml +257 -0
  49. data/lib/data/x53.yml +257 -0
  50. data/lib/data/x54.yml +257 -0
  51. data/lib/data/x55.yml +257 -0
  52. data/lib/data/x56.yml +257 -0
  53. data/lib/data/x57.yml +257 -0
  54. data/lib/data/x58.yml +257 -0
  55. data/lib/data/x59.yml +257 -0
  56. data/lib/data/x5a.yml +257 -0
  57. data/lib/data/x5b.yml +257 -0
  58. data/lib/data/x5c.yml +257 -0
  59. data/lib/data/x5d.yml +257 -0
  60. data/lib/data/x5e.yml +257 -0
  61. data/lib/data/x5f.yml +257 -0
  62. data/lib/data/x60.yml +257 -0
  63. data/lib/data/x61.yml +257 -0
  64. data/lib/data/x62.yml +257 -0
  65. data/lib/data/x63.yml +257 -0
  66. data/lib/data/x64.yml +257 -0
  67. data/lib/data/x65.yml +257 -0
  68. data/lib/data/x66.yml +257 -0
  69. data/lib/data/x67.yml +257 -0
  70. data/lib/data/x68.yml +257 -0
  71. data/lib/data/x69.yml +257 -0
  72. data/lib/data/x6a.yml +257 -0
  73. data/lib/data/x6b.yml +257 -0
  74. data/lib/data/x6c.yml +257 -0
  75. data/lib/data/x6d.yml +257 -0
  76. data/lib/data/x6e.yml +257 -0
  77. data/lib/data/x6f.yml +257 -0
  78. data/lib/data/x70.yml +257 -0
  79. data/lib/data/x71.yml +257 -0
  80. data/lib/data/x72.yml +257 -0
  81. data/lib/data/x73.yml +257 -0
  82. data/lib/data/x74.yml +257 -0
  83. data/lib/data/x75.yml +257 -0
  84. data/lib/data/x76.yml +257 -0
  85. data/lib/data/x77.yml +257 -0
  86. data/lib/data/x78.yml +257 -0
  87. data/lib/data/x79.yml +257 -0
  88. data/lib/data/x7a.yml +257 -0
  89. data/lib/data/x7b.yml +257 -0
  90. data/lib/data/x7c.yml +257 -0
  91. data/lib/data/x7d.yml +257 -0
  92. data/lib/data/x7e.yml +257 -0
  93. data/lib/data/x7f.yml +257 -0
  94. data/lib/data/x80.yml +257 -0
  95. data/lib/data/x81.yml +257 -0
  96. data/lib/data/x82.yml +257 -0
  97. data/lib/data/x83.yml +257 -0
  98. data/lib/data/x84.yml +257 -0
  99. data/lib/data/x85.yml +257 -0
  100. data/lib/data/x86.yml +257 -0
  101. data/lib/data/x87.yml +257 -0
  102. data/lib/data/x88.yml +257 -0
  103. data/lib/data/x89.yml +257 -0
  104. data/lib/data/x8a.yml +257 -0
  105. data/lib/data/x8b.yml +257 -0
  106. data/lib/data/x8c.yml +257 -0
  107. data/lib/data/x8d.yml +257 -0
  108. data/lib/data/x8e.yml +257 -0
  109. data/lib/data/x8f.yml +257 -0
  110. data/lib/data/x90.yml +257 -0
  111. data/lib/data/x91.yml +257 -0
  112. data/lib/data/x92.yml +257 -0
  113. data/lib/data/x93.yml +257 -0
  114. data/lib/data/x94.yml +257 -0
  115. data/lib/data/x95.yml +257 -0
  116. data/lib/data/x96.yml +257 -0
  117. data/lib/data/x97.yml +257 -0
  118. data/lib/data/x98.yml +257 -0
  119. data/lib/data/x99.yml +257 -0
  120. data/lib/data/x9a.yml +257 -0
  121. data/lib/data/x9b.yml +257 -0
  122. data/lib/data/x9c.yml +257 -0
  123. data/lib/data/x9d.yml +257 -0
  124. data/lib/data/x9e.yml +257 -0
  125. data/lib/data/x9f.yml +256 -0
  126. data/lib/data/xa0.yml +257 -0
  127. data/lib/data/xa1.yml +257 -0
  128. data/lib/data/xa2.yml +257 -0
  129. data/lib/data/xa3.yml +257 -0
  130. data/lib/data/xa4.yml +256 -0
  131. data/lib/data/xac.yml +257 -0
  132. data/lib/data/xad.yml +257 -0
  133. data/lib/data/xae.yml +257 -0
  134. data/lib/data/xaf.yml +257 -0
  135. data/lib/data/xb0.yml +257 -0
  136. data/lib/data/xb1.yml +257 -0
  137. data/lib/data/xb2.yml +257 -0
  138. data/lib/data/xb3.yml +257 -0
  139. data/lib/data/xb4.yml +257 -0
  140. data/lib/data/xb5.yml +257 -0
  141. data/lib/data/xb6.yml +257 -0
  142. data/lib/data/xb7.yml +257 -0
  143. data/lib/data/xb8.yml +257 -0
  144. data/lib/data/xb9.yml +257 -0
  145. data/lib/data/xba.yml +257 -0
  146. data/lib/data/xbb.yml +257 -0
  147. data/lib/data/xbc.yml +257 -0
  148. data/lib/data/xbd.yml +257 -0
  149. data/lib/data/xbe.yml +257 -0
  150. data/lib/data/xbf.yml +257 -0
  151. data/lib/data/xc0.yml +257 -0
  152. data/lib/data/xc1.yml +257 -0
  153. data/lib/data/xc2.yml +257 -0
  154. data/lib/data/xc3.yml +257 -0
  155. data/lib/data/xc4.yml +257 -0
  156. data/lib/data/xc5.yml +257 -0
  157. data/lib/data/xc6.yml +257 -0
  158. data/lib/data/xc7.yml +257 -0
  159. data/lib/data/xc8.yml +257 -0
  160. data/lib/data/xc9.yml +257 -0
  161. data/lib/data/xca.yml +257 -0
  162. data/lib/data/xcb.yml +257 -0
  163. data/lib/data/xcc.yml +257 -0
  164. data/lib/data/xcd.yml +257 -0
  165. data/lib/data/xce.yml +257 -0
  166. data/lib/data/xcf.yml +257 -0
  167. data/lib/data/xd0.yml +257 -0
  168. data/lib/data/xd1.yml +257 -0
  169. data/lib/data/xd2.yml +257 -0
  170. data/lib/data/xd3.yml +257 -0
  171. data/lib/data/xd4.yml +257 -0
  172. data/lib/data/xd5.yml +257 -0
  173. data/lib/data/xd6.yml +257 -0
  174. data/lib/data/xd7.yml +256 -0
  175. data/lib/data/xf9.yml +257 -0
  176. data/lib/data/xfa.yml +256 -0
  177. data/lib/data/xfb.yml +257 -0
  178. data/lib/data/xfc.yml +257 -0
  179. data/lib/data/xfd.yml +256 -0
  180. data/lib/data/xfe.yml +257 -0
  181. data/lib/data/xff.yml +257 -0
  182. data/lib/permalink_fu.rb +176 -0
  183. data/test/permalink_fu_test.rb +476 -0
  184. data/test/test_helper.rb +13 -0
  185. metadata +251 -0
@@ -0,0 +1,64 @@
1
+ # PermalinkFu
2
+
3
+ A simple plugin for creating URL-friendly permalinks (slugs) from attributes.
4
+
5
+ Uses [`ActiveSupport::Multibyte::Handlers::UTF8Handler`](http://api.rubyonrails.org/classes/ActiveSupport/Multibyte/Handlers/UTF8Handler.html) (part of Rails since 1.2) rather than `iconv` (which is [inconsistent between platforms](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/243426)) for normalization/decomposition.
6
+
7
+
8
+ ## Usage
9
+
10
+ class Article < ActiveRecord::Base
11
+ has_permalink :title
12
+ end
13
+
14
+ This will escape the title in a before_validation callback, turning e.g. "Föö!! Bàr" into "foo-bar".
15
+
16
+ The permalink is by default stored in the `permalink` attribute.
17
+
18
+ has_permalink :title, :as => :slug
19
+
20
+ will store it in `slug` instead.
21
+
22
+ has_permalink [:category, :title]
23
+
24
+ will store a permalink form of `"#{category}-#{title}"`.
25
+
26
+ Permalinks are guaranteed unique: "foo-bar-2", "foo-bar-3" etc are used if there are conflicts. You can set the scope of the uniqueness like
27
+
28
+ has_permalink :title, :scope => :blog_id
29
+
30
+ This means that two articles with the same `blog_id` can not have the same permalink, but two articles with different `blog_id`s can.
31
+
32
+ Two finders are provided:
33
+
34
+ Article.find_by_permalink(params[:id])
35
+ Article.find_by_permalink!(params[:id])
36
+
37
+ These methods keep their name no matter what attribute is used to store the permalink.
38
+
39
+ The `find_by_permalink` method returns `nil` if there is no match; the `find_by_permalink!` method will raise `ActiveRecord::RecordNotFound`.
40
+
41
+ You can override the model's `to_param` method with
42
+
43
+ has_permalink :title, :param => true
44
+
45
+ This means that the permalink will be used instead of the primary key (id) in generated URLs. Remember to change your controller code from e.g. `find` to `find_by_permalink!`.
46
+
47
+ You can add conditions to `has_permalink` like so:
48
+
49
+ class Article < ActiveRecord::Base
50
+ has_permalink :title, :if => Proc.new { |article| article.needs_permalink? }
51
+ end
52
+
53
+ Use the `:if` or `:unless` options to specify a Proc, method, or string to be called or evaluated. The permalink will only be generated if the option evaluates to true.
54
+
55
+ You can use `PermalinkFu.escape` to escape a string manually.
56
+
57
+
58
+ ## Credits
59
+
60
+ Originally extracted from [Mephisto](http://mephistoblog.com) by [technoweenie](http://github.com/technoweenie/permalink_fu/).
61
+
62
+ Conditions added by [Pat Nakajima](http://github.com/nakajima/permalink_fu/).
63
+
64
+ [Henrik Nyh](http://github.com/technoweenie/permalink_fu/) replaced `iconv` with `ActiveSupport::Multibyte`.
@@ -0,0 +1,257 @@
1
+ ---
2
+ - "\z"
3
+ - "\x01"
4
+ - "\x02"
5
+ - "\x03"
6
+ - "\x04"
7
+ - "\x05"
8
+ - "\x06"
9
+ - "\a"
10
+ - "\x08"
11
+ - ' '
12
+ - "\n"
13
+ - "\v"
14
+ - "\f"
15
+ - "\r"
16
+ - "\x0e"
17
+ - "\x0f"
18
+ - "\x10"
19
+ - "\x11"
20
+ - "\x12"
21
+ - "\x13"
22
+ - "\x14"
23
+ - "\x15"
24
+ - "\x16"
25
+ - "\x17"
26
+ - "\x18"
27
+ - "\x19"
28
+ - "\x1a"
29
+ - "\e"
30
+ - "\x1c"
31
+ - "\x1d"
32
+ - "\x1e"
33
+ - "\x1f"
34
+ - ' '
35
+ - '!'
36
+ - '"'
37
+ - '#'
38
+ - $
39
+ - '%'
40
+ - '&'
41
+ - "'"
42
+ - (
43
+ - )
44
+ - '*'
45
+ - +
46
+ - ','
47
+ - -
48
+ - .
49
+ - /
50
+ - 0
51
+ - 1
52
+ - 2
53
+ - 3
54
+ - 4
55
+ - 5
56
+ - 6
57
+ - 7
58
+ - 8
59
+ - 9
60
+ - ':'
61
+ - ;
62
+ - <
63
+ - =
64
+ - '>'
65
+ - '?'
66
+ - '@'
67
+ - A
68
+ - B
69
+ - C
70
+ - D
71
+ - E
72
+ - F
73
+ - G
74
+ - H
75
+ - I
76
+ - J
77
+ - K
78
+ - L
79
+ - M
80
+ - N
81
+ - O
82
+ - P
83
+ - Q
84
+ - R
85
+ - S
86
+ - T
87
+ - U
88
+ - V
89
+ - W
90
+ - X
91
+ - Y
92
+ - Z
93
+ - ']'
94
+ - \
95
+ - ']'
96
+ - '^'
97
+ - _
98
+ - '`'
99
+ - a
100
+ - b
101
+ - c
102
+ - d
103
+ - e
104
+ - f
105
+ - g
106
+ - h
107
+ - i
108
+ - j
109
+ - k
110
+ - l
111
+ - m
112
+ - n
113
+ - o
114
+ - p
115
+ - q
116
+ - r
117
+ - s
118
+ - t
119
+ - u
120
+ - v
121
+ - w
122
+ - x
123
+ - y
124
+ - z
125
+ - '{'
126
+ - '|'
127
+ - '}'
128
+ - '~'
129
+ - 
130
+ - ''
131
+ - ''
132
+ - ''
133
+ - ''
134
+ - ''
135
+ - ''
136
+ - ''
137
+ - ''
138
+ - ''
139
+ - ''
140
+ - ''
141
+ - ''
142
+ - ''
143
+ - ''
144
+ - ''
145
+ - ''
146
+ - ''
147
+ - ''
148
+ - ''
149
+ - ''
150
+ - ''
151
+ - ''
152
+ - ''
153
+ - ''
154
+ - ''
155
+ - ''
156
+ - ''
157
+ - ''
158
+ - ''
159
+ - ''
160
+ - ''
161
+ - ''
162
+ - ' '
163
+ - '!'
164
+ - C/
165
+ - PS
166
+ - $?
167
+ - Y=
168
+ - '|'
169
+ - SS
170
+ - '"'
171
+ - (c)
172
+ - a
173
+ - <<
174
+ - '!'
175
+ - ''
176
+ - (r)
177
+ - -
178
+ - deg
179
+ - +-
180
+ - 2
181
+ - 3
182
+ - "'"
183
+ - u
184
+ - P
185
+ - '*'
186
+ - ','
187
+ - 1
188
+ - o
189
+ - '>>'
190
+ - 1/4
191
+ - 1/2
192
+ - 3/4
193
+ - '?'
194
+ - A
195
+ - A
196
+ - A
197
+ - A
198
+ - A
199
+ - A
200
+ - AE
201
+ - C
202
+ - E
203
+ - E
204
+ - E
205
+ - E
206
+ - I
207
+ - I
208
+ - I
209
+ - I
210
+ - D
211
+ - N
212
+ - O
213
+ - O
214
+ - O
215
+ - O
216
+ - O
217
+ - x
218
+ - O
219
+ - U
220
+ - U
221
+ - U
222
+ - U
223
+ - U
224
+ - Th
225
+ - ss
226
+ - a
227
+ - a
228
+ - a
229
+ - a
230
+ - a
231
+ - a
232
+ - ae
233
+ - c
234
+ - e
235
+ - e
236
+ - e
237
+ - e
238
+ - i
239
+ - i
240
+ - i
241
+ - i
242
+ - d
243
+ - n
244
+ - o
245
+ - o
246
+ - o
247
+ - o
248
+ - o
249
+ - /
250
+ - o
251
+ - u
252
+ - u
253
+ - u
254
+ - u
255
+ - y
256
+ - th
257
+ - y
@@ -0,0 +1,257 @@
1
+ ---
2
+ - A
3
+ - a
4
+ - A
5
+ - a
6
+ - A
7
+ - a
8
+ - C
9
+ - c
10
+ - C
11
+ - c
12
+ - C
13
+ - c
14
+ - C
15
+ - c
16
+ - D
17
+ - d
18
+ - D
19
+ - d
20
+ - E
21
+ - e
22
+ - E
23
+ - e
24
+ - E
25
+ - e
26
+ - E
27
+ - e
28
+ - E
29
+ - e
30
+ - G
31
+ - g
32
+ - G
33
+ - g
34
+ - G
35
+ - g
36
+ - G
37
+ - g
38
+ - H
39
+ - h
40
+ - H
41
+ - h
42
+ - I
43
+ - i
44
+ - I
45
+ - i
46
+ - I
47
+ - i
48
+ - I
49
+ - i
50
+ - I
51
+ - i
52
+ - IJ
53
+ - ''
54
+ - J
55
+ - j
56
+ - K
57
+ - k
58
+ - k
59
+ - L
60
+ - l
61
+ - L
62
+ - l
63
+ - L
64
+ - l
65
+ - L
66
+ - l
67
+ - L
68
+ - l
69
+ - N
70
+ - n
71
+ - N
72
+ - n
73
+ - N
74
+ - n
75
+ - "'n"
76
+ - ng
77
+ - NG
78
+ - O
79
+ - o
80
+ - O
81
+ - o
82
+ - O
83
+ - o
84
+ - OE
85
+ - oe
86
+ - R
87
+ - r
88
+ - R
89
+ - r
90
+ - R
91
+ - r
92
+ - S
93
+ - s
94
+ - S
95
+ - s
96
+ - S
97
+ - s
98
+ - S
99
+ - s
100
+ - T
101
+ - t
102
+ - T
103
+ - t
104
+ - T
105
+ - t
106
+ - U
107
+ - u
108
+ - U
109
+ - u
110
+ - U
111
+ - u
112
+ - U
113
+ - u
114
+ - U
115
+ - u
116
+ - U
117
+ - u
118
+ - W
119
+ - w
120
+ - Y
121
+ - y
122
+ - Y
123
+ - Z
124
+ - z
125
+ - Z
126
+ - z
127
+ - Z
128
+ - z
129
+ - s
130
+ - b
131
+ - B
132
+ - B
133
+ - b
134
+ - 6
135
+ - 6
136
+ - O
137
+ - C
138
+ - c
139
+ - D
140
+ - D
141
+ - D
142
+ - d
143
+ - d
144
+ - 3
145
+ - '@'
146
+ - E
147
+ - F
148
+ - f
149
+ - G
150
+ - G
151
+ - hv
152
+ - I
153
+ - I
154
+ - K
155
+ - k
156
+ - l
157
+ - l
158
+ - W
159
+ - N
160
+ - n
161
+ - O
162
+ - O
163
+ - o
164
+ - OI
165
+ - oi
166
+ - P
167
+ - p
168
+ - YR
169
+ - 2
170
+ - 2
171
+ - SH
172
+ - sh
173
+ - t
174
+ - T
175
+ - t
176
+ - T
177
+ - U
178
+ - u
179
+ - Y
180
+ - V
181
+ - Y
182
+ - y
183
+ - Z
184
+ - z
185
+ - ZH
186
+ - ZH
187
+ - zh
188
+ - zh
189
+ - 2
190
+ - 5
191
+ - 5
192
+ - ts
193
+ - w
194
+ - '|'
195
+ - '||'
196
+ - '|='
197
+ - '!'
198
+ - DZ
199
+ - Dz
200
+ - dz
201
+ - LJ
202
+ - Lj
203
+ - lj
204
+ - NJ
205
+ - Nj
206
+ - nj
207
+ - A
208
+ - a
209
+ - I
210
+ - i
211
+ - O
212
+ - o
213
+ - U
214
+ - u
215
+ - U
216
+ - u
217
+ - U
218
+ - u
219
+ - U
220
+ - u
221
+ - U
222
+ - u
223
+ - '@'
224
+ - A
225
+ - a
226
+ - A
227
+ - a
228
+ - AE
229
+ - ae
230
+ - G
231
+ - g
232
+ - G
233
+ - g
234
+ - K
235
+ - k
236
+ - O
237
+ - o
238
+ - O
239
+ - o
240
+ - ZH
241
+ - zh
242
+ - j
243
+ - DZ
244
+ - D
245
+ - dz
246
+ - G
247
+ - g
248
+ - HV
249
+ - W
250
+ - N
251
+ - n
252
+ - A
253
+ - a
254
+ - AE
255
+ - ae
256
+ - O
257
+ - o