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
e763429e
Commit
e763429e
authored
Jul 26, 2017
by
Alexander Belozerov
Committed by
Cuong Tran
Jul 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix #401] Allow wrappers in routes annotation (#492)
parent
240c6b26
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
2 deletions
+27
-2
annotate_routes.rb
lib/annotate/annotate_routes.rb
+10
-2
annotate_routes.rake
lib/tasks/annotate_routes.rake
+2
-0
annotate_routes_spec.rb
spec/annotate/annotate_routes_spec.rb
+15
-0
No files found.
lib/annotate/annotate_routes.rb
View file @
e763429e
# rubocop:disable Metrics/ModuleLength
# == Annotate Routes
#
# Based on:
...
...
@@ -36,7 +38,10 @@ module AnnotateRoutes
def
header
(
options
=
{})
routes_map
=
app_routes_map
(
options
)
out
=
[
"#
#{
options
[
:format_markdown
]
?
PREFIX_MD
:
PREFIX
}
"
+
(
options
[
:timestamp
]
?
" (Updated
#{
Time
.
now
.
strftime
(
'%Y-%m-%d %H:%M'
)
}
)"
:
''
)]
out
=
[]
out
+=
[
"#
#{
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
+=
[
'#'
]
return
out
if
routes_map
.
size
.
zero?
...
...
@@ -51,7 +56,10 @@ module AnnotateRoutes
out
+=
[
"#
#{
content
(
routes_map
[
0
],
maxs
,
options
)
}
"
]
end
out
+
routes_map
[
1
..-
1
].
map
{
|
line
|
"#
#{
content
(
options
[
:format_markdown
]
?
line
.
split
(
' '
)
:
line
,
maxs
,
options
)
}
"
}
out
+=
routes_map
[
1
..-
1
].
map
{
|
line
|
"#
#{
content
(
options
[
:format_markdown
]
?
line
.
split
(
' '
)
:
line
,
maxs
,
options
)
}
"
}
out
+=
[
"#
#{
options
[
:wrapper_close
]
}
"
]
if
options
[
:wrapper_close
]
out
end
def
do_annotations
(
options
=
{})
...
...
lib/tasks/annotate_routes.rake
View file @
e763429e
...
...
@@ -8,6 +8,8 @@ task :annotate_routes => :environment do
options
[
:position_in_routes
]
=
Annotate
.
fallback
(
ENV
[
'position_in_routes'
],
ENV
[
'position'
])
options
[
:ignore_routes
]
=
Annotate
.
fallback
(
ENV
[
'ignore_routes'
],
nil
)
options
[
:require
]
=
ENV
[
'require'
]
?
ENV
[
'require'
].
split
(
','
)
:
[]
options
[
:wrapper_open
]
=
Annotate
.
fallback
(
ENV
[
'wrapper_open'
],
ENV
[
'wrapper'
])
options
[
:wrapper_close
]
=
Annotate
.
fallback
(
ENV
[
'wrapper_close'
],
ENV
[
'wrapper'
])
AnnotateRoutes
.
do_annotations
(
options
)
end
...
...
spec/annotate/annotate_routes_spec.rb
View file @
e763429e
...
...
@@ -56,6 +56,21 @@ describe AnnotateRoutes do
AnnotateRoutes
.
do_annotations
(
format_markdown:
true
)
end
it
'wraps annotation if wrapper is specified'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
@mock_file
).
to
receive
(
:puts
).
with
(
"
# START
# == Route Map
#
# Prefix Verb URI Pattern Controller#Action
# myaction1 GET /url1(.:format) mycontroller1#action
# myaction2 POST /url2(.:format) mycontroller2#action
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
# END
\n
"
)
AnnotateRoutes
.
do_annotations
(
wrapper_open:
'START'
,
wrapper_close:
'END'
)
end
end
describe
'When adding'
do
...
...
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