nanoant-sinatra-hat 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rack/gettext_reloader.rb +8 -7
- data/lib/sinatra-hat.rb +153 -0
- metadata +2 -5
- data/lib/gettext/date.rb +0 -80
- data/lib/sinatra-hat/string_permalink.rb +0 -7
- data/lib/sinatra-hat/utils.rb +0 -164
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module GetText
|
2
2
|
class Reloader < ::Rack::Reloader
|
3
|
-
def initialize(app, cooldown
|
4
|
-
@
|
5
|
-
@
|
6
|
-
@
|
3
|
+
def initialize(app, path, cooldown=10)
|
4
|
+
@path = path
|
5
|
+
@po = Dir.glob(File.join(@path, '**', '*.po'))
|
6
|
+
@mo = Dir.glob(File.join(@path, '**', '*.mo'))
|
7
|
+
@pot = File.join(@path, 'rbigg.pot') # Used for locking
|
7
8
|
# If there are not translations, give up
|
8
9
|
cooldown = nil unless @po && @mo && @po.size > 0 && @mo.size > 0
|
9
10
|
super(app, cooldown, Stat)
|
@@ -28,12 +29,12 @@ module GetText
|
|
28
29
|
found, mstat = safe_stat(@mo.first)
|
29
30
|
if found && mstat && mstat.mtime == stat.mtime
|
30
31
|
require 'gettext/tools'
|
31
|
-
Dir.chdir
|
32
|
-
GetText.create_mofiles(:po_root => '
|
32
|
+
Dir.chdir @path do
|
33
|
+
GetText.create_mofiles(:po_root => '.', :mo_root => '.')
|
33
34
|
end
|
34
35
|
end
|
35
36
|
# Reload whole translation
|
36
|
-
FastGettext.add_text_domain(FastGettext.text_domain, :path =>
|
37
|
+
FastGettext.add_text_domain(FastGettext.text_domain, :path => @path)
|
37
38
|
FastGettext.current_cache = {}
|
38
39
|
end
|
39
40
|
end
|
data/lib/sinatra-hat.rb
CHANGED
@@ -0,0 +1,153 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'iconv'
|
3
|
+
|
4
|
+
class Integer
|
5
|
+
def minute
|
6
|
+
self * 60
|
7
|
+
end
|
8
|
+
alias minutes minute
|
9
|
+
def hour
|
10
|
+
minute * 60
|
11
|
+
end
|
12
|
+
alias hours hour
|
13
|
+
def day
|
14
|
+
hour * 24
|
15
|
+
end
|
16
|
+
alias days day
|
17
|
+
def week
|
18
|
+
day * 7
|
19
|
+
end
|
20
|
+
alias weeks week
|
21
|
+
def month
|
22
|
+
day * 30
|
23
|
+
end
|
24
|
+
alias months month
|
25
|
+
def year
|
26
|
+
day * 365
|
27
|
+
end
|
28
|
+
alias years year
|
29
|
+
def ago
|
30
|
+
Time.now - self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Time
|
35
|
+
def year_start
|
36
|
+
d = (self - (month-1).months - (day-1).days - hour.hours - min.minutes - sec)
|
37
|
+
d - (d.day-1).days - d.hour.hours - d.min.minutes - d.sec
|
38
|
+
end
|
39
|
+
def month_start
|
40
|
+
self - (day-1).days - hour.hours - min.minutes - sec
|
41
|
+
end
|
42
|
+
def week_start
|
43
|
+
self - ((wday + 6) % 7).days - hour.hours - min.minutes - sec
|
44
|
+
end
|
45
|
+
def midnight
|
46
|
+
self - hour.hours - min.minutes - sec
|
47
|
+
end
|
48
|
+
def noon
|
49
|
+
midnight + 12.hours
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class String
|
54
|
+
def mail_utf8_subject
|
55
|
+
# 4.2 http://tools.ietf.org/html/rfc2047
|
56
|
+
'=?UTF-8?Q?'+(self.chomp.gsub(/[^ !-<>-^`-~]/){|m| m.unpack('C*').map{|c| '=%02X' % c}.join}.gsub(/\s/, '_'))+'?='
|
57
|
+
end
|
58
|
+
def cdata
|
59
|
+
"<![CDATA[#{self.gsub(/\]\]>/,']]]]><![CDATA[>')}]]>"
|
60
|
+
end
|
61
|
+
def md5
|
62
|
+
hash = Digest::MD5.new
|
63
|
+
hash << self
|
64
|
+
hash.hexdigest
|
65
|
+
end
|
66
|
+
def sha1
|
67
|
+
hash = Digest::SHA1.new
|
68
|
+
hash << self
|
69
|
+
hash.hexdigest
|
70
|
+
end
|
71
|
+
# This is Pligg style password hash
|
72
|
+
def pwdhash(salt=nil)
|
73
|
+
salt = String.random_password.md5 if salt.nil?
|
74
|
+
salt = salt[0..8]
|
75
|
+
salt+(salt+self).sha1
|
76
|
+
end
|
77
|
+
def excerpt(chars=nil)
|
78
|
+
first = split(/(?:\n\r?){2,}/)[0] || ""
|
79
|
+
return first if chars.nil?
|
80
|
+
words = first.split(' ')
|
81
|
+
pos, count = words.inject([0, 0]) do |c, v|
|
82
|
+
c[1] + v.length < chars ? [c[0] + 1, c[1] + v.length] : c
|
83
|
+
end
|
84
|
+
words[0..pos].join(' ') + ((pos == words.size) ? '' : '…')
|
85
|
+
end
|
86
|
+
def utf8_length
|
87
|
+
unpack('U*').length
|
88
|
+
end
|
89
|
+
def pad(other, extra=0)
|
90
|
+
padding = other.utf8_length - utf8_length
|
91
|
+
padding = 0 if padding < 0
|
92
|
+
' ' * (padding+extra) + self
|
93
|
+
end
|
94
|
+
def self.random_password(length=9, strength=0)
|
95
|
+
vowels = 'aeuy'
|
96
|
+
consonants = 'bdghjmnpqrstvz'
|
97
|
+
consonants += 'BDGHJLMNPQRSTVWXZ' if strength & 1 != 0
|
98
|
+
vowels += 'AEUY' if strength & 2 != 0
|
99
|
+
consonants += '23456789' if strength & 4 != 0
|
100
|
+
consonants += '@#$%' if strength & 8 != 0
|
101
|
+
password = '';
|
102
|
+
alt = rand(2)
|
103
|
+
length.times do
|
104
|
+
password += consonants[rand(consonants.size - 1)].chr if alt != 0
|
105
|
+
password += vowels[rand(vowels.size - 1)].chr if alt == 0
|
106
|
+
alt = 1 - alt
|
107
|
+
end
|
108
|
+
password
|
109
|
+
end
|
110
|
+
def comma_split
|
111
|
+
CSV.parse_line(gsub(/"\s+,/,'",').gsub(/,\s+"/,',"')).collect{|t| t.strip unless t.nil?}.delete_if{|t| t.nil? || t.empty?}
|
112
|
+
end
|
113
|
+
# http://gist.github.com/93045
|
114
|
+
def to_permalink
|
115
|
+
Iconv.iconv('ascii//translit//IGNORE', 'utf-8', self).first.gsub("'", "").gsub(/[^\x00-\x7F]+/, '').gsub(/[^a-zA-Z0-9-]+/, '-').gsub(/--+/, '-').gsub(/^-/, '').gsub(/-$/, '').downcase
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Array
|
120
|
+
def comma_join
|
121
|
+
map{|v| s = v.gsub!(/,/,',') || v.gsub!(/"/,'""'); s ? '"'+v+'"' : v}.join(', ')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if defined? Rack
|
126
|
+
class Rack::Request
|
127
|
+
def url(path=nil)
|
128
|
+
url = scheme + "://"
|
129
|
+
url << host
|
130
|
+
if scheme == "https" && port != 443 ||
|
131
|
+
scheme == "http" && port != 80
|
132
|
+
url << ":#{port}"
|
133
|
+
end
|
134
|
+
url << (path ? path : fullpath)
|
135
|
+
url
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def silence_warnings
|
141
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
142
|
+
yield
|
143
|
+
ensure
|
144
|
+
$VERBOSE = old_verbose
|
145
|
+
end
|
146
|
+
|
147
|
+
if RUBY_VERSION < "1.9.0"
|
148
|
+
class Symbol
|
149
|
+
def to_proc
|
150
|
+
proc { |obj, *args| obj.send(self, *args) }
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoant-sinatra-hat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Strzelecki
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,7 +26,6 @@ files:
|
|
26
26
|
- README.markdown
|
27
27
|
- Rakefile
|
28
28
|
- VERSION
|
29
|
-
- lib/gettext/date.rb
|
30
29
|
- lib/gettext/haml.rb
|
31
30
|
- lib/gettext/haml_parser.rb
|
32
31
|
- lib/gettext/ruby19_fix.rb
|
@@ -34,8 +33,6 @@ files:
|
|
34
33
|
- lib/rack/gettext_reloader.rb
|
35
34
|
- lib/sequel/utf8_fix.rb
|
36
35
|
- lib/sinatra-hat.rb
|
37
|
-
- lib/sinatra-hat/string_permalink.rb
|
38
|
-
- lib/sinatra-hat/utils.rb
|
39
36
|
- lib/sinatra/reloader.rb
|
40
37
|
- lib/sinatra/template_cache.rb
|
41
38
|
- test/sinatra-hat_test.rb
|
data/lib/gettext/date.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
class Date
|
2
|
-
silence_warnings do
|
3
|
-
MONTHNAMES = [nil,
|
4
|
-
N_('January'),
|
5
|
-
N_('February'),
|
6
|
-
N_('March'),
|
7
|
-
N_('April'),
|
8
|
-
N_('May'),
|
9
|
-
N_('June'),
|
10
|
-
N_('July'),
|
11
|
-
N_('August'),
|
12
|
-
N_('September'),
|
13
|
-
N_('October'),
|
14
|
-
N_('November'),
|
15
|
-
N_('December')]
|
16
|
-
|
17
|
-
BASE_MONTHNAMES = [nil,
|
18
|
-
N_('b|January'),
|
19
|
-
N_('b|February'),
|
20
|
-
N_('b|March'),
|
21
|
-
N_('b|April'),
|
22
|
-
N_('b|May'),
|
23
|
-
N_('b|June'),
|
24
|
-
N_('b|July'),
|
25
|
-
N_('b|August'),
|
26
|
-
N_('b|September'),
|
27
|
-
N_('b|October'),
|
28
|
-
N_('b|November'),
|
29
|
-
N_('b|December')]
|
30
|
-
|
31
|
-
DAYNAMES = [
|
32
|
-
N_('Sunday'),
|
33
|
-
N_('Monday'),
|
34
|
-
N_('Tuesday'),
|
35
|
-
N_('Wednesday'),
|
36
|
-
N_('Thursday'),
|
37
|
-
N_('Friday'),
|
38
|
-
N_('Saturday')]
|
39
|
-
|
40
|
-
ABBR_MONTHNAMES = [nil,
|
41
|
-
N_('Jan'),
|
42
|
-
N_('Feb'),
|
43
|
-
N_('Mar'),
|
44
|
-
N_('Apr'),
|
45
|
-
N_('May'),
|
46
|
-
N_('Jun'),
|
47
|
-
N_('Jul'),
|
48
|
-
N_('Aug'),
|
49
|
-
N_('Sep'),
|
50
|
-
N_('Oct'),
|
51
|
-
N_('Nov'),
|
52
|
-
N_('Dec')]
|
53
|
-
|
54
|
-
ABBR_DAYNAMES = [
|
55
|
-
N_('Sun'),
|
56
|
-
N_('Mon'),
|
57
|
-
N_('Tue'),
|
58
|
-
N_('Wed'),
|
59
|
-
N_('Thu'),
|
60
|
-
N_('Fri'),
|
61
|
-
N_('Sat')]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class Time
|
66
|
-
alias :strftime_nolocale :strftime
|
67
|
-
|
68
|
-
def strftime_gettext(format)
|
69
|
-
format = format.dup
|
70
|
-
format.gsub!(/%a/, _(Date::ABBR_DAYNAMES[self.wday]))
|
71
|
-
format.gsub!(/%A/, _(Date::DAYNAMES[self.wday]))
|
72
|
-
format.gsub!(/%b/, _(Date::ABBR_MONTHNAMES[self.mon]))
|
73
|
-
format.gsub!(/%B/, _(Date::MONTHNAMES[self.mon]))
|
74
|
-
self.strftime_nolocale(format)
|
75
|
-
end
|
76
|
-
|
77
|
-
def to_s
|
78
|
-
strftime_gettext _('%I:%M %p, %A, %B %d, %Y')
|
79
|
-
end
|
80
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# http://gist.github.com/93045
|
2
|
-
require 'iconv'
|
3
|
-
class String
|
4
|
-
def to_permalink
|
5
|
-
Iconv.iconv('ascii//translit//IGNORE', 'utf-8', self).first.gsub("'", "").gsub(/[^\x00-\x7F]+/, '').gsub(/[^a-zA-Z0-9-]+/, '-').gsub(/--+/, '-').gsub(/^-/, '').gsub(/-$/, '').downcase
|
6
|
-
end
|
7
|
-
end
|
data/lib/sinatra-hat/utils.rb
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
class Integer
|
4
|
-
def minute
|
5
|
-
self * 60
|
6
|
-
end
|
7
|
-
alias minutes minute
|
8
|
-
def hour
|
9
|
-
minute * 60
|
10
|
-
end
|
11
|
-
alias hours hour
|
12
|
-
def day
|
13
|
-
hour * 24
|
14
|
-
end
|
15
|
-
alias days day
|
16
|
-
def week
|
17
|
-
day * 7
|
18
|
-
end
|
19
|
-
alias weeks week
|
20
|
-
def month
|
21
|
-
day * 30
|
22
|
-
end
|
23
|
-
alias months month
|
24
|
-
def year
|
25
|
-
day * 365
|
26
|
-
end
|
27
|
-
alias years year
|
28
|
-
def ago
|
29
|
-
Time.now - self
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Time
|
34
|
-
def year_start
|
35
|
-
d = (self - (month-1).months - (day-1).days - hour.hours - min.minutes - sec)
|
36
|
-
d - (d.day-1).days - d.hour.hours - d.min.minutes - d.sec
|
37
|
-
end
|
38
|
-
def month_start
|
39
|
-
self - (day-1).days - hour.hours - min.minutes - sec
|
40
|
-
end
|
41
|
-
def week_start
|
42
|
-
self - ((wday + 6) % 7).days - hour.hours - min.minutes - sec
|
43
|
-
end
|
44
|
-
def midnight
|
45
|
-
self - hour.hours - min.minutes - sec
|
46
|
-
end
|
47
|
-
def noon
|
48
|
-
midnight + 12.hours
|
49
|
-
end
|
50
|
-
def ago
|
51
|
-
s = (Time.now - self).round
|
52
|
-
if (m = s.div(60)) > 0
|
53
|
-
if (h = m.div(60)) > 0
|
54
|
-
if (d = h.div(24)) > 0
|
55
|
-
"#{d} " + n_('day', 'days', d)
|
56
|
-
else
|
57
|
-
"#{h} " + n_('hour', 'hours', h)
|
58
|
-
end
|
59
|
-
else
|
60
|
-
"#{m} " + n_('minute', 'minutes', m)
|
61
|
-
end
|
62
|
-
else
|
63
|
-
"#{s} " + n_('second', 'seconds', s)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class String
|
69
|
-
def mail_utf8_subject
|
70
|
-
# 4.2 http://tools.ietf.org/html/rfc2047
|
71
|
-
'=?UTF-8?Q?'+(self.chomp.gsub(/[^ !-<>-^`-~]/){|m| m.unpack('C*').map{|c| '=%02X' % c}.join}.gsub(/\s/, '_'))+'?='
|
72
|
-
end
|
73
|
-
def cdata
|
74
|
-
"<![CDATA[#{self.gsub(/\]\]>/,']]]]><![CDATA[>')}]]>"
|
75
|
-
end
|
76
|
-
def md5
|
77
|
-
hash = Digest::MD5.new
|
78
|
-
hash << self
|
79
|
-
hash.hexdigest
|
80
|
-
end
|
81
|
-
def sha1
|
82
|
-
hash = Digest::SHA1.new
|
83
|
-
hash << self
|
84
|
-
hash.hexdigest
|
85
|
-
end
|
86
|
-
# This is Pligg style password hash
|
87
|
-
def pwdhash(salt=nil)
|
88
|
-
salt = String.random_password.md5 if salt.nil?
|
89
|
-
salt = salt[0..8]
|
90
|
-
salt+(salt+self).sha1
|
91
|
-
end
|
92
|
-
def excerpt(chars=nil)
|
93
|
-
first = split(/(?:\n\r?){2,}/)[0] || ""
|
94
|
-
return first if chars.nil?
|
95
|
-
words = first.split(' ')
|
96
|
-
pos, count = words.inject([0, 0]) do |c, v|
|
97
|
-
c[1] + v.length < chars ? [c[0] + 1, c[1] + v.length] : c
|
98
|
-
end
|
99
|
-
words[0..pos].join(' ') + ((pos == words.size) ? '' : '…')
|
100
|
-
end
|
101
|
-
def utf8_length
|
102
|
-
unpack('U*').length
|
103
|
-
end
|
104
|
-
def pad(other, extra=0)
|
105
|
-
padding = other.utf8_length - utf8_length
|
106
|
-
padding = 0 if padding < 0
|
107
|
-
' ' * (padding+extra) + self
|
108
|
-
end
|
109
|
-
def self.random_password(length=9, strength=0)
|
110
|
-
vowels = 'aeuy'
|
111
|
-
consonants = 'bdghjmnpqrstvz'
|
112
|
-
consonants += 'BDGHJLMNPQRSTVWXZ' if strength & 1 != 0
|
113
|
-
vowels += 'AEUY' if strength & 2 != 0
|
114
|
-
consonants += '23456789' if strength & 4 != 0
|
115
|
-
consonants += '@#$%' if strength & 8 != 0
|
116
|
-
password = '';
|
117
|
-
alt = rand(2)
|
118
|
-
length.times do
|
119
|
-
password += consonants[rand(consonants.size - 1)].chr if alt != 0
|
120
|
-
password += vowels[rand(vowels.size - 1)].chr if alt == 0
|
121
|
-
alt = 1 - alt
|
122
|
-
end
|
123
|
-
password
|
124
|
-
end
|
125
|
-
def comma_split
|
126
|
-
CSV.parse_line(gsub(/"\s+,/,'",').gsub(/,\s+"/,',"')).collect{|t| t.strip unless t.nil?}.delete_if{|t| t.nil? || t.empty?}
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
class Array
|
131
|
-
def comma_join
|
132
|
-
map{|v| s = v.gsub!(/,/,',') || v.gsub!(/"/,'""'); s ? '"'+v+'"' : v}.join(', ')
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
if defined? Rack
|
137
|
-
class Rack::Request
|
138
|
-
def url(path=nil)
|
139
|
-
url = scheme + "://"
|
140
|
-
url << host
|
141
|
-
if scheme == "https" && port != 443 ||
|
142
|
-
scheme == "http" && port != 80
|
143
|
-
url << ":#{port}"
|
144
|
-
end
|
145
|
-
url << (path ? path : fullpath)
|
146
|
-
url
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def silence_warnings
|
152
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
153
|
-
yield
|
154
|
-
ensure
|
155
|
-
$VERBOSE = old_verbose
|
156
|
-
end
|
157
|
-
|
158
|
-
if RUBY_VERSION < "1.9.0"
|
159
|
-
class Symbol
|
160
|
-
def to_proc
|
161
|
-
proc { |obj, *args| obj.send(self, *args) }
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|