Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
603c853a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
603c853a
编写于
5月 14, 2008
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't fallback to just adding "'s" in TextHelper#pluralize, because the Inflector is always loaded.
上级
bc3cc91a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
93 deletion
+73
-93
actionpack/lib/action_view/helpers/text_helper.rb
actionpack/lib/action_view/helpers/text_helper.rb
+59
-68
actionpack/test/template/text_helper_test.rb
actionpack/test/template/text_helper_test.rb
+14
-25
未找到文件。
actionpack/lib/action_view/helpers/text_helper.rb
浏览文件 @
603c853a
...
@@ -3,19 +3,19 @@
...
@@ -3,19 +3,19 @@
module
ActionView
module
ActionView
module
Helpers
#:nodoc:
module
Helpers
#:nodoc:
# The TextHelper module provides a set of methods for filtering, formatting
# The TextHelper module provides a set of methods for filtering, formatting
# and transforming strings, which can reduce the amount of inline Ruby code in
# and transforming strings, which can reduce the amount of inline Ruby code in
# your views. These helper methods extend ActionView making them callable
# your views. These helper methods extend ActionView making them callable
# within your template files.
# within your template files.
module
TextHelper
module
TextHelper
# The preferred method of outputting text in your views is to use the
# The preferred method of outputting text in your views is to use the
# <%= "text" %> eRuby syntax. The regular _puts_ and _print_ methods
# <%= "text" %> eRuby syntax. The regular _puts_ and _print_ methods
# do not operate as expected in an eRuby code block. If you absolutely must
# do not operate as expected in an eRuby code block. If you absolutely must
# output text within a non-output code block (i.e., <% %>), you can use the concat method.
# output text within a non-output code block (i.e., <% %>), you can use the concat method.
#
#
# ==== Examples
# ==== Examples
# <%
# <%
# concat "hello", binding
# concat "hello", binding
# # is the equivalent of <%= "hello" %>
# # is the equivalent of <%= "hello" %>
#
#
# if (logged_in == true):
# if (logged_in == true):
...
@@ -30,15 +30,15 @@ def concat(string, binding)
...
@@ -30,15 +30,15 @@ def concat(string, binding)
end
end
if
RUBY_VERSION
<
'1.9'
if
RUBY_VERSION
<
'1.9'
# If +text+ is longer than +length+, +text+ will be truncated to the length of
# If +text+ is longer than +length+, +text+ will be truncated to the length of
# +length+ (defaults to 30) and the last characters will be replaced with the +truncate_string+
# +length+ (defaults to 30) and the last characters will be replaced with the +truncate_string+
# (defaults to "...").
# (defaults to "...").
#
#
# ==== Examples
# ==== Examples
# truncate("Once upon a time in a world far far away", 14)
# truncate("Once upon a time in a world far far away", 14)
# # => Once upon a...
# # => Once upon a...
#
#
# truncate("Once upon a time in a world far far away")
# truncate("Once upon a time in a world far far away")
# # => Once upon a time in a world f...
# # => Once upon a time in a world f...
#
#
# truncate("And they found that many people were sleeping better.", 25, "(clipped)")
# truncate("And they found that many people were sleeping better.", 25, "(clipped)")
...
@@ -63,20 +63,20 @@ def truncate(text, length = 30, truncate_string = "...") #:nodoc:
...
@@ -63,20 +63,20 @@ def truncate(text, length = 30, truncate_string = "...") #:nodoc:
end
end
# Highlights one or more +phrases+ everywhere in +text+ by inserting it into
# Highlights one or more +phrases+ everywhere in +text+ by inserting it into
# a +highlighter+ string. The highlighter can be specialized by passing +highlighter+
# a +highlighter+ string. The highlighter can be specialized by passing +highlighter+
# as a single-quoted string with \1 where the phrase is to be inserted (defaults to
# as a single-quoted string with \1 where the phrase is to be inserted (defaults to
# '<strong class="highlight">\1</strong>')
# '<strong class="highlight">\1</strong>')
#
#
# ==== Examples
# ==== Examples
# highlight('You searched for: rails', 'rails')
# highlight('You searched for: rails', 'rails')
# # => You searched for: <strong class="highlight">rails</strong>
# # => You searched for: <strong class="highlight">rails</strong>
#
#
# highlight('You searched for: ruby, rails, dhh', 'actionpack')
# highlight('You searched for: ruby, rails, dhh', 'actionpack')
# # => You searched for: ruby, rails, dhh
# # => You searched for: ruby, rails, dhh
#
#
# highlight('You searched for: rails', ['for', 'rails'], '<em>\1</em>')
# highlight('You searched for: rails', ['for', 'rails'], '<em>\1</em>')
# # => You searched <em>for</em>: <em>rails</em>
# # => You searched <em>for</em>: <em>rails</em>
#
#
# highlight('You searched for: rails', 'rails', "<a href='search?q=\1'>\1</a>")
# highlight('You searched for: rails', 'rails', "<a href='search?q=\1'>\1</a>")
# # => You searched for: <a href='search?q=rails>rails</a>
# # => You searched for: <a href='search?q=rails>rails</a>
def
highlight
(
text
,
phrases
,
highlighter
=
'<strong class="highlight">\1</strong>'
)
def
highlight
(
text
,
phrases
,
highlighter
=
'<strong class="highlight">\1</strong>'
)
...
@@ -89,23 +89,23 @@ def highlight(text, phrases, highlighter = '<strong class="highlight">\1</strong
...
@@ -89,23 +89,23 @@ def highlight(text, phrases, highlighter = '<strong class="highlight">\1</strong
end
end
if
RUBY_VERSION
<
'1.9'
if
RUBY_VERSION
<
'1.9'
# Extracts an excerpt from +text+ that matches the first instance of +phrase+.
# Extracts an excerpt from +text+ that matches the first instance of +phrase+.
# The +radius+ expands the excerpt on each side of the first occurrence of +phrase+ by the number of characters
# The +radius+ expands the excerpt on each side of the first occurrence of +phrase+ by the number of characters
# defined in +radius+ (which defaults to 100). If the excerpt radius overflows the beginning or end of the +text+,
# defined in +radius+ (which defaults to 100). If the excerpt radius overflows the beginning or end of the +text+,
# then the +excerpt_string+ will be prepended/appended accordingly. The resulting string will be stripped in any case.
# then the +excerpt_string+ will be prepended/appended accordingly. The resulting string will be stripped in any case.
# If the +phrase+ isn't found, nil is returned.
# If the +phrase+ isn't found, nil is returned.
#
#
# ==== Examples
# ==== Examples
# excerpt('This is an example', 'an', 5)
# excerpt('This is an example', 'an', 5)
# # => "...s is an exam..."
# # => "...s is an exam..."
#
#
# excerpt('This is an example', 'is', 5)
# excerpt('This is an example', 'is', 5)
# # => "This is a..."
# # => "This is a..."
#
#
# excerpt('This is an example', 'is')
# excerpt('This is an example', 'is')
# # => "This is an example"
# # => "This is an example"
#
#
# excerpt('This next thing is an example', 'ex', 2)
# excerpt('This next thing is an example', 'ex', 2)
# # => "...next..."
# # => "...next..."
#
#
# excerpt('This is also an example', 'an', 8, '<chop> ')
# excerpt('This is also an example', 'an', 8, '<chop> ')
...
@@ -147,33 +147,24 @@ def excerpt(text, phrase, radius = 100, excerpt_string = "...") #:nodoc:
...
@@ -147,33 +147,24 @@ def excerpt(text, phrase, radius = 100, excerpt_string = "...") #:nodoc:
end
end
end
end
# Attempts to pluralize the +singular+ word unless +count+ is 1. If +plural+
# Attempts to pluralize the +singular+ word unless +count+ is 1. If
# is supplied, it will use that when count is > 1, if the ActiveSupport Inflector
# +plural+ is supplied, it will use that when count is > 1, otherwise
# is loaded, it will use the Inflector to determine the plural form, otherwise
# it will use the Inflector to determine the plural form
# it will just add an 's' to the +singular+ word.
#
#
# ==== Examples
# ==== Examples
# pluralize(1, 'person')
# pluralize(1, 'person')
# # => 1 person
# # => 1 person
#
#
# pluralize(2, 'person')
# pluralize(2, 'person')
# # => 2 people
# # => 2 people
#
#
# pluralize(3, 'person', 'users')
# pluralize(3, 'person', 'users')
# # => 3 users
# # => 3 users
#
#
# pluralize(0, 'person')
# pluralize(0, 'person')
# # => 0 people
# # => 0 people
def
pluralize
(
count
,
singular
,
plural
=
nil
)
def
pluralize
(
count
,
singular
,
plural
=
nil
)
"
#{
count
||
0
}
"
+
if
count
==
1
||
count
==
'1'
"
#{
count
||
0
}
"
+
((
count
==
1
||
count
==
'1'
)
?
singular
:
(
plural
||
singular
.
pluralize
))
singular
elsif
plural
plural
elsif
Object
.
const_defined?
(
"Inflector"
)
Inflector
.
pluralize
(
singular
)
else
singular
+
"s"
end
end
end
# Wraps the +text+ into lines no longer than +line_width+ width. This method
# Wraps the +text+ into lines no longer than +line_width+ width. This method
...
@@ -229,7 +220,7 @@ def textilize(text)
...
@@ -229,7 +220,7 @@ def textilize(text)
end
end
end
end
# Returns the text with all the Textile codes turned into HTML tags,
# Returns the text with all the Textile codes turned into HTML tags,
# but without the bounding <p> tag that RedCloth adds.
# but without the bounding <p> tag that RedCloth adds.
#
#
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
...
@@ -273,25 +264,25 @@ def textilize_without_paragraph(text)
...
@@ -273,25 +264,25 @@ def textilize_without_paragraph(text)
# # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>"
# # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>"
#
#
# markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.")
# markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.")
# # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a>
# # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a>
# # has more information.</p>"
# # has more information.</p>"
#
#
# markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")')
# markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")')
# # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
# # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
def
markdown
(
text
)
def
markdown
(
text
)
text
.
blank?
?
""
:
BlueCloth
.
new
(
text
).
to_html
text
.
blank?
?
""
:
BlueCloth
.
new
(
text
).
to_html
end
end
rescue
LoadError
rescue
LoadError
# We can't really help what's not there
# We can't really help what's not there
end
end
# Returns +text+ transformed into HTML using simple formatting rules.
# Returns +text+ transformed into HTML using simple formatting rules.
# Two or more consecutive newlines(<tt>\n\n</tt>) are considered as a
# Two or more consecutive newlines(<tt>\n\n</tt>) are considered as a
# paragraph and wrapped in <tt><p></tt> tags. One newline (<tt>\n</tt>) is
# paragraph and wrapped in <tt><p></tt> tags. One newline (<tt>\n</tt>) is
# considered as a linebreak and a <tt><br /></tt> tag is appended. This
# considered as a linebreak and a <tt><br /></tt> tag is appended. This
# method does not remove the newlines from the +text+.
# method does not remove the newlines from the +text+.
#
#
# You can pass any HTML attributes into <tt>html_options</tt>. These
# You can pass any HTML attributes into <tt>html_options</tt>. These
# will be added to all created paragraphs.
# will be added to all created paragraphs.
# ==== Examples
# ==== Examples
# my_text = "Here is some basic text...\n...with a line break."
# my_text = "Here is some basic text...\n...with a line break."
...
@@ -316,19 +307,19 @@ def simple_format(text, html_options={})
...
@@ -316,19 +307,19 @@ def simple_format(text, html_options={})
text
<<
"</p>"
text
<<
"</p>"
end
end
# Turns all URLs and e-mail addresses into clickable links. The +link+ parameter
# Turns all URLs and e-mail addresses into clickable links. The +link+ parameter
# will limit what should be linked. You can add HTML attributes to the links using
# will limit what should be linked. You can add HTML attributes to the links using
# +href_options+. Options for +link+ are <tt>:all</tt> (default),
# +href_options+. Options for +link+ are <tt>:all</tt> (default),
# <tt>:email_addresses</tt>, and <tt>:urls</tt>. If a block is given, each URL and
# <tt>:email_addresses</tt>, and <tt>:urls</tt>. If a block is given, each URL and
# e-mail address is yielded and the result is used as the link text.
# e-mail address is yielded and the result is used as the link text.
#
#
# ==== Examples
# ==== Examples
# auto_link("Go to http://www.rubyonrails.org and say hello to david@loudthinking.com")
# auto_link("Go to http://www.rubyonrails.org and say hello to david@loudthinking.com")
# # => "Go to <a href=\"http://www.rubyonrails.org\">http://www.rubyonrails.org</a> and
# # => "Go to <a href=\"http://www.rubyonrails.org\">http://www.rubyonrails.org</a> and
# # say hello to <a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>"
# # say hello to <a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>"
#
#
# auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :urls)
# auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :urls)
# # => "Visit <a href=\"http://www.loudthinking.com/\">http://www.loudthinking.com/</a>
# # => "Visit <a href=\"http://www.loudthinking.com/\">http://www.loudthinking.com/</a>
# # or e-mail david@loudthinking.com"
# # or e-mail david@loudthinking.com"
#
#
# auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :email_addresses)
# auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :email_addresses)
...
@@ -338,9 +329,9 @@ def simple_format(text, html_options={})
...
@@ -338,9 +329,9 @@ def simple_format(text, html_options={})
# auto_link(post_body, :all, :target => '_blank') do |text|
# auto_link(post_body, :all, :target => '_blank') do |text|
# truncate(text, 15)
# truncate(text, 15)
# end
# end
# # => "Welcome to my new blog at <a href=\"http://www.myblog.com/\" target=\"_blank\">http://www.m...</a>.
# # => "Welcome to my new blog at <a href=\"http://www.myblog.com/\" target=\"_blank\">http://www.m...</a>.
# Please e-mail me at <a href=\"mailto:me@email.com\">me@email.com</a>."
# Please e-mail me at <a href=\"mailto:me@email.com\">me@email.com</a>."
#
#
def
auto_link
(
text
,
link
=
:all
,
href_options
=
{},
&
block
)
def
auto_link
(
text
,
link
=
:all
,
href_options
=
{},
&
block
)
return
''
if
text
.
blank?
return
''
if
text
.
blank?
case
link
case
link
...
@@ -349,15 +340,15 @@ def auto_link(text, link = :all, href_options = {}, &block)
...
@@ -349,15 +340,15 @@ def auto_link(text, link = :all, href_options = {}, &block)
when
:urls
then
auto_link_urls
(
text
,
href_options
,
&
block
)
when
:urls
then
auto_link_urls
(
text
,
href_options
,
&
block
)
end
end
end
end
# Creates a Cycle object whose _to_s_ method cycles through elements of an
# Creates a Cycle object whose _to_s_ method cycles through elements of an
# array every time it is called. This can be used for example, to alternate
# array every time it is called. This can be used for example, to alternate
# classes for table rows. You can use named cycles to allow nesting in loops.
# classes for table rows. You can use named cycles to allow nesting in loops.
# Passing a Hash as the last parameter with a <tt>:name</tt> key will create a
# Passing a Hash as the last parameter with a <tt>:name</tt> key will create a
# named cycle. You can manually reset a cycle by calling reset_cycle and passing the
# named cycle. You can manually reset a cycle by calling reset_cycle and passing the
# name of the cycle.
# name of the cycle.
#
#
# ==== Examples
# ==== Examples
# # Alternate CSS classes for even and odd numbers...
# # Alternate CSS classes for even and odd numbers...
# @items = [1,2,3,4]
# @items = [1,2,3,4]
# <table>
# <table>
...
@@ -370,8 +361,8 @@ def auto_link(text, link = :all, href_options = {}, &block)
...
@@ -370,8 +361,8 @@ def auto_link(text, link = :all, href_options = {}, &block)
#
#
#
#
# # Cycle CSS classes for rows, and text colors for values within each row
# # Cycle CSS classes for rows, and text colors for values within each row
# @items = x = [{:first => 'Robert', :middle => 'Daniel', :last => 'James'},
# @items = x = [{:first => 'Robert', :middle => 'Daniel', :last => 'James'},
# {:first => 'Emily', :middle => 'Shannon', :maiden => 'Pike', :last => 'Hicks'},
# {:first => 'Emily', :middle => 'Shannon', :maiden => 'Pike', :last => 'Hicks'},
# {:first => 'June', :middle => 'Dae', :last => 'Jones'}]
# {:first => 'June', :middle => 'Dae', :last => 'Jones'}]
# <% @items.each do |item| %>
# <% @items.each do |item| %>
# <tr class="<%= cycle("even", "odd", :name => "row_class") -%>">
# <tr class="<%= cycle("even", "odd", :name => "row_class") -%>">
...
@@ -401,8 +392,8 @@ def cycle(first_value, *values)
...
@@ -401,8 +392,8 @@ def cycle(first_value, *values)
end
end
return
cycle
.
to_s
return
cycle
.
to_s
end
end
# Resets a cycle so that it starts from the first element the next time
# Resets a cycle so that it starts from the first element the next time
# it is called. Pass in +name+ to reset a named cycle.
# it is called. Pass in +name+ to reset a named cycle.
#
#
# ==== Example
# ==== Example
...
@@ -428,12 +419,12 @@ def reset_cycle(name = "default")
...
@@ -428,12 +419,12 @@ def reset_cycle(name = "default")
class
Cycle
#:nodoc:
class
Cycle
#:nodoc:
attr_reader
:values
attr_reader
:values
def
initialize
(
first_value
,
*
values
)
def
initialize
(
first_value
,
*
values
)
@values
=
values
.
unshift
(
first_value
)
@values
=
values
.
unshift
(
first_value
)
reset
reset
end
end
def
reset
def
reset
@index
=
0
@index
=
0
end
end
...
@@ -453,7 +444,7 @@ def get_cycle(name)
...
@@ -453,7 +444,7 @@ def get_cycle(name)
@_cycles
=
Hash
.
new
unless
defined?
(
@_cycles
)
@_cycles
=
Hash
.
new
unless
defined?
(
@_cycles
)
return
@_cycles
[
name
]
return
@_cycles
[
name
]
end
end
def
set_cycle
(
name
,
cycle_object
)
def
set_cycle
(
name
,
cycle_object
)
@_cycles
=
Hash
.
new
unless
defined?
(
@_cycles
)
@_cycles
=
Hash
.
new
unless
defined?
(
@_cycles
)
@_cycles
[
name
]
=
cycle_object
@_cycles
[
name
]
=
cycle_object
...
@@ -462,13 +453,13 @@ def set_cycle(name, cycle_object)
...
@@ -462,13 +453,13 @@ def set_cycle(name, cycle_object)
AUTO_LINK_RE
=
%r{
AUTO_LINK_RE
=
%r{
( # leading text
( # leading text
<
\w
+.*?>| # leading HTML tag, or
<
\w
+.*?>| # leading HTML tag, or
[^=!:'"/]| # leading punctuation, or
[^=!:'"/]| # leading punctuation, or
^ # beginning of line
^ # beginning of line
)
)
(
(
(?:https?://)| # protocol spec, or
(?:https?://)| # protocol spec, or
(?:www
\.
) # www.*
(?:www
\.
) # www.*
)
)
(
(
[-
\w
]+ # subdomain or domain
[-
\w
]+ # subdomain or domain
(?:
\.
[-
\w
]+)* # remaining subdomains or domain
(?:
\.
[-
\w
]+)* # remaining subdomains or domain
...
@@ -502,7 +493,7 @@ def auto_link_email_addresses(text)
...
@@ -502,7 +493,7 @@ def auto_link_email_addresses(text)
body
=
text
.
dup
body
=
text
.
dup
text
.
gsub
(
/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/
)
do
text
.
gsub
(
/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/
)
do
text
=
$1
text
=
$1
if
body
.
match
(
/<a\b[^>]*>(.*)(
#{
Regexp
.
escape
(
text
)
}
)(.*)<\/a>/
)
if
body
.
match
(
/<a\b[^>]*>(.*)(
#{
Regexp
.
escape
(
text
)
}
)(.*)<\/a>/
)
text
text
else
else
...
...
actionpack/test/template/text_helper_test.rb
浏览文件 @
603c853a
...
@@ -23,9 +23,9 @@ def test_simple_format
...
@@ -23,9 +23,9 @@ def test_simple_format
text
=
"A
\r\n
\n
B
\n\n\r\n\t\n
C
\n
D"
.
freeze
text
=
"A
\r\n
\n
B
\n\n\r\n\t\n
C
\n
D"
.
freeze
assert_equal
"<p>A
\n
<br />
\n
<br />B</p>
\n\n
<p>
\t\n
<br />C
\n
<br />D</p>"
,
simple_format
(
text
)
assert_equal
"<p>A
\n
<br />
\n
<br />B</p>
\n\n
<p>
\t\n
<br />C
\n
<br />D</p>"
,
simple_format
(
text
)
assert_equal
%q(<p class="test">This is a classy test</p>)
,
simple_format
(
"This is a classy test"
,
:class
=>
'test'
)
assert_equal
%q(<p class="test">This is a classy test</p>)
,
simple_format
(
"This is a classy test"
,
:class
=>
'test'
)
assert_equal
%Q(<p class="test">para 1</p>
\n\n
<p class="test">para 2</p>)
,
simple_format
(
"para 1
\n\n
para 2"
,
:class
=>
'test'
)
assert_equal
%Q(<p class="test">para 1</p>
\n\n
<p class="test">para 2</p>)
,
simple_format
(
"para 1
\n\n
para 2"
,
:class
=>
'test'
)
end
end
def
test_truncate
def
test_truncate
...
@@ -41,7 +41,7 @@ def test_truncate_should_use_default_length_of_30
...
@@ -41,7 +41,7 @@ def test_truncate_should_use_default_length_of_30
if
RUBY_VERSION
<
'1.9.0'
if
RUBY_VERSION
<
'1.9.0'
def
test_truncate_multibyte
def
test_truncate_multibyte
with_kcode
'none'
do
with_kcode
'none'
do
assert_equal
"
\354\225\210\353\205\225\355
..."
,
truncate
(
"
\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224
"
,
10
)
assert_equal
"
\354\225\210\353\205\225\355
..."
,
truncate
(
"
\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224
"
,
10
)
end
end
with_kcode
'u'
do
with_kcode
'u'
do
assert_equal
"
\354\225\204\353\246\254\353\236\221
\354\225\204\353\246\254
..."
,
assert_equal
"
\354\225\204\353\246\254\353\236\221
\354\225\204\353\246\254
..."
,
...
@@ -73,7 +73,7 @@ def test_highlighter
...
@@ -73,7 +73,7 @@ def test_highlighter
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day"
,
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day"
,
highlight
(
"This is a beautiful morning, but also a beautiful day"
,
"beautiful"
,
'<b>\1</b>'
)
highlight
(
"This is a beautiful morning, but also a beautiful day"
,
"beautiful"
,
'<b>\1</b>'
)
)
)
assert_equal
(
assert_equal
(
"This text is not changed because we supplied an empty phrase"
,
"This text is not changed because we supplied an empty phrase"
,
highlight
(
"This text is not changed because we supplied an empty phrase"
,
nil
)
highlight
(
"This text is not changed because we supplied an empty phrase"
,
nil
)
...
@@ -166,18 +166,7 @@ def test_pluralization
...
@@ -166,18 +166,7 @@ def test_pluralization
assert_equal
(
"2 counters"
,
pluralize
(
2
,
"count"
,
"counters"
))
assert_equal
(
"2 counters"
,
pluralize
(
2
,
"count"
,
"counters"
))
assert_equal
(
"0 counters"
,
pluralize
(
nil
,
"count"
,
"counters"
))
assert_equal
(
"0 counters"
,
pluralize
(
nil
,
"count"
,
"counters"
))
assert_equal
(
"2 people"
,
pluralize
(
2
,
"person"
))
assert_equal
(
"2 people"
,
pluralize
(
2
,
"person"
))
assert_equal
(
"10 buffaloes"
,
pluralize
(
10
,
"buffalo"
))
assert_equal
(
"10 buffaloes"
,
pluralize
(
10
,
"buffalo"
))
end
uses_mocha
(
"should_just_add_s_for_pluralize_without_inflector_loaded"
)
do
def
test_should_just_add_s_for_pluralize_without_inflector_loaded
Object
.
expects
(
:const_defined?
).
with
(
"Inflector"
).
times
(
4
).
returns
(
false
)
assert_equal
(
"1 count"
,
pluralize
(
1
,
"count"
))
assert_equal
(
"2 persons"
,
pluralize
(
2
,
"person"
))
assert_equal
(
"2 personss"
,
pluralize
(
"2"
,
"persons"
))
assert_equal
(
"2 counts"
,
pluralize
(
2
,
"count"
))
assert_equal
(
"10 buffalos"
,
pluralize
(
10
,
"buffalo"
))
end
end
end
def
test_auto_link_parsing
def
test_auto_link_parsing
...
@@ -298,7 +287,7 @@ def test_cycle_class
...
@@ -298,7 +287,7 @@ def test_cycle_class
assert_equal
(
"2"
,
value
.
to_s
)
assert_equal
(
"2"
,
value
.
to_s
)
assert_equal
(
"3"
,
value
.
to_s
)
assert_equal
(
"3"
,
value
.
to_s
)
end
end
def
test_cycle_class_with_no_arguments
def
test_cycle_class_with_no_arguments
assert_raise
(
ArgumentError
)
{
value
=
Cycle
.
new
()
}
assert_raise
(
ArgumentError
)
{
value
=
Cycle
.
new
()
}
end
end
...
@@ -311,11 +300,11 @@ def test_cycle
...
@@ -311,11 +300,11 @@ def test_cycle
assert_equal
(
"2"
,
cycle
(
"one"
,
2
,
"3"
))
assert_equal
(
"2"
,
cycle
(
"one"
,
2
,
"3"
))
assert_equal
(
"3"
,
cycle
(
"one"
,
2
,
"3"
))
assert_equal
(
"3"
,
cycle
(
"one"
,
2
,
"3"
))
end
end
def
test_cycle_with_no_arguments
def
test_cycle_with_no_arguments
assert_raise
(
ArgumentError
)
{
value
=
cycle
()
}
assert_raise
(
ArgumentError
)
{
value
=
cycle
()
}
end
end
def
test_cycle_resets_with_new_values
def
test_cycle_resets_with_new_values
assert_equal
(
"even"
,
cycle
(
"even"
,
"odd"
))
assert_equal
(
"even"
,
cycle
(
"even"
,
"odd"
))
assert_equal
(
"odd"
,
cycle
(
"even"
,
"odd"
))
assert_equal
(
"odd"
,
cycle
(
"even"
,
"odd"
))
...
@@ -325,7 +314,7 @@ def test_cycle_resets_with_new_values
...
@@ -325,7 +314,7 @@ def test_cycle_resets_with_new_values
assert_equal
(
"3"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"3"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
end
end
def
test_named_cycles
def
test_named_cycles
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
...
@@ -334,24 +323,24 @@ def test_named_cycles
...
@@ -334,24 +323,24 @@ def test_named_cycles
assert_equal
(
"3"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"3"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
end
end
def
test_default_named_cycle
def
test_default_named_cycle
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"2"
,
cycle
(
1
,
2
,
3
,
:name
=>
"default"
))
assert_equal
(
"2"
,
cycle
(
1
,
2
,
3
,
:name
=>
"default"
))
assert_equal
(
"3"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"3"
,
cycle
(
1
,
2
,
3
))
end
end
def
test_reset_cycle
def
test_reset_cycle
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"2"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"2"
,
cycle
(
1
,
2
,
3
))
reset_cycle
reset_cycle
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
))
end
end
def
test_reset_unknown_cycle
def
test_reset_unknown_cycle
reset_cycle
(
"colors"
)
reset_cycle
(
"colors"
)
end
end
def
test_recet_named_cycle
def
test_recet_named_cycle
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"1"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
...
@@ -361,7 +350,7 @@ def test_recet_named_cycle
...
@@ -361,7 +350,7 @@ def test_recet_named_cycle
assert_equal
(
"2"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"2"
,
cycle
(
1
,
2
,
3
,
:name
=>
"numbers"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
,
:name
=>
"colors"
))
end
end
def
test_cycle_no_instance_variable_clashes
def
test_cycle_no_instance_variable_clashes
@cycles
=
%w{Specialized Fuji Giant}
@cycles
=
%w{Specialized Fuji Giant}
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
))
assert_equal
(
"red"
,
cycle
(
"red"
,
"blue"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录