padrino-core 0.12.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/padrino-core.rb +4 -4
- data/lib/padrino-core/application.rb +6 -195
- data/lib/padrino-core/application/application_setup.rb +199 -0
- data/lib/padrino-core/application/routing.rb +66 -25
- data/lib/padrino-core/cli/base.rb +8 -5
- data/lib/padrino-core/cli/rake.rb +12 -9
- data/lib/padrino-core/loader.rb +1 -1
- data/lib/padrino-core/logger.rb +25 -0
- data/lib/padrino-core/mounter.rb +8 -3
- data/lib/padrino-core/reloader.rb +2 -2
- data/lib/padrino-core/server.rb +50 -17
- data/lib/padrino-core/version.rb +1 -1
- data/padrino-core.gemspec +2 -10
- data/test/fixtures/apps/demo_app.rb +7 -0
- data/test/fixtures/apps/demo_demo.rb +7 -0
- data/test/helper.rb +6 -37
- data/test/test_application.rb +12 -13
- data/test/test_core.rb +12 -13
- data/test/test_csrf_protection.rb +49 -23
- data/test/test_dependencies.rb +7 -7
- data/test/test_filters.rb +41 -17
- data/test/test_flash.rb +24 -24
- data/test/test_locale.rb +1 -1
- data/test/test_logger.rb +39 -27
- data/test/test_mounter.rb +34 -20
- data/test/test_reloader_complex.rb +5 -6
- data/test/test_reloader_simple.rb +23 -20
- data/test/test_reloader_system.rb +10 -7
- data/test/test_restful_routing.rb +1 -1
- data/test/test_router.rb +7 -7
- data/test/test_routing.rb +177 -141
- metadata +14 -53
- data/lib/padrino-core/application/rendering.rb +0 -325
- data/lib/padrino-core/application/rendering/extensions/erubis.rb +0 -68
- data/lib/padrino-core/application/rendering/extensions/haml.rb +0 -29
- data/lib/padrino-core/application/rendering/extensions/slim.rb +0 -21
- data/lib/padrino-core/locale/cs.yml +0 -33
- data/lib/padrino-core/locale/da.yml +0 -33
- data/lib/padrino-core/locale/de.yml +0 -33
- data/lib/padrino-core/locale/en.yml +0 -33
- data/lib/padrino-core/locale/es.yml +0 -33
- data/lib/padrino-core/locale/fr.yml +0 -33
- data/lib/padrino-core/locale/hu.yml +0 -33
- data/lib/padrino-core/locale/it.yml +0 -39
- data/lib/padrino-core/locale/ja.yml +0 -33
- data/lib/padrino-core/locale/lv.yml +0 -33
- data/lib/padrino-core/locale/nl.yml +0 -33
- data/lib/padrino-core/locale/no.yml +0 -33
- data/lib/padrino-core/locale/pl.yml +0 -33
- data/lib/padrino-core/locale/pt_br.yml +0 -39
- data/lib/padrino-core/locale/ro.yml +0 -33
- data/lib/padrino-core/locale/ru.yml +0 -34
- data/lib/padrino-core/locale/sv.yml +0 -33
- data/lib/padrino-core/locale/tr.yml +0 -33
- data/lib/padrino-core/locale/uk.yml +0 -33
- data/lib/padrino-core/locale/zh_cn.yml +0 -33
- data/lib/padrino-core/locale/zh_tw.yml +0 -33
- data/lib/padrino-core/support_lite.rb +0 -259
- data/test/fixtures/apps/.components +0 -6
- data/test/fixtures/apps/.gitignore +0 -7
- data/test/fixtures/apps/render.rb +0 -13
- data/test/fixtures/apps/views/blog/post.erb +0 -1
- data/test/fixtures/layouts/layout.erb +0 -1
- data/test/mini_shoulda.rb +0 -45
- data/test/test_rendering.rb +0 -606
- data/test/test_rendering_extensions.rb +0 -14
- data/test/test_support_lite.rb +0 -56
@@ -1,33 +0,0 @@
|
|
1
|
-
nl:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%d-%m-%Y"
|
8
|
-
short: "%d %b"
|
9
|
-
long: "%d %B %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [zondag, maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag]
|
13
|
-
abbr_day_names: [zo, ma, di, wo, do, vr, za]
|
14
|
-
month_names: [~, januari, februari, maart, april, mei, juni, juli, augustus, september, oktober, november, december]
|
15
|
-
abbr_month_names: [~, jan, feb, maa, apr, mei, jun, jul, aug, sep, okt, nov, dec]
|
16
|
-
order:
|
17
|
-
- day
|
18
|
-
- month
|
19
|
-
- year
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a %d %b %Y %H:%M:%S %z"
|
24
|
-
short: "%d %b %H:%M"
|
25
|
-
long: "%d %B %Y %H:%M"
|
26
|
-
am: "am"
|
27
|
-
pm: "pm"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " en "
|
33
|
-
last_word_connector: " en "
|
@@ -1,33 +0,0 @@
|
|
1
|
-
"no":
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%d.%m.%Y"
|
8
|
-
short: "%e. %b %Y"
|
9
|
-
long: "%e. %B %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [søndag, mandag, tirsdag, onsdag, torsdag, fredag, lørdag]
|
13
|
-
abbr_day_names: [sø, ma, ti, 'on', to, fr, lø]
|
14
|
-
month_names: [~, januar, februar, mars, april, mai, juni, juli, august, september, oktober, november, desember]
|
15
|
-
abbr_month_names: [~, jan, feb, mar, apr, maj, jun, jul, aug, sep, okt, nov, des]
|
16
|
-
order:
|
17
|
-
- day
|
18
|
-
- month
|
19
|
-
- year
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%e. %B %Y, %H:%M"
|
24
|
-
short: "%e. %b %Y, %H:%M"
|
25
|
-
long: "%A, %e. %B %Y, %H:%M"
|
26
|
-
am: ""
|
27
|
-
pm: ""
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " og "
|
33
|
-
last_word_connector: " og "
|
@@ -1,33 +0,0 @@
|
|
1
|
-
pl:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%Y-%m-%d"
|
8
|
-
short: "%d %b"
|
9
|
-
long: "%d %B %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [Niedziela, Poniedziałek, Wtorek, Środa, Czwartek, Piątek, Sobota]
|
13
|
-
abbr_day_names: [nie, pon, wto, śro, czw, pia, sob]
|
14
|
-
month_names: [~, Styczeń, Luty, Marzec, Kwiecień, Maj, Czerwiec, Lipiec, Sierpień, Wrzesień, Październik, Listopad, Grudzień]
|
15
|
-
abbr_month_names: [~, sty, lut, mar, kwi, maj, cze, lip, sie, wrz, paź, lis, gru]
|
16
|
-
order:
|
17
|
-
- year
|
18
|
-
- month
|
19
|
-
- day
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a, %d %b %Y, %H:%M:%S %z"
|
24
|
-
short: "%d %b, %H:%M"
|
25
|
-
long: "%d %B %Y, %H:%M"
|
26
|
-
am: "przed południem"
|
27
|
-
pm: "po południu"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " i "
|
33
|
-
last_word_connector: " i "
|
@@ -1,39 +0,0 @@
|
|
1
|
-
pt_br:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%d-%m-%Y"
|
8
|
-
short: "%d %b"
|
9
|
-
long: "%d %B %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [Domingo, Segunda-feira, Terça-feira, Quarta-feira, Quinta-feira, Sexta-feira, Sábado]
|
13
|
-
abbr_day_names: [Dom, Seg, Ter, Qua, Qui, Sex, Sab]
|
14
|
-
month_names: [~, Janeiro, Fevereiro, Março, Abril, Maio, Junho, Julho, Agosto, Setembro, Outubro, Novembro, Dezembro]
|
15
|
-
abbr_month_names: [~, Jan, Fev, Mar, Abr, Maio, Jun, Jul, Ago, Set, Out, Nov, Dez]
|
16
|
-
order:
|
17
|
-
- day
|
18
|
-
- month
|
19
|
-
- year
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a %d %b %Y, %H:%M:%S %z"
|
24
|
-
time: "%H:%M"
|
25
|
-
short: "%d %b %H:%M"
|
26
|
-
long: "%d %B %Y %H:%M"
|
27
|
-
only_second: "%S"
|
28
|
-
|
29
|
-
datetime:
|
30
|
-
formats:
|
31
|
-
default: "%d-%m-%YT%H:%M:%S%Z"
|
32
|
-
|
33
|
-
am: 'am'
|
34
|
-
pm: 'pm'
|
35
|
-
|
36
|
-
support:
|
37
|
-
array:
|
38
|
-
sentence_connector: "e"
|
39
|
-
skip_last_comma: false
|
@@ -1,33 +0,0 @@
|
|
1
|
-
ro:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%d.%m.%Y"
|
8
|
-
short: "%d %b"
|
9
|
-
long: "%d %B %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [Duminică, Luni, Marți, Miercuri, Joi, Vineri, Sâmbătă]
|
13
|
-
abbr_day_names: [Dum, Lun, Mar, Mie, Joi, Vin, Sâm]
|
14
|
-
month_names: [~, Ianuarie, Februarie, Martie, Aprilie, Mai, Iunie, Iulie, August, Septembrie, Octombrie, Noiembrie, Decembrie]
|
15
|
-
abbr_month_names: [~, Ian, Feb, Mar, Apr, Mai, Iun, Iul, Aug, Sep, Oct, Noi, Dec]
|
16
|
-
order:
|
17
|
-
- day
|
18
|
-
- month
|
19
|
-
- year
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a, %d %b %Y %H:%M:%S %z"
|
24
|
-
short: "%d %b %H:%M"
|
25
|
-
long: "%d, %B %Y %H:%M"
|
26
|
-
am: "am"
|
27
|
-
pm: "pm"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " și "
|
33
|
-
last_word_connector: " și "
|
@@ -1,34 +0,0 @@
|
|
1
|
-
ru:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%d.%m.%Y"
|
8
|
-
short: "%d %b"
|
9
|
-
long: "%e %B, %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [Воскресенье, Понедельник, Вторник, Среда, Четверг, Пятница, Суббота]
|
13
|
-
abbr_day_names: [Вс, Пн, Вт, Ср, Чт, Пт, Сб]
|
14
|
-
month_names: [~, Январь, Февраль, Март, Апрель, Май, Июнь, Июль, Август, Сентябрь, Октябрь, Ноябрь, Декабрь]
|
15
|
-
abbr_month_names: [~, Янв, Фев, Мар, Апр, Май, Июн, Июл, Авг, Сен, Окт, Ноя, Дек]
|
16
|
-
order:
|
17
|
-
- year
|
18
|
-
- month
|
19
|
-
- day
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a, %d %b %Y %H:%M:%S %z"
|
24
|
-
short: "%d %b %H:%M"
|
25
|
-
long: "%e %B, %Y %H:%M"
|
26
|
-
am: "д.п."
|
27
|
-
pm: "п.п."
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " и "
|
33
|
-
last_word_connector: " и "
|
34
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
sv:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%Y-%m-%d"
|
8
|
-
short: "%b %d"
|
9
|
-
long: "%B %d, %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [söndag, måndag, tisdag, onsdag, torsdag, fredag, lördag]
|
13
|
-
abbr_day_names: [sön, mån, tis, ons, tors, fre, lör]
|
14
|
-
month_names: [~, januari, februari, mars, april, maj, juni, juli, augusti, september, oktober, november, december]
|
15
|
-
abbr_month_names: [~, jan, feb, mar, apr, may, jun, jul, aug, sep, okt, nov, dec]
|
16
|
-
order:
|
17
|
-
- år
|
18
|
-
- månad
|
19
|
-
- dag
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a, %d %b %Y %H:%M:%S %z"
|
24
|
-
short: "%d %b %H:%M"
|
25
|
-
long: "%B %d, %Y %H:%M"
|
26
|
-
am: "fm"
|
27
|
-
pm: "em"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " och "
|
33
|
-
last_word_connector: ", och "
|
@@ -1,33 +0,0 @@
|
|
1
|
-
tr:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%d/%m/%Y"
|
8
|
-
short: "%d %b"
|
9
|
-
long: "%d %B %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [Pazar, Pazartesi, Salı, Çarşamba, Perşembe, Cuma, Cumartesi]
|
13
|
-
abbr_day_names: [Paz, Pts, Sal, Çar, Per, Cum, Cts]
|
14
|
-
month_names: [~, Ocak, Şubat, Mart, Nisan, Mayıs, Haziran, Temmuz, Ağustos, Eylül, Ekim, Kasım, Aralık]
|
15
|
-
abbr_month_names: [~, Oca, Şub, Mar, Nis, May, Haz, Tem, Ağu, Eyl, Eki, Kas, Ara]
|
16
|
-
order:
|
17
|
-
- day
|
18
|
-
- month
|
19
|
-
- year
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a, %b %b %Y %H:%M:%S %z"
|
24
|
-
short: "%b %d %H:%M"
|
25
|
-
long: "%d %B, %Y %H:%M"
|
26
|
-
am: "öö"
|
27
|
-
pm: "ös"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " ve "
|
33
|
-
last_word_connector: " ve "
|
@@ -1,33 +0,0 @@
|
|
1
|
-
uk:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%d.%m.%Y"
|
8
|
-
short: "%d %b"
|
9
|
-
long: "%e %B, %Y"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [Неділя, Понеділок, Вівторок, Середа, Четвер, Пятница, Субота]
|
13
|
-
abbr_day_names: [Нд, Пн, Вт, Ср, Чт, Пт, Сб]
|
14
|
-
month_names: [~, Січено, Лютий, Березень, Квітень, Травень, Червень, Липень, Серпень, Вересень, Жовтень, Листопад, Грудень]
|
15
|
-
abbr_month_names: [~, Січ, Лют, Бер, Кві, Тра, Чер, Лип, Сер, Вер, Жов, Лис, Гру]
|
16
|
-
order:
|
17
|
-
- year
|
18
|
-
- month
|
19
|
-
- day
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%a, %d %b %Y %H:%M:%S %z"
|
24
|
-
short: "%d %b %H:%M"
|
25
|
-
long: "%e %B, %Y %H:%M"
|
26
|
-
am: "д.п."
|
27
|
-
pm: "п.п"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " і "
|
33
|
-
last_word_connector: ", і "
|
@@ -1,33 +0,0 @@
|
|
1
|
-
zh_cn:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%Y年%m月%d日"
|
8
|
-
short: "%b月%d日"
|
9
|
-
long: "%Y年%B月%d日"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六]
|
13
|
-
abbr_day_names: [日, 一, 二, 三, 四, 五, 六]
|
14
|
-
month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
|
15
|
-
abbr_month_names: [~, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
16
|
-
order:
|
17
|
-
- year
|
18
|
-
- month
|
19
|
-
- day
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%Y年%b月%d日 %H:%M:%S %z"
|
24
|
-
short: "%b月%d日 %H:%M"
|
25
|
-
long: "%Y年%B%d日 %H时%M分"
|
26
|
-
am: "上午"
|
27
|
-
pm: "下午"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ","
|
32
|
-
two_words_connector: "和"
|
33
|
-
last_word_connector: ",还有"
|
@@ -1,33 +0,0 @@
|
|
1
|
-
zh_tw:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%Y-%m-%d"
|
8
|
-
short: "%b%d日"
|
9
|
-
long: "%Y年%b%d日"
|
10
|
-
only_day: "%e"
|
11
|
-
|
12
|
-
day_names: [星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六]
|
13
|
-
abbr_day_names: [日, 一, 二, 三, 四, 五, 六]
|
14
|
-
month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
|
15
|
-
abbr_month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
|
16
|
-
order:
|
17
|
-
- year
|
18
|
-
- month
|
19
|
-
- day
|
20
|
-
|
21
|
-
time:
|
22
|
-
formats:
|
23
|
-
default: "%Y年%b%d日 %A %H:%M:%S %Z"
|
24
|
-
short: "%b%d日 %H:%M"
|
25
|
-
long: "%Y年%b%d日 %H:%M"
|
26
|
-
am: "上午"
|
27
|
-
pm: "下午"
|
28
|
-
|
29
|
-
support:
|
30
|
-
array:
|
31
|
-
words_connector: ", "
|
32
|
-
two_words_connector: " 和 "
|
33
|
-
last_word_connector: ", 和 "
|
@@ -1,259 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# This file loads certain extensions required by Padrino from ActiveSupport.
|
3
|
-
#
|
4
|
-
require 'active_support/core_ext/module/aliasing' # alias_method_chain
|
5
|
-
require 'active_support/core_ext/hash/reverse_merge' # reverse_merge
|
6
|
-
require 'active_support/core_ext/hash/keys' # symbolize_keys
|
7
|
-
require 'active_support/core_ext/hash/indifferent_access' # params[:foo]
|
8
|
-
require 'active_support/core_ext/hash/slice' # slice
|
9
|
-
require 'active_support/core_ext/object/blank' # present?
|
10
|
-
require 'active_support/core_ext/array/extract_options' # extract_options
|
11
|
-
require 'active_support/inflector/methods' # constantize
|
12
|
-
require 'active_support/inflector/inflections' # pluralize
|
13
|
-
require 'active_support/core_ext/string/output_safety' # SafeBuffer and html_safe
|
14
|
-
require 'active_support/inflections' # load default inflections
|
15
|
-
require 'yaml' unless defined?(YAML) # load yaml for i18n
|
16
|
-
require 'win32console' if RUBY_PLATFORM =~ /(win|m)32/ # ruby color support for win
|
17
|
-
|
18
|
-
##
|
19
|
-
# This is an adapted version of active_support/core_ext/string/inflections.rb
|
20
|
-
# to prevent loading several dependencies including I18n gem.
|
21
|
-
#
|
22
|
-
# Issue: https://github.com/rails/rails/issues/1526
|
23
|
-
#
|
24
|
-
class String
|
25
|
-
##
|
26
|
-
# Returns the plural form of the word in the string.
|
27
|
-
#
|
28
|
-
# "post".pluralize # => "posts"
|
29
|
-
# "octopus".pluralize # => "octopi"
|
30
|
-
# "sheep".pluralize # => "sheep"
|
31
|
-
# "words".pluralize # => "words"
|
32
|
-
# "the blue mailman".pluralize # => "the blue mailmen"
|
33
|
-
# "CamelOctopus".pluralize # => "CamelOctopi"
|
34
|
-
#
|
35
|
-
def pluralize
|
36
|
-
ActiveSupport::Inflector.pluralize(self)
|
37
|
-
end
|
38
|
-
|
39
|
-
##
|
40
|
-
# Returns the singular form of the word in the string.
|
41
|
-
#
|
42
|
-
# "posts".singularize # => "post"
|
43
|
-
# "octopi".singularize # => "octopus"
|
44
|
-
# "sheep".singularize # => "sheep"
|
45
|
-
# "words".singularize # => "word"
|
46
|
-
# "the blue mailmen".singularize # => "the blue mailman"
|
47
|
-
# "CamelOctopi".singularize # => "CamelOctopus"
|
48
|
-
#
|
49
|
-
def singularize
|
50
|
-
ActiveSupport::Inflector.singularize(self)
|
51
|
-
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# +constantize+ tries to find a declared constant with the name specified
|
55
|
-
# in the string. It raises a NameError when the name is not in CamelCase
|
56
|
-
# or is not initialized.
|
57
|
-
#
|
58
|
-
# "Module".constantize # => Module
|
59
|
-
# "Class".constantize # => Class
|
60
|
-
#
|
61
|
-
def constantize
|
62
|
-
ActiveSupport::Inflector.constantize(self)
|
63
|
-
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
67
|
-
#
|
68
|
-
# +underscore+ will also change '::' to '/' to convert namespaces to paths.
|
69
|
-
#
|
70
|
-
# "ActiveRecord".underscore # => "active_record"
|
71
|
-
# "ActiveRecord::Errors".underscore # => active_record/errors
|
72
|
-
#
|
73
|
-
def underscore
|
74
|
-
ActiveSupport::Inflector.underscore(self)
|
75
|
-
end
|
76
|
-
|
77
|
-
##
|
78
|
-
# By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize
|
79
|
-
# is set to <tt>:lower</tt> then camelize produces lowerCamelCase.
|
80
|
-
#
|
81
|
-
# +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
|
82
|
-
#
|
83
|
-
# "active_record".camelize # => "ActiveRecord"
|
84
|
-
# "active_record".camelize(:lower) # => "activeRecord"
|
85
|
-
# "active_record/errors".camelize # => "ActiveRecord::Errors"
|
86
|
-
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
87
|
-
#
|
88
|
-
def camelize(first_letter = :upper)
|
89
|
-
case first_letter
|
90
|
-
when :upper then ActiveSupport::Inflector.camelize(self, true)
|
91
|
-
when :lower then ActiveSupport::Inflector.camelize(self, false)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
alias_method :camelcase, :camelize
|
95
|
-
|
96
|
-
##
|
97
|
-
# Create a class name from a plural table name like Rails does for table names to models.
|
98
|
-
# Note that this returns a string and not a class. (To convert to an actual class
|
99
|
-
# follow +classify+ with +constantize+.)
|
100
|
-
#
|
101
|
-
# "egg_and_hams".classify # => "EggAndHam"
|
102
|
-
# "posts".classify # => "Post"
|
103
|
-
#
|
104
|
-
# Singular names are not handled correctly.
|
105
|
-
#
|
106
|
-
# "business".classify # => "Busines"
|
107
|
-
#
|
108
|
-
def classify
|
109
|
-
ActiveSupport::Inflector.classify(self)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
module ObjectSpace
|
114
|
-
class << self
|
115
|
-
##
|
116
|
-
# Returns all the classes in the object space.
|
117
|
-
# Optionally, a block can be passed, for example the following code
|
118
|
-
# would return the classes that start with the character "A":
|
119
|
-
#
|
120
|
-
# ObjectSpace.classes do |klass|
|
121
|
-
# if klass.to_s[0] == "A"
|
122
|
-
# klass
|
123
|
-
# end
|
124
|
-
# end
|
125
|
-
#
|
126
|
-
def classes(&block)
|
127
|
-
rs = Set.new
|
128
|
-
|
129
|
-
ObjectSpace.each_object(Class).each do |klass|
|
130
|
-
if block
|
131
|
-
if r = block.call(klass)
|
132
|
-
# add the returned value if the block returns something
|
133
|
-
rs << r
|
134
|
-
end
|
135
|
-
else
|
136
|
-
rs << klass
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
rs
|
141
|
-
end
|
142
|
-
|
143
|
-
##
|
144
|
-
# Returns a list of existing classes that are not included in "snapshot"
|
145
|
-
# This method is useful to get the list of new classes that were loaded
|
146
|
-
# after an event like requiring a file.
|
147
|
-
# Usage:
|
148
|
-
#
|
149
|
-
# snapshot = ObjectSpace.classes
|
150
|
-
# # require a file
|
151
|
-
# ObjectSpace.new_classes(snapshot)
|
152
|
-
#
|
153
|
-
def new_classes(snapshot)
|
154
|
-
self.classes do |klass|
|
155
|
-
if !snapshot.include?(klass)
|
156
|
-
klass
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
##
|
164
|
-
# FileSet helper method for iterating and interacting with files inside a directory
|
165
|
-
#
|
166
|
-
module FileSet
|
167
|
-
extend self
|
168
|
-
##
|
169
|
-
# Iterates over every file in the glob pattern and yields to a block
|
170
|
-
# Returns the list of files matching the glob pattern
|
171
|
-
# FileSet.glob('padrino-core/application/*.rb', __FILE__) { |file| load file }
|
172
|
-
#
|
173
|
-
def glob(glob_pattern, file_path=nil, &block)
|
174
|
-
glob_pattern = File.join(File.dirname(file_path), glob_pattern) if file_path
|
175
|
-
file_list = Dir.glob(glob_pattern).sort
|
176
|
-
file_list.each { |file| block.call(file) }
|
177
|
-
file_list
|
178
|
-
end
|
179
|
-
|
180
|
-
##
|
181
|
-
# Requires each file matched in the glob pattern into the application
|
182
|
-
# FileSet.glob_require('padrino-core/application/*.rb', __FILE__)
|
183
|
-
#
|
184
|
-
def glob_require(glob_pattern, file_path=nil)
|
185
|
-
glob(glob_pattern, file_path) { |f| require f }
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
##
|
190
|
-
# Removes indentation
|
191
|
-
# Add colors
|
192
|
-
#
|
193
|
-
# @example
|
194
|
-
# help <<-EOS.undent
|
195
|
-
# Here my help usage
|
196
|
-
# sample_code
|
197
|
-
#
|
198
|
-
# Fix
|
199
|
-
# EOS
|
200
|
-
# puts help.red.bold
|
201
|
-
#
|
202
|
-
class String
|
203
|
-
# colorize(:red)
|
204
|
-
def colorize(color)
|
205
|
-
Colorizer.send(color, self)
|
206
|
-
end
|
207
|
-
|
208
|
-
# Used to colorize strings for the shell
|
209
|
-
class Colorizer
|
210
|
-
# Returns colors integer mapping
|
211
|
-
def self.colors
|
212
|
-
@_colors ||= {
|
213
|
-
:clear => 0,
|
214
|
-
:bold => 1,
|
215
|
-
:black => 30,
|
216
|
-
:red => 31,
|
217
|
-
:green => 32,
|
218
|
-
:yellow => 33,
|
219
|
-
:blue => 34,
|
220
|
-
:magenta => 35,
|
221
|
-
:cyan => 36,
|
222
|
-
:white => 37
|
223
|
-
}
|
224
|
-
end
|
225
|
-
|
226
|
-
# Defines class level color methods
|
227
|
-
# i.e Colorizer.red("hello")
|
228
|
-
class << self
|
229
|
-
Colorizer.colors.each do |color, value|
|
230
|
-
define_method(color) do |target|
|
231
|
-
"\e[#{value}m" << target << "\e[0m"
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
# Strip unnecessary indentation of the front of a string
|
238
|
-
def undent
|
239
|
-
gsub(/^.{#{slice(/^ +/).size}}/, '')
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
##
|
244
|
-
# Make sure we can always use the class name
|
245
|
-
# In reloader for accessing class_name Foo._orig_klass_name
|
246
|
-
#
|
247
|
-
class Module
|
248
|
-
alias :_orig_klass_name :to_s
|
249
|
-
end
|
250
|
-
|
251
|
-
##
|
252
|
-
# Loads our locale configuration files
|
253
|
-
#
|
254
|
-
I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n)
|
255
|
-
|
256
|
-
##
|
257
|
-
# Used to determine if this file has already been required
|
258
|
-
#
|
259
|
-
module SupportLite; end
|