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
c40faf4a
Commit
c40faf4a
authored
Jan 13, 2015
by
Cuong Tran
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #225 from kamilbielawski/comments_wrapping
Add pre/post wrapper for annotation block
parents
cb331bbe
a84af5e8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
2 deletions
+29
-2
README.rdoc
README.rdoc
+4
-0
annotate
bin/annotate
+13
-0
annotate_models.rb
lib/annotate/annotate_models.rb
+5
-2
annotate_models.rake
lib/tasks/annotate_models.rake
+2
-0
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+5
-0
No files found.
README.rdoc
View file @
c40faf4a
...
@@ -167,6 +167,10 @@ you can do so with a simple environment variable, instead of editing the
...
@@ -167,6 +167,10 @@ you can do so with a simple environment variable, instead of editing the
Place the annotations at the top (before) or the bottom (after) of the routes.rb file
Place the annotations at the top (before) or the bottom (after) of the routes.rb file
--ps, --position-in-serializer [before|top|after|bottom]
--ps, --position-in-serializer [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of the serializer files
Place the annotations at the top (before) or the bottom (after) of the serializer files
--w, --wrapper STR Wrap annotation with the text passed as parameter.
If --w option is used, the same text will be used as opening and closing
--wo, --wrapper-open STR Annotation wrapper opening.
--wc, --wrapper-close STR Annotation wrapper closing
-r, --routes Annotate routes.rb with the output of 'rake routes'
-r, --routes Annotate routes.rb with the output of 'rake routes'
-v, --version Show the current version of this gem
-v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation
-m, --show-migration Include the migration version number in the annotation
...
...
bin/annotate
View file @
c40faf4a
...
@@ -78,6 +78,19 @@ OptionParser.new do |opts|
...
@@ -78,6 +78,19 @@ OptionParser.new do |opts|
has_set_position
[
'position_in_serializer'
]
=
true
has_set_position
[
'position_in_serializer'
]
=
true
end
end
opts
.
on
(
'--w'
,
'--wrapper STR'
,
'Wrap annotation with the text passed as parameter.'
,
'If --w option is used, the same text will be used as opening and closing'
)
do
|
p
|
ENV
[
'wrapper'
]
=
p
end
opts
.
on
(
'--wo'
,
'--wrapper-open STR'
,
'Annotation wrapper opening.'
)
do
|
p
|
ENV
[
'wrapper_open'
]
=
p
end
opts
.
on
(
'--wc'
,
'--wrapper-close STR'
,
'Annotation wrapper closing'
)
do
|
p
|
ENV
[
'wrapper_close'
]
=
p
end
opts
.
on
(
'-r'
,
'--routes'
,
opts
.
on
(
'-r'
,
'--routes'
,
"Annotate routes.rb with the output of 'rake routes'"
)
do
"Annotate routes.rb with the output of 'rake routes'"
)
do
target
=
{
target
=
{
...
...
lib/annotate/annotate_models.rb
View file @
c40faf4a
...
@@ -253,6 +253,9 @@ module AnnotateModels
...
@@ -253,6 +253,9 @@ module AnnotateModels
new_content
=
old_content
.
sub
(
PATTERN
,
"
\n
"
+
info_block
)
new_content
=
old_content
.
sub
(
PATTERN
,
"
\n
"
+
info_block
)
end
end
wrapper_open
=
options
[
:wrapper_open
]
?
"#
#{
options
[
:wrapper_open
]
}
\n
"
:
""
wrapper_close
=
options
[
:wrapper_close
]
?
"
\n
#
#{
options
[
:wrapper_close
]
}
"
:
""
wrapped_info_block
=
"
#{
wrapper_open
}#{
info_block
}#{
wrapper_close
}
"
# if there *was* no old schema info (no substitution happened) or :force was passed,
# if there *was* no old schema info (no substitution happened) or :force was passed,
# we simply need to insert it in correct position
# we simply need to insert it in correct position
if
new_content
==
old_content
||
options
[
:force
]
if
new_content
==
old_content
||
options
[
:force
]
...
@@ -260,8 +263,8 @@ module AnnotateModels
...
@@ -260,8 +263,8 @@ module AnnotateModels
old_content
.
sub!
(
PATTERN
,
''
)
old_content
.
sub!
(
PATTERN
,
''
)
new_content
=
%w(after bottom)
.
include?
(
options
[
position
].
to_s
)
?
new_content
=
%w(after bottom)
.
include?
(
options
[
position
].
to_s
)
?
(
encoding_header
+
(
old_content
.
rstrip
+
"
\n\n
"
+
info_block
))
:
(
encoding_header
+
(
old_content
.
rstrip
+
"
\n\n
"
+
wrapped_
info_block
))
:
(
encoding_header
+
info_block
+
"
\n
"
+
old_content
)
(
encoding_header
+
wrapped_
info_block
+
"
\n
"
+
old_content
)
end
end
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
new_content
}
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
new_content
}
...
...
lib/tasks/annotate_models.rake
View file @
c40faf4a
...
@@ -31,6 +31,8 @@ task :annotate_models => :environment do
...
@@ -31,6 +31,8 @@ task :annotate_models => :environment do
options
[
:sort
]
=
Annotate
.
true?
(
ENV
[
'sort'
])
options
[
:sort
]
=
Annotate
.
true?
(
ENV
[
'sort'
])
options
[
:force
]
=
Annotate
.
true?
(
ENV
[
'force'
])
options
[
:force
]
=
Annotate
.
true?
(
ENV
[
'force'
])
options
[
:trace
]
=
Annotate
.
true?
(
ENV
[
'trace'
])
options
[
:trace
]
=
Annotate
.
true?
(
ENV
[
'trace'
])
options
[
:wrapper_open
]
=
Annotate
.
fallback
(
ENV
[
'wrapper_open'
],
ENV
[
'wrapper'
])
options
[
:wrapper_close
]
=
Annotate
.
fallback
(
ENV
[
'wrapper_close'
],
ENV
[
'wrapper'
])
AnnotateModels
.
do_annotations
(
options
)
AnnotateModels
.
do_annotations
(
options
)
end
end
...
...
spec/annotate/annotate_models_spec.rb
View file @
c40faf4a
...
@@ -455,6 +455,11 @@ end
...
@@ -455,6 +455,11 @@ end
expect
(
File
.
read
(
@model_file_name
)).
to
eq
(
"
#{
@file_content
}
\n
#{
@schema_info
}
"
)
expect
(
File
.
read
(
@model_file_name
)).
to
eq
(
"
#{
@file_content
}
\n
#{
@schema_info
}
"
)
end
end
it
'should wrap annotation if wrapper is specified'
do
annotate_one_file
:wrapper_open
=>
'START'
,
:wrapper_close
=>
'END'
expect
(
File
.
read
(
@model_file_name
)).
to
eq
(
"# START
\n
#{
@schema_info
}
\n
# END
\n
#{
@file_content
}
"
)
end
describe
"with existing annotation => :before"
do
describe
"with existing annotation => :before"
do
before
do
before
do
annotate_one_file
:position
=>
:before
annotate_one_file
:position
=>
:before
...
...
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