Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
765a2c73
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
765a2c73
编写于
1月 12, 2016
作者:
D
Douglas Barbosa Alexandre
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactoring Banzai::Filter::GollumTagsFilter
上级
89e8b82b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
23 deletion
+28
-23
lib/banzai/filter/gollum_tags_filter.rb
lib/banzai/filter/gollum_tags_filter.rb
+28
-19
spec/lib/banzai/filter/gollum_tags_filter_spec.rb
spec/lib/banzai/filter/gollum_tags_filter_spec.rb
+0
-4
未找到文件。
lib/banzai/filter/gollum_tags_filter.rb
浏览文件 @
765a2c73
...
...
@@ -14,7 +14,10 @@ module Banzai
include
ActionView
::
Helpers
::
TagHelper
# Pattern to match tag contents.
TAGS_PATTERN
=
%r{(.?)
\[\[
(.+?)
\]\]
([^
\[
]?)}
TAGS_PATTERN
=
%r{
\[\[
(.+?)
\]\]
}
# Pattern to match allowed image extensions
ALLOWED_IMAGE_EXTENSIONS
=
%r{.+(jpg|png|gif|svg|bmp)
\z
}i
def
call
search_text_nodes
(
doc
).
each
do
|
node
|
...
...
@@ -22,9 +25,11 @@ module Banzai
next
unless
content
.
match
(
TAGS_PATTERN
)
html
=
process_tag
(
$
2
)
html
=
process_tag
(
$
1
)
node
.
replace
(
html
)
if
html
!=
node
.
content
if
html
&&
html
!=
node
.
content
node
.
replace
(
html
)
end
end
doc
...
...
@@ -38,11 +43,11 @@ module Banzai
#
# Returns the String HTML version of the tag.
def
process_tag
(
tag
)
if
html
=
process_image_tag
(
tag
)
html
else
process_page_link_tag
(
tag
)
end
parts
=
tag
.
split
(
'|'
)
return
if
parts
.
size
.
zero?
process_image_tag
(
parts
)
||
process_page_link_tag
(
parts
)
end
# Attempt to process the tag as an image tag.
...
...
@@ -51,16 +56,15 @@ module Banzai
#
# Returns the String HTML if the tag is a valid image tag or nil
# if it is not.
def
process_image_tag
(
tag
)
parts
=
tag
.
split
(
'|'
)
return
if
parts
.
size
.
zero?
def
process_image_tag
(
parts
)
content
=
parts
[
0
].
strip
name
=
parts
[
0
].
strip
return
unless
image?
(
content
)
if
file
=
project_wiki
.
find_file
(
name
)
if
url?
(
content
)
path
=
content
elsif
file
=
project_wiki
.
find_file
(
content
)
path
=
::
File
.
join
project_wiki_base_path
,
file
.
path
elsif
name
=~
/^https?:\/\/.+(jpg|png|gif|svg|bmp)$/i
path
=
name
end
if
path
...
...
@@ -68,16 +72,21 @@ module Banzai
end
end
def
image?
(
path
)
path
=~
ALLOWED_IMAGE_EXTENSIONS
end
def
url?
(
path
)
path
.
start_with?
(
*
%w(http https)
)
end
# Attempt to process the tag as a page link tag.
#
# tag - The String tag contents (the stuff inside the double brackets).
#
# Returns the String HTML if the tag is a valid page link tag or nil
# if it is not.
def
process_page_link_tag
(
tag
)
parts
=
tag
.
split
(
'|'
)
return
if
parts
.
size
.
zero?
def
process_page_link_tag
(
parts
)
if
parts
.
size
==
1
url
=
parts
[
0
].
strip
else
...
...
spec/lib/banzai/filter/gollum_tags_filter_spec.rb
浏览文件 @
765a2c73
...
...
@@ -37,8 +37,6 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do
context
'linking external images'
do
it
'creates img tag for valid URL'
do
expect
(
project_wiki
).
to
receive
(
:find_file
).
with
(
'http://example.com/image.jpg'
).
and_return
(
nil
)
tag
=
'[[http://example.com/image.jpg]]'
doc
=
filter
(
"See
#{
tag
}
"
,
project_wiki:
project_wiki
)
...
...
@@ -46,8 +44,6 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do
end
it
'does not creates img tag for invalid URL'
do
expect
(
project_wiki
).
to
receive
(
:find_file
).
with
(
'http://example.com/image.pdf'
).
and_return
(
nil
)
tag
=
'[[http://example.com/image.pdf]]'
doc
=
filter
(
"See
#{
tag
}
"
,
project_wiki:
project_wiki
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录