Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dc88847e
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,发现更多精彩内容 >>
提交
dc88847e
编写于
3月 17, 2009
作者:
P
Pratik Naik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Try to use actionpack gem to generate guide when Rails is not vendored
上级
18eb80cc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
155 deletion
+19
-155
railties/guides/rails_guides.rb
railties/guides/rails_guides.rb
+19
-9
railties/guides/rails_guides/generator.rb
railties/guides/rails_guides/generator.rb
+0
-34
railties/guides/rails_guides/levenshtein.rb
railties/guides/rails_guides/levenshtein.rb
+0
-112
未找到文件。
railties/guides/rails_guides.rb
浏览文件 @
dc88847e
pwd
=
File
.
dirname
(
__FILE__
)
$:
<<
pwd
$:
<<
File
.
join
(
pwd
,
"../../activesupport/lib"
)
$:
<<
File
.
join
(
pwd
,
"../../actionpack/lib"
)
require
"action_controller"
require
"action_view"
begin
as_lib
=
File
.
join
(
pwd
,
"../../activesupport/lib"
)
ap_lib
=
File
.
join
(
pwd
,
"../../actionpack/lib"
)
$:
<<
as_lib
if
File
.
directory?
(
as_lib
)
$:
<<
ap_lib
if
File
.
directory?
(
ap_lib
)
require
"action_controller"
require
"action_view"
rescue
LoadError
require
'rubygems'
gem
"actionpack"
,
'>= 2.3'
require
"action_controller"
require
"action_view"
end
# Require rubygems after loading Action View
require
'rubygems'
begin
gem
'RedCloth'
,
'>= 4.1.1'
# Need exactly 4.1.1
require
'rubygems'
gem
'RedCloth'
,
'>= 4.1.1'
rescue
Gem
::
LoadError
$stderr
.
puts
%(
Missing the RedCloth 4.1.1 gem.\nPlease `gem install -v=4.1.1 RedCloth` to generate the guides.
)
$stderr
.
puts
%(
Generating Guides requires RedCloth 4.1.1+
)
exit
1
end
...
...
@@ -22,7 +33,6 @@ module RailsGuides
autoload
:Indexer
,
"rails_guides/indexer"
autoload
:Helpers
,
"rails_guides/helpers"
autoload
:TextileExtensions
,
"rails_guides/textile_extensions"
autoload
:Levenshtein
,
"rails_guides/levenshtein"
end
RedCloth
.
send
(
:include
,
RailsGuides
::
TextileExtensions
)
...
...
railties/guides/rails_guides/generator.rb
浏览文件 @
dc88847e
...
...
@@ -57,7 +57,6 @@ def generate_guide(guide)
result
=
view
.
render
(
:layout
=>
'layout'
,
:text
=>
textile
(
body
))
f
.
write
result
warn_about_broken_links
(
result
)
end
end
end
...
...
@@ -135,38 +134,5 @@ def with_workaround_for_notextile(body)
code_blocks
[
$1
.
to_i
]
end
end
def
warn_about_broken_links
(
html
)
anchors
=
extract_anchors
(
html
)
check_fragment_identifiers
(
html
,
anchors
)
end
def
extract_anchors
(
html
)
# Textile generates headers with IDs computed from titles.
anchors
=
Set
.
new
html
.
scan
(
/<h\d\s+id="([^"]+)/
).
flatten
.
each
do
|
anchor
|
if
anchors
.
member?
(
anchor
)
puts
"*** DUPLICATE HEADER ID:
#{
anchor
}
, please consider rewording"
else
anchors
<<
anchor
end
end
# Also, footnotes are rendered as paragraphs this way.
anchors
+=
Set
.
new
(
html
.
scan
(
/<p\s+class="footnote"\s+id="([^"]+)/
).
flatten
)
return
anchors
end
def
check_fragment_identifiers
(
html
,
anchors
)
html
.
scan
(
/<a\s+href="#([^"]+)/
).
flatten
.
each
do
|
fragment_identifier
|
next
if
fragment_identifier
==
'mainCol'
# in layout, jumps to some DIV
unless
anchors
.
member?
(
fragment_identifier
)
guess
=
anchors
.
min
{
|
a
,
b
|
Levenshtein
.
distance
(
fragment_identifier
,
a
)
<=>
Levenshtein
.
distance
(
fragment_identifier
,
b
)
}
puts
"*** BROKEN LINK: #
#{
fragment_identifier
}
, perhaps you meant #
#{
guess
}
."
end
end
end
end
end
railties/guides/rails_guides/levenshtein.rb
已删除
100644 → 0
浏览文件 @
18eb80cc
#
# Levenshtein distance algorithm implementation for Ruby, with UTF-8 support
#
# Author:: Paul BATTLEY (pbattley @ gmail.com)
# Version:: 1.3
# Date:: 2005-04-19
#
# == About
#
# The Levenshtein distance is a measure of how similar two strings s and t are,
# calculated as the number of deletions/insertions/substitutions needed to
# transform s into t. The greater the distance, the more the strings differ.
#
# The Levenshtein distance is also sometimes referred to as the
# easier-to-pronounce-and-spell 'edit distance'.
#
# == Revision history
#
# * 2005-05-19 1.3 Repairing an oversight, distance can now be called via
# Levenshtein.distance(s, t)
# * 2005-05-04 1.2 Now uses just one 1-dimensional array. I think this is as
# far as optimisation can go.
# * 2005-05-04 1.1 Now storing only the current and previous rows of the matrix
# instead of the whole lot.
#
# == Licence
#
# Copyright (c) 2005 Paul Battley
#
# Usage of the works is permitted provided that this instrument is retained
# with the works, so that any entity that uses the works is notified of this
# instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
#
module
Levenshtein
#
# Calculate the Levenshtein distance between two strings +str1+ and +str2+.
# +str1+ and +str2+ should be ASCII or UTF-8.
#
def
distance
(
str1
,
str2
)
s
=
str1
.
unpack
(
'U*'
)
t
=
str2
.
unpack
(
'U*'
)
n
=
s
.
length
m
=
t
.
length
return
m
if
(
0
==
n
)
return
n
if
(
0
==
m
)
d
=
(
0
..
m
).
to_a
x
=
nil
(
0
...
n
).
each
do
|
i
|
e
=
i
+
1
(
0
...
m
).
each
do
|
j
|
cost
=
(
s
[
i
]
==
t
[
j
])
?
0
:
1
x
=
[
d
[
j
+
1
]
+
1
,
# insertion
e
+
1
,
# deletion
d
[
j
]
+
cost
# substitution
].
min
d
[
j
]
=
e
e
=
x
end
d
[
m
]
=
x
end
return
x
end
extend
self
end
if
(
__FILE__
==
$0
)
require
'test/unit'
class
LevenshteinTest
<
Test
::
Unit
::
TestCase
include
Levenshtein
EXPECTED
=
[
# Easy ones
[
'test'
,
'test'
,
0
],
[
'test'
,
'tent'
,
1
],
[
'gumbo'
,
'gambol'
,
2
],
[
'kitten'
,
'sitting'
,
3
],
# Empty strings
[
'foo'
,
''
,
3
],
[
''
,
''
,
0
],
[
'a'
,
''
,
1
],
# UTF-8
[
"f
\303\266
o"
,
'foo'
,
1
],
[
"fran
\303\247
ais"
,
'francais'
,
1
],
[
"fran
\303\247
ais"
,
"fran
\303\246
ais"
,
1
],
[
"
\347\247\201\343\201\256\345\220\215\345\211\215\343\201\257
"
<<
"
\343\203\235\343\203\274\343\203\253\343\201\247\343\201\231
"
,
"
\343\201\274\343\201\217\343\201\256\345\220\215\345\211\215\343\201
"
<<
"
\257\343\203\235\343\203\274\343\203\253\343\201\247\343\201\231
"
,
2
],
# Japanese
# Edge cases
[
'a'
,
'a'
,
0
],
[
'0123456789'
,
'abcdefghijklmnopqrstuvwxyz'
,
26
]
]
def
test_known_distances
EXPECTED
.
each
do
|
a
,
b
,
x
|
assert_equal
(
x
,
distance
(
a
,
b
))
assert_equal
(
x
,
distance
(
b
,
a
))
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录