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
d108ba8b
Commit
d108ba8b
authored
Dec 17, 2016
by
Guillermo Guerrero Ibarra
Committed by
Cuong Tran
Dec 17, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Routes markdown (#429)
* --active-admin replaced as a flag. closes #363. * Implemented routes in markdown, closes #178
parent
983d36f6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
32 deletions
+138
-32
.rubocop_todo.yml
.rubocop_todo.yml
+17
-19
annotate
bin/annotate
+3
-4
annotate_routes.rb
lib/annotate/annotate_routes.rb
+36
-9
potato.md
potato.md
+41
-0
annotate_routes_spec.rb
spec/annotate/annotate_routes_spec.rb
+41
-0
No files found.
.rubocop_todo.yml
View file @
d108ba8b
# This configuration was generated by
# This configuration was generated by
# `rubocop --auto-gen-config`
# `rubocop --auto-gen-config`
# on 2016-12-1
6 13:08:29
+0100 using RuboCop version 0.46.0.
# on 2016-12-1
7 10:16:05
+0100 using RuboCop version 0.46.0.
# The point is for the user to remove these configuration records
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# Note that changes in the inspected code, or installation of new
...
@@ -101,14 +101,14 @@ Lint/UselessAccessModifier:
...
@@ -101,14 +101,14 @@ Lint/UselessAccessModifier:
Exclude
:
Exclude
:
-
'
lib/annotate/annotate_routes.rb'
-
'
lib/annotate/annotate_routes.rb'
# Offense count: 1
6
# Offense count: 1
7
Metrics/AbcSize
:
Metrics/AbcSize
:
Max
:
144
Max
:
144
# Offense count: 3
# Offense count: 3
# Configuration parameters: CountComments.
# Configuration parameters: CountComments.
Metrics/BlockLength
:
Metrics/BlockLength
:
Max
:
13
5
Max
:
13
4
# Offense count: 2
# Offense count: 2
Metrics/BlockNesting
:
Metrics/BlockNesting
:
...
@@ -118,17 +118,22 @@ Metrics/BlockNesting:
...
@@ -118,17 +118,22 @@ Metrics/BlockNesting:
Metrics/CyclomaticComplexity
:
Metrics/CyclomaticComplexity
:
Max
:
36
Max
:
36
# Offense count: 3
39
# Offense count: 3
50
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
# URISchemes: http, https
Metrics/LineLength
:
Metrics/LineLength
:
Max
:
543
Max
:
543
# Offense count: 2
3
# Offense count: 2
4
# Configuration parameters: CountComments.
# Configuration parameters: CountComments.
Metrics/MethodLength
:
Metrics/MethodLength
:
Max
:
70
Max
:
70
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength
:
Max
:
116
# Offense count: 7
# Offense count: 7
Metrics/PerceivedComplexity
:
Metrics/PerceivedComplexity
:
Max
:
41
Max
:
41
...
@@ -254,12 +259,13 @@ Style/ExtraSpacing:
...
@@ -254,12 +259,13 @@ Style/ExtraSpacing:
-
'
spec/integration/rails_4.2.0/Gemfile'
-
'
spec/integration/rails_4.2.0/Gemfile'
-
'
spec/integration/rails_4.2.0/config.ru'
-
'
spec/integration/rails_4.2.0/config.ru'
# Offense count:
8
# Offense count:
9
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
# SupportedStyles: format, sprintf, percent
Style/FormatString
:
Style/FormatString
:
Exclude
:
Exclude
:
-
'
lib/annotate/annotate_models.rb'
-
'
lib/annotate/annotate_models.rb'
-
'
lib/annotate/annotate_routes.rb'
# Offense count: 181
# Offense count: 181
# Cop supports --auto-correct.
# Cop supports --auto-correct.
...
@@ -284,14 +290,6 @@ Style/GuardClause:
...
@@ -284,14 +290,6 @@ Style/GuardClause:
Style/HashSyntax
:
Style/HashSyntax
:
Enabled
:
false
Enabled
:
false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray
:
Exclude
:
-
'
lib/annotate/annotate_routes.rb'
# Offense count: 6
# Offense count: 6
# Cop supports --auto-correct.
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth.
# Configuration parameters: SupportedStyles, IndentationWidth.
...
@@ -437,7 +435,7 @@ Style/Semicolon:
...
@@ -437,7 +435,7 @@ Style/Semicolon:
-
'
bin/annotate'
-
'
bin/annotate'
-
'
spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb'
-
'
spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb'
# Offense count:
4
# Offense count:
3
# Cop supports --auto-correct.
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
# SupportedStyles: space, no_space
...
@@ -519,7 +517,7 @@ Style/SpaceInsideStringInterpolation:
...
@@ -519,7 +517,7 @@ Style/SpaceInsideStringInterpolation:
Exclude
:
Exclude
:
-
'
lib/annotate/annotate_models.rb'
-
'
lib/annotate/annotate_models.rb'
# Offense count: 22
2
# Offense count: 22
3
# Cop supports --auto-correct.
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
# SupportedStyles: single_quotes, double_quotes
...
@@ -570,18 +568,18 @@ Style/TrailingCommaInLiteral:
...
@@ -570,18 +568,18 @@ Style/TrailingCommaInLiteral:
-
'
spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake'
-
'
spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake'
-
'
spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake'
-
'
spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake'
# Offense count:
1
# Offense count:
2
# Cop supports --auto-correct.
# Cop supports --auto-correct.
Style/TrailingWhitespace
:
Style/TrailingWhitespace
:
Exclude
:
Exclude
:
-
'
spec/annotate/annotate_routes_spec.rb'
-
'
spec/integration/rails_2.3_with_bundler/db/schema.rb'
-
'
spec/integration/rails_2.3_with_bundler/db/schema.rb'
# Offense count:
3
# Offense count:
2
# Cop supports --auto-correct.
# Cop supports --auto-correct.
Style/UnneededInterpolation
:
Style/UnneededInterpolation
:
Exclude
:
Exclude
:
-
'
bin/annotate'
-
'
bin/annotate'
-
'
lib/annotate/annotate_routes.rb'
# Offense count: 8
# Offense count: 8
# Cop supports --auto-correct.
# Cop supports --auto-correct.
...
...
bin/annotate
View file @
d108ba8b
...
@@ -90,12 +90,11 @@ OptionParser.new do |opts|
...
@@ -90,12 +90,11 @@ OptionParser.new do |opts|
ENV
[
'routes'
]
=
'true'
ENV
[
'routes'
]
=
'true'
end
end
opts
.
on
(
'-aa'
,
'--active-admin'
,
'Annotate active_admin models'
)
do
|
p
|
opts
.
on
(
'-aa'
,
'--active-admin'
,
'Annotate active_admin models'
)
do
ENV
[
'active_admin'
]
=
p
ENV
[
'active_admin'
]
=
'true'
end
end
opts
.
on
(
'-v'
,
'--version'
,
opts
.
on
(
'-v'
,
'--version'
,
'Show the current version of this gem'
)
do
'Show the current version of this gem'
)
do
puts
"annotate v
#{
Annotate
.
version
}
"
;
exit
puts
"annotate v
#{
Annotate
.
version
}
"
;
exit
end
end
...
...
lib/annotate/annotate_routes.rb
View file @
d108ba8b
...
@@ -18,25 +18,51 @@
...
@@ -18,25 +18,51 @@
# Released under the same license as Ruby. No Support. No Warranty.
# Released under the same license as Ruby. No Support. No Warranty.
#
#
module
AnnotateRoutes
module
AnnotateRoutes
PREFIX
=
'# == Route Map'
PREFIX
=
'== Route Map'
.
freeze
PREFIX_MD
=
'## Route Map'
.
freeze
HEADER_ROW
=
[
'Prefix'
,
'Verb'
,
'URI Pattern'
,
'Controller#Action'
]
def
self
.
do_annotations
(
options
=
{})
class
<<
self
return
unless
routes_exists?
def
content
(
line
,
maxs
,
options
=
{})
return
line
.
rstrip
unless
options
[
:format_markdown
]
line
.
each_with_index
.
map
do
|
elem
,
index
|
min_length
=
maxs
.
map
{
|
arr
|
arr
[
index
]
}.
max
||
0
sprintf
(
"%-
#{
min_length
}
.
#{
min_length
}
s"
,
elem
.
tr
(
'|'
,
'-'
))
end
.
join
(
' | '
)
end
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
+=
[
'#'
]
return
out
if
routes_map
.
size
.
zero?
routes_map
=
AnnotateRoutes
.
app_routes_map
(
options
)
maxs
=
[
HEADER_ROW
.
map
(
&
:size
)]
+
routes_map
[
1
..-
1
].
map
{
|
line
|
line
.
split
.
map
(
&
:size
)
}
max
=
maxs
.
map
(
&
:max
).
max
header
=
[
if
options
[
:format_markdown
]
"
#{
PREFIX
}
"
+
(
options
[
:timestamp
]
?
" (Updated
#{
Time
.
now
.
strftime
(
'%Y-%m-%d %H:%M'
)
}
)"
:
''
),
'#'
out
+=
[
"#
#{
content
(
HEADER_ROW
,
maxs
,
options
)
}
"
]
]
+
routes_map
.
map
{
|
line
|
"#
#{
line
}
"
.
rstrip
}
out
+=
[
"#
#{
content
([
'-'
*
max
,
'-'
*
max
,
'-'
*
max
,
'-'
*
max
],
maxs
,
options
)
}
"
]
else
out
+=
[
"#
#{
content
(
routes_map
[
0
],
maxs
,
options
)
}
"
]
end
out
+
routes_map
[
1
..-
1
].
map
{
|
line
|
"#
#{
content
(
options
[
:format_markdown
]
?
line
.
split
(
' '
)
:
line
,
maxs
,
options
)
}
"
}
end
def
do_annotations
(
options
=
{})
return
unless
routes_exists?
existing_text
=
File
.
read
(
routes_file
)
existing_text
=
File
.
read
(
routes_file
)
if
write_contents
(
existing_text
,
header
,
options
)
if
write_contents
(
existing_text
,
header
(
options
)
,
options
)
puts
"
#{
routes_file
}
annotated."
puts
"
#{
routes_file
}
annotated."
end
end
end
end
def
self
.
remove_annotations
(
options
=
{})
def
remove_annotations
(
options
=
{})
return
unless
routes_exists?
return
unless
routes_exists?
existing_text
=
File
.
read
(
routes_file
)
existing_text
=
File
.
read
(
routes_file
)
content
,
where_header_found
=
strip_annotations
(
existing_text
)
content
,
where_header_found
=
strip_annotations
(
existing_text
)
...
@@ -47,6 +73,7 @@ module AnnotateRoutes
...
@@ -47,6 +73,7 @@ module AnnotateRoutes
puts
"Removed annotations from
#{
routes_file
}
."
puts
"Removed annotations from
#{
routes_file
}
."
end
end
end
end
end
private
private
...
...
potato.md
0 → 100644
View file @
d108ba8b
Colons can be used to align columns.
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
There must be at least 3 dashes separating each header cell.
The outer pipes (|) are optional, and you don't need to make the
raw Markdown line up prettily. You can also use inline Markdown.
Markdown | Less | Pretty
--- | --- | ---
*Still*
|
`renders`
|
**nicely**
1 | 2 | 3
## 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
\n
")
Table name:
`users`
### Columns
Name | Type | Attributes
----------------------- | ------------------ | ---------------------------
**`id`**
|
`integer`
|
`not null, primary key`
**`foreign_thing_id`**
|
`integer`
|
`not null`
### Foreign Keys
*
`fk_rails_...`
(_ON DELETE => on_delete_value ON UPDATE => on_update_value_):
*
**`foreign_thing_id => foreign_things.id`**
spec/annotate/annotate_routes_spec.rb
View file @
d108ba8b
...
@@ -17,6 +17,47 @@ describe AnnotateRoutes do
...
@@ -17,6 +17,47 @@ describe AnnotateRoutes do
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
describe
'Annotate#example'
do
before
(
:each
)
do
expect
(
File
).
to
receive
(
:exists?
).
with
(
ROUTE_FILE
).
and_return
(
true
)
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
""
)
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
).
and_return
(
' 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'
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADDED
)
end
it
'annotate normal'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
@mock_file
).
to
receive
(
:puts
).
with
(
"
# == 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
\n
"
)
AnnotateRoutes
.
do_annotations
end
it
'annotate markdown'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
@mock_file
).
to
receive
(
:puts
).
with
(
"
# ## 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
\n
"
)
AnnotateRoutes
.
do_annotations
(
format_markdown:
true
)
end
end
describe
'When adding'
do
describe
'When adding'
do
before
(
:each
)
do
before
(
:each
)
do
expect
(
File
).
to
receive
(
:exists?
).
with
(
ROUTE_FILE
).
and_return
(
true
)
expect
(
File
).
to
receive
(
:exists?
).
with
(
ROUTE_FILE
).
and_return
(
true
)
...
...
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