Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
c9b11322
Commit
c9b11322
authored
Mar 01, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add FilterArray class to Banzai
parent
6aa50165
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
76 additions
and
13 deletions
+76
-13
lib/banzai/filter_array.rb
lib/banzai/filter_array.rb
+27
-0
lib/banzai/pipeline/base_pipeline.rb
lib/banzai/pipeline/base_pipeline.rb
+1
-1
lib/banzai/pipeline/broadcast_message_pipeline.rb
lib/banzai/pipeline/broadcast_message_pipeline.rb
+1
-1
lib/banzai/pipeline/combined_pipeline.rb
lib/banzai/pipeline/combined_pipeline.rb
+1
-1
lib/banzai/pipeline/gfm_pipeline.rb
lib/banzai/pipeline/gfm_pipeline.rb
+1
-1
lib/banzai/pipeline/plain_markdown_pipeline.rb
lib/banzai/pipeline/plain_markdown_pipeline.rb
+1
-1
lib/banzai/pipeline/post_process_pipeline.rb
lib/banzai/pipeline/post_process_pipeline.rb
+1
-1
lib/banzai/pipeline/reference_extraction_pipeline.rb
lib/banzai/pipeline/reference_extraction_pipeline.rb
+1
-1
lib/banzai/pipeline/single_line_pipeline.rb
lib/banzai/pipeline/single_line_pipeline.rb
+1
-1
lib/banzai/pipeline/wiki_pipeline.rb
lib/banzai/pipeline/wiki_pipeline.rb
+2
-5
spec/lib/banzai/filter_array_spec.rb
spec/lib/banzai/filter_array_spec.rb
+39
-0
No files found.
lib/banzai/filter_array.rb
0 → 100644
View file @
c9b11322
module
Banzai
class
FilterArray
<
Array
# Insert a value immediately after another value
#
# If the preceding value does not exist, the new value is added to the end
# of the Array.
def
insert_after
(
after_value
,
value
)
i
=
index
(
after_value
)
||
length
-
1
insert
(
i
+
1
,
value
)
end
# Insert a value immediately before another value
#
# If the succeeding value does not exist, the new value is added to the
# beginning of the Array.
def
insert_before
(
before_value
,
value
)
i
=
index
(
before_value
)
||
-
1
if
i
<
0
unshift
(
value
)
else
insert
(
i
,
value
)
end
end
end
end
lib/banzai/pipeline/base_pipeline.rb
View file @
c9b11322
...
...
@@ -4,7 +4,7 @@ module Banzai
module
Pipeline
class
BasePipeline
def
self
.
filters
[]
FilterArray
[]
end
def
self
.
transform_context
(
context
)
...
...
lib/banzai/pipeline/broadcast_message_pipeline.rb
View file @
c9b11322
...
...
@@ -2,7 +2,7 @@ module Banzai
module
Pipeline
class
BroadcastMessagePipeline
<
DescriptionPipeline
def
self
.
filters
@filters
||=
[
@filters
||=
FilterArray
[
Filter
::
MarkdownFilter
,
Filter
::
SanitizationFilter
,
...
...
lib/banzai/pipeline/combined_pipeline.rb
View file @
c9b11322
...
...
@@ -10,7 +10,7 @@ module Banzai
end
def
self
.
filters
pipelines
.
flat_map
(
&
:filters
)
FilterArray
.
new
(
pipelines
.
flat_map
(
&
:filters
)
)
end
def
self
.
transform_context
(
context
)
...
...
lib/banzai/pipeline/gfm_pipeline.rb
View file @
c9b11322
...
...
@@ -2,7 +2,7 @@ module Banzai
module
Pipeline
class
GfmPipeline
<
BasePipeline
def
self
.
filters
@filters
||=
[
@filters
||=
FilterArray
[
Filter
::
SyntaxHighlightFilter
,
Filter
::
SanitizationFilter
,
...
...
lib/banzai/pipeline/plain_markdown_pipeline.rb
View file @
c9b11322
...
...
@@ -2,7 +2,7 @@ module Banzai
module
Pipeline
class
PlainMarkdownPipeline
<
BasePipeline
def
self
.
filters
[
FilterArray
[
Filter
::
MarkdownFilter
]
end
...
...
lib/banzai/pipeline/post_process_pipeline.rb
View file @
c9b11322
...
...
@@ -2,7 +2,7 @@ module Banzai
module
Pipeline
class
PostProcessPipeline
<
BasePipeline
def
self
.
filters
[
FilterArray
[
Filter
::
RelativeLinkFilter
,
Filter
::
RedactorFilter
]
...
...
lib/banzai/pipeline/reference_extraction_pipeline.rb
View file @
c9b11322
...
...
@@ -2,7 +2,7 @@ module Banzai
module
Pipeline
class
ReferenceExtractionPipeline
<
BasePipeline
def
self
.
filters
[
FilterArray
[
Filter
::
ReferenceGathererFilter
]
end
...
...
lib/banzai/pipeline/single_line_pipeline.rb
View file @
c9b11322
...
...
@@ -2,7 +2,7 @@ module Banzai
module
Pipeline
class
SingleLinePipeline
<
GfmPipeline
def
self
.
filters
@filters
||=
[
@filters
||=
FilterArray
[
Filter
::
SanitizationFilter
,
Filter
::
EmojiFilter
,
...
...
lib/banzai/pipeline/wiki_pipeline.rb
View file @
c9b11322
...
...
@@ -4,11 +4,8 @@ module Banzai
module
Pipeline
class
WikiPipeline
<
FullPipeline
def
self
.
filters
@filters
||=
begin
filters
=
super
toc
=
filters
.
index
(
Filter
::
TableOfContentsFilter
)
filters
.
insert
(
toc
+
1
,
Filter
::
GollumTagsFilter
)
end
@filters
||=
super
.
insert_after
(
Filter
::
TableOfContentsFilter
,
Filter
::
GollumTagsFilter
)
end
end
end
...
...
spec/lib/banzai/filter_array_spec.rb
0 → 100644
View file @
c9b11322
require
'spec_helper'
describe
Banzai
::
FilterArray
do
describe
'#insert_after'
do
it
'inserts an element after a provided element'
do
filters
=
described_class
.
new
(
%w(a b c)
)
filters
.
insert_after
(
'b'
,
'1'
)
expect
(
filters
).
to
eq
%w(a b 1 c)
end
it
'inserts an element at the end when the provided element does not exist'
do
filters
=
described_class
.
new
(
%w(a b c)
)
filters
.
insert_after
(
'd'
,
'1'
)
expect
(
filters
).
to
eq
%w(a b c 1)
end
end
describe
'#insert_before'
do
it
'inserts an element before a provided element'
do
filters
=
described_class
.
new
(
%w(a b c)
)
filters
.
insert_before
(
'b'
,
'1'
)
expect
(
filters
).
to
eq
%w(a 1 b c)
end
it
'inserts an element at the beginning when the provided element does not exist'
do
filters
=
described_class
.
new
(
%w(a b c)
)
filters
.
insert_before
(
'd'
,
'1'
)
expect
(
filters
).
to
eq
%w(1 a b c)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment