rutils 0.1.8 → 0.1.9
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.
- data/CHANGELOG +3 -0
- data/lib/datetime/datetime.rb +22 -3
- data/lib/integration/red_cloth_override.rb +10 -1
- data/lib/rutils.rb +1 -1
- data/test/t_datetime.rb +3 -2
- data/test/t_gilenson.rb +1 -1
- data/test/t_integration.rb +14 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/datetime/datetime.rb
CHANGED
@@ -59,8 +59,27 @@ end
|
|
59
59
|
class Time
|
60
60
|
alias_method :strftime_norutils, :strftime
|
61
61
|
|
62
|
-
def strftime(
|
63
|
-
RuTils::DateTime::ru_strftime(
|
64
|
-
strftime_norutils(
|
62
|
+
def strftime(fmt)
|
63
|
+
RuTils::DateTime::ru_strftime(fmt, self) if RuTils::overrides_enabled?
|
64
|
+
strftime_norutils(fmt)
|
65
65
|
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Date
|
69
|
+
|
70
|
+
# Inside rails we have date formatting
|
71
|
+
if self.instance_methods.include?('strftime')
|
72
|
+
alias_method :strftime_norutils, :strftime
|
73
|
+
def strftime(fmt=nil)
|
74
|
+
RuTils::DateTime::ru_strftime(fmt, self) if RuTils::overrides_enabled?
|
75
|
+
strftime_norutils(fmt)
|
76
|
+
end
|
77
|
+
|
78
|
+
else
|
79
|
+
def strftime(fmt=nil)
|
80
|
+
RuTils::DateTime::ru_strftime(fmt, self) if RuTils::overrides_enabled?
|
81
|
+
self.to_time.strftime(fmt)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
66
85
|
end
|
@@ -12,7 +12,16 @@ if defined?(Object::RedCloth) and (!RedCloth.instance_methods.include?(:stock_pg
|
|
12
12
|
# Вместо того чтобы влезать в чужие таблицы мы просто заменим Textile Glyphs на Gilenson - и все будут рады.
|
13
13
|
alias_method :stock_pgl, :pgl
|
14
14
|
def pgl(text) #:nodoc:
|
15
|
-
RuTils::overrides_enabled?
|
15
|
+
if RuTils::overrides_enabled?
|
16
|
+
# Suspend the spaces in the start and end of the block because Gilenson chews them off, and RedCloth feeds them to us in packs
|
17
|
+
# that appear between tag starts/stops. We mess up the formatting but preserve the spacing.
|
18
|
+
spaces = Array.new(2,'')
|
19
|
+
text.gsub!(/\A([\s]+)/) { spaces[0] = $1; '' }
|
20
|
+
text.gsub!(/(\s+)\Z/) { spaces[1] = $1; '' }
|
21
|
+
text.replace(spaces[0].to_s + RuTils::Gilenson::Formatter.new(text).to_html + spaces[1].to_s)
|
22
|
+
else
|
23
|
+
stock_pgl(text)
|
24
|
+
end
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
data/lib/rutils.rb
CHANGED
data/test/t_datetime.rb
CHANGED
@@ -23,8 +23,9 @@ class StrftimeRuTest < Test::Unit::TestCase
|
|
23
23
|
assert_equal "Сегодня: 31 декабря, суббота, 2005 года", Time.local(2005,"dec",31).strftime("Сегодня: %d %B, %A, %Y года")
|
24
24
|
assert_equal "Сегодня: ноябрь, 30 число, дождик в четверг, а год у нас - 2006", Time.local(2006,11,30).strftime("Сегодня: %B, %d число, дождик в %A, а год у нас - %Y")
|
25
25
|
|
26
|
-
date = Date.new(2005,
|
27
|
-
assert_equal "
|
26
|
+
date = Date.new(2005, 12, 31)
|
27
|
+
assert_equal "дек декабрь сб суббота", "#{Date::RU_ABBR_MONTHNAMES[date.mon]} #{Date::RU_MONTHNAMES[date.mon]} #{Date::RU_ABBR_DAYNAMES[date.wday]} #{Date::RU_DAYNAMES[date.wday]}"
|
28
|
+
assert_equal "сб, суббота, дек, декабрь", date.strftime("%a, %A, %b, %B")
|
28
29
|
|
29
30
|
RuTils::overrides = false
|
30
31
|
assert_equal "Sat, Saturday, Dec, December", Time.local(2005,"dec",31).strftime("%a, %A, %b, %B")
|
data/test/t_gilenson.rb
CHANGED
@@ -61,7 +61,7 @@ class GilensonOwnTest < Test::Unit::TestCase
|
|
61
61
|
assert_equal 'при установке командой строки в ?page=help <nobr>бла-бла-бла-бла</nobr>', 'при установке командой строки в ?page=help бла-бла-бла-бла'.gilensize
|
62
62
|
assert_equal 'как интересно будет переноситься со строки на строку <nobr>что-то</nobr> разделённое дефисом, ведь дефис тот тоже ведь из наших. <nobr>Какие-то</nobr> браузеры думают, что следует переносить и его…', 'как интересно будет переноситься со строки на строку что-то разделённое дефисом, ведь дефис тот тоже ведь из наших. Какие-то браузеры думают, что следует переносить и его...'.gilensize
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def test_quotes
|
66
66
|
assert_equal 'english “quotes” should be quite like this', 'english "quotes" should be quite like this'.gilensize
|
67
67
|
assert_equal 'русские же «оформляются» подобным образом', 'русские же "оформляются" подобным образом'.gilensize
|
data/test/t_integration.rb
CHANGED
@@ -47,10 +47,22 @@ class TextileIntegrationTest < Test::Unit::TestCase
|
|
47
47
|
assert_equal "<p>И вот «они пошли туда», и шли шли шли</p>",
|
48
48
|
RedCloth.new('И вот "они пошли туда", и шли шли шли').to_html
|
49
49
|
|
50
|
+
RuTils::overrides = false
|
51
|
+
assert !RuTils::overrides_enabled?
|
52
|
+
assert_equal '<p><strong>strong text</strong> and <em>emphasized text</em></p>',
|
53
|
+
RedCloth.new("*strong text* and _emphasized text_").to_html, "Spaces should be preserved \
|
54
|
+
without RuTils"
|
55
|
+
|
56
|
+
RuTils::overrides = true
|
57
|
+
assert RuTils.overrides_enabled?
|
58
|
+
assert_equal '<p><strong>strong text</strong> and <em>emphasized text</em></p>',
|
59
|
+
RedCloth.new("*strong text* and _emphasized text_").to_html, "Spaces should be preserved"
|
60
|
+
|
50
61
|
RuTils::overrides = false
|
51
62
|
assert !RuTils.overrides_enabled?
|
52
63
|
assert_equal "<p>И вот “они пошли туда”, и шли шли шли</p>",
|
53
64
|
RedCloth.new('И вот "они пошли туда", и шли шли шли').to_html
|
65
|
+
|
54
66
|
end
|
55
67
|
end
|
56
68
|
|
@@ -73,7 +85,7 @@ class MarkdownIntegrationTest < Test::Unit::TestCase
|
|
73
85
|
end
|
74
86
|
|
75
87
|
TEST_DATE = Date.parse("1983-10-15") # coincidentially...
|
76
|
-
|
88
|
+
TEST_TIME = Time.local(1983, 10, 15, 12, 15) # also coincidentially...
|
77
89
|
# Перегрузка helper'ов Rails
|
78
90
|
class RailsHelpersOverrideTest < Test::Unit::TestCase
|
79
91
|
def test_distance_of_time_in_words
|
@@ -106,6 +118,7 @@ class RailsHelpersOverrideTest < Test::Unit::TestCase
|
|
106
118
|
assert_match /декабря/, stub.get_date_select, "Имя месяца должно быть указано в родительном падеже"
|
107
119
|
assert_match /декабря/, stub.get_date_select_without_day,
|
108
120
|
"Хелпер select_date не позволяет опускать фрагменты, имя месяца должно быть указано в родительном падеже"
|
121
|
+
|
109
122
|
end
|
110
123
|
end
|
111
124
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rutils
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-02-
|
6
|
+
version: 0.1.9
|
7
|
+
date: 2007-02-17 00:00:00 +01:00
|
8
8
|
summary: Simple processing of russian strings
|
9
9
|
require_paths:
|
10
10
|
- lib
|