ruby_slippers 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ext/ext.rb +75 -64
- data/lib/ruby_slippers/article.rb +0 -4
- data/test/fixtures/pages/archives.html.erb +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/ext/ext.rb
CHANGED
@@ -1,3 +1,78 @@
|
|
1
|
+
require 'iconv'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
def meta_def name, &blk
|
5
|
+
(class << self; self; end).instance_eval do
|
6
|
+
define_method(name, &blk)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class String
|
12
|
+
def slugize(slug = '-')
|
13
|
+
slugged = Iconv.iconv('ascii//TRANSLIT//IGNORE', 'utf-8', self).to_s
|
14
|
+
slugged.gsub!(/&/, 'and')
|
15
|
+
slugged.gsub!(/[^\w_\-#{Regexp.escape(slug)}]+/i, slug)
|
16
|
+
slugged.gsub!(/#{slug}{2,}/i, slug)
|
17
|
+
slugged.gsub!(/^#{slug}|#{slug}$/i, '')
|
18
|
+
url_encode(slugged.downcase)
|
19
|
+
end
|
20
|
+
|
21
|
+
def url_encode(word)
|
22
|
+
URI.escape(word, /[^\w_+-]/i)
|
23
|
+
end
|
24
|
+
|
25
|
+
def humanize
|
26
|
+
self.capitalize.gsub(/[-_]+/, ' ')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Fixnum
|
31
|
+
def ordinal
|
32
|
+
# 1 => 1st
|
33
|
+
# 2 => 2nd
|
34
|
+
# 3 => 3rd
|
35
|
+
# ...
|
36
|
+
case self % 100
|
37
|
+
when 11..13; "#{self}th"
|
38
|
+
else
|
39
|
+
case self % 10
|
40
|
+
when 1; "#{self}st"
|
41
|
+
when 2; "#{self}nd"
|
42
|
+
when 3; "#{self}rd"
|
43
|
+
else "#{self}th"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Object
|
50
|
+
def blank?
|
51
|
+
self.nil? || self == ""
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Date
|
56
|
+
# This check is for people running RubySlippers::Enginewith ActiveSupport, avoid a collision
|
57
|
+
unless respond_to? :iso8601
|
58
|
+
# Return the date as a String formatted according to ISO 8601.
|
59
|
+
def iso8601
|
60
|
+
::Time.utc(year, month, day, 0, 0, 0, 0).iso8601
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
module Kernel
|
66
|
+
def silence_stream(stream)
|
67
|
+
old_stream = stream.dup
|
68
|
+
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
69
|
+
stream.sync = true
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
stream.reopen(old_stream)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
1
76
|
require 'enumerator'
|
2
77
|
|
3
78
|
class Array
|
@@ -98,67 +173,3 @@ class Array
|
|
98
173
|
end
|
99
174
|
end
|
100
175
|
end
|
101
|
-
|
102
|
-
class Object
|
103
|
-
def meta_def name, &blk
|
104
|
-
(class << self; self; end).instance_eval do
|
105
|
-
define_method(name, &blk)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
class String
|
111
|
-
def slugize
|
112
|
-
self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
|
113
|
-
end
|
114
|
-
|
115
|
-
def humanize
|
116
|
-
self.capitalize.gsub(/[-_]+/, ' ')
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
class Fixnum
|
121
|
-
def ordinal
|
122
|
-
# 1 => 1st
|
123
|
-
# 2 => 2nd
|
124
|
-
# 3 => 3rd
|
125
|
-
# ...
|
126
|
-
case self % 100
|
127
|
-
when 11..13; "#{self}th"
|
128
|
-
else
|
129
|
-
case self % 10
|
130
|
-
when 1; "#{self}st"
|
131
|
-
when 2; "#{self}nd"
|
132
|
-
when 3; "#{self}rd"
|
133
|
-
else "#{self}th"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
class Object
|
140
|
-
def blank?
|
141
|
-
self.nil? || self == ""
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
class Date
|
146
|
-
# This check is for people running RubySlippers::Enginewith ActiveSupport, avoid a collision
|
147
|
-
unless respond_to? :iso8601
|
148
|
-
# Return the date as a String formatted according to ISO 8601.
|
149
|
-
def iso8601
|
150
|
-
::Time.utc(year, month, day, 0, 0, 0, 0).iso8601
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
module Kernel
|
156
|
-
def silence_stream(stream)
|
157
|
-
old_stream = stream.dup
|
158
|
-
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
159
|
-
stream.sync = true
|
160
|
-
yield
|
161
|
-
ensure
|
162
|
-
stream.reopen(old_stream)
|
163
|
-
end
|
164
|
-
end
|
@@ -10,7 +10,7 @@
|
|
10
10
|
begin;
|
11
11
|
"<div class='archived_article'>"+
|
12
12
|
"<div class='title'>#{article.title}</div>"+
|
13
|
-
"<a href='#{article.url}'><img src='
|
13
|
+
"<a href='#{article.url}'><img src='/img/archives/#{article.slug}-full.png' width='200'></img></a>"+
|
14
14
|
"<div class='title'>#{article.date}</div>"+
|
15
15
|
"</div>";
|
16
16
|
rescue;end
|