Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
annotate
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
annotate
Commits
da0adbdb
Commit
da0adbdb
authored
5 years ago
by
Shu Fujita
Committed by
Andrew W. Lee
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor AnnotateRoutes.header (#714)
I refactored `AnnotateRoutes.header` for performance, and add `AnnotateRoutes.comment` to make code DRY.
parent
3e3d6056
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
annotate_routes.rb
lib/annotate/annotate_routes.rb
+16
-8
No files found.
lib/annotate/annotate_routes.rb
View file @
da0adbdb
...
@@ -88,10 +88,10 @@ module AnnotateRoutes
...
@@ -88,10 +88,10 @@ module AnnotateRoutes
end
end
out
<<
''
if
magic_comments_map
.
any?
out
<<
''
if
magic_comments_map
.
any?
out
+=
[
"#
#{
options
[
:wrapper_open
]
}
"
]
if
options
[
:wrapper_open
]
out
<<
comment
(
options
[
:wrapper_open
])
if
options
[
:wrapper_open
]
out
+=
[
"#
#{
options
[
:format_markdown
]
?
PREFIX_MD
:
PREFIX
}
"
+
(
options
[
:timestamp
]
?
" (Updated
#{
Time
.
now
.
strftime
(
'%Y-%m-%d %H:%M'
)
}
)"
:
''
)]
out
<<
comment
(
options
[
:format_markdown
]
?
PREFIX_MD
:
PREFIX
)
+
(
options
[
:timestamp
]
?
" (Updated
#{
Time
.
now
.
strftime
(
'%Y-%m-%d %H:%M'
)
}
)"
:
''
)
out
+=
[
'#'
]
out
<<
comment
return
out
if
routes_map
.
size
.
zero?
return
out
if
routes_map
.
size
.
zero?
maxs
=
[
HEADER_ROW
.
map
(
&
:size
)]
+
routes_map
[
1
..-
1
].
map
{
|
line
|
line
.
split
.
map
(
&
:size
)
}
maxs
=
[
HEADER_ROW
.
map
(
&
:size
)]
+
routes_map
[
1
..-
1
].
map
{
|
line
|
line
.
split
.
map
(
&
:size
)
}
...
@@ -99,18 +99,26 @@ module AnnotateRoutes
...
@@ -99,18 +99,26 @@ module AnnotateRoutes
if
options
[
:format_markdown
]
if
options
[
:format_markdown
]
max
=
maxs
.
map
(
&
:max
).
compact
.
max
max
=
maxs
.
map
(
&
:max
).
compact
.
max
out
+=
[
"#
#{
content
(
HEADER_ROW
,
maxs
,
options
)
}
"
]
out
<<
comment
(
content
(
HEADER_ROW
,
maxs
,
options
))
out
+=
[
"#
#{
content
([
'-'
*
max
,
'-'
*
max
,
'-'
*
max
,
'-'
*
max
],
maxs
,
options
)
}
"
]
out
<<
comment
(
content
([
'-'
*
max
,
'-'
*
max
,
'-'
*
max
,
'-'
*
max
],
maxs
,
options
))
else
else
out
+=
[
"#
#{
content
(
routes_map
[
0
],
maxs
,
options
)
}
"
]
out
<<
comment
(
content
(
routes_map
[
0
],
maxs
,
options
))
end
end
out
+=
routes_map
[
1
..-
1
].
map
{
|
line
|
"#
#{
content
(
options
[
:format_markdown
]
?
line
.
split
(
' '
)
:
line
,
maxs
,
options
)
}
"
}
out
+=
routes_map
[
1
..-
1
].
map
{
|
line
|
comment
(
content
(
options
[
:format_markdown
]
?
line
.
split
(
' '
)
:
line
,
maxs
,
options
))
}
out
+=
[
"#
#{
options
[
:wrapper_close
]
}
"
]
if
options
[
:wrapper_close
]
out
<<
comment
(
options
[
:wrapper_close
])
if
options
[
:wrapper_close
]
out
out
end
end
def
comment
(
row
=
''
)
if
row
==
''
'#'
else
"#
#{
row
}
"
end
end
# TODO: write the method doc using ruby rdoc formats
# TODO: write the method doc using ruby rdoc formats
# This method returns an array of 'real_content' and 'header_position'.
# This method returns an array of 'real_content' and 'header_position'.
# 'header_position' will either be :before, :after, or
# 'header_position' will either be :before, :after, or
...
...
This diff is collapsed.
Click to expand it.
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