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
3faf06f1
Commit
3faf06f1
authored
Aug 18, 2013
by
Cuong Tran
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #116 from Mik-die/optional_ending_lines
Remove excessive newline when annotation is put after code
parents
f5099413
495c71f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
13 deletions
+9
-13
annotate_models.rb
lib/annotate/annotate_models.rb
+5
-5
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+4
-8
No files found.
lib/annotate/annotate_models.rb
View file @
3faf06f1
...
@@ -5,7 +5,7 @@ module AnnotateModels
...
@@ -5,7 +5,7 @@ module AnnotateModels
PREFIX
=
"== Schema Information"
PREFIX
=
"== Schema Information"
PREFIX_MD
=
"## Schema Information"
PREFIX_MD
=
"## Schema Information"
END_MARK
=
"== Schema Information End"
END_MARK
=
"== Schema Information End"
PATTERN
=
/^\n?# (?:
#{
COMPAT_PREFIX
}
|
#{
COMPAT_PREFIX_MD
}
).*?\n(#.*\n)*\n/
PATTERN
=
/^\n?# (?:
#{
COMPAT_PREFIX
}
|
#{
COMPAT_PREFIX_MD
}
).*?\n(#.*\n)*\n
*
/
# File.join for windows reverse bar compat?
# File.join for windows reverse bar compat?
# I dont use windows, can`t test
# I dont use windows, can`t test
...
@@ -164,9 +164,9 @@ module AnnotateModels
...
@@ -164,9 +164,9 @@ module AnnotateModels
if
options
[
:format_rdoc
]
if
options
[
:format_rdoc
]
info
<<
"#--
\n
"
info
<<
"#--
\n
"
info
<<
"#
#{
END_MARK
}
\n
"
info
<<
"#
#{
END_MARK
}
\n
"
info
<<
"#++
\n
\n
"
info
<<
"#++
\n
"
else
else
info
<<
"#
\n
\n
"
info
<<
"#
\n
"
end
end
end
end
...
@@ -208,7 +208,7 @@ module AnnotateModels
...
@@ -208,7 +208,7 @@ module AnnotateModels
return
false
if
(
old_content
=~
/# -\*- SkipSchemaAnnotations.*\n/
)
return
false
if
(
old_content
=~
/# -\*- SkipSchemaAnnotations.*\n/
)
# Ignore the Schema version line because it changes with each migration
# Ignore the Schema version line because it changes with each migration
header_pattern
=
/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?
\n
)/
header_pattern
=
/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?)/
old_header
=
old_content
.
match
(
header_pattern
).
to_s
old_header
=
old_content
.
match
(
header_pattern
).
to_s
new_header
=
info_block
.
match
(
header_pattern
).
to_s
new_header
=
info_block
.
match
(
header_pattern
).
to_s
...
@@ -242,7 +242,7 @@ module AnnotateModels
...
@@ -242,7 +242,7 @@ module AnnotateModels
new_content
=
options
[
position
].
to_s
==
'after'
?
new_content
=
options
[
position
].
to_s
==
'after'
?
(
encoding_header
+
(
old_content
.
rstrip
+
"
\n\n
"
+
info_block
))
:
(
encoding_header
+
(
old_content
.
rstrip
+
"
\n\n
"
+
info_block
))
:
(
encoding_header
+
info_block
+
old_content
)
(
encoding_header
+
info_block
+
"
\n
"
+
old_content
)
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
new_content
}
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
new_content
}
return
true
return
true
...
...
spec/annotate/annotate_models_spec.rb
View file @
3faf06f1
...
@@ -51,7 +51,6 @@ describe AnnotateModels do
...
@@ -51,7 +51,6 @@ describe AnnotateModels do
# id :integer not null, primary key
# id :integer not null, primary key
# name :string(50) not null
# name :string(50) not null
#
#
EOS
EOS
end
end
...
@@ -69,7 +68,6 @@ EOS
...
@@ -69,7 +68,6 @@ EOS
# id :integer not null
# id :integer not null
# name :string(50) not null
# name :string(50) not null
#
#
EOS
EOS
end
end
...
@@ -89,7 +87,6 @@ EOS
...
@@ -89,7 +87,6 @@ EOS
# b_id :integer not null
# b_id :integer not null
# name :string(50) not null
# name :string(50) not null
#
#
EOS
EOS
end
end
it
"should get schema info with enum type "
do
it
"should get schema info with enum type "
do
...
@@ -125,7 +122,6 @@ EOS
...
@@ -125,7 +122,6 @@ EOS
#--
#--
#
#{
AnnotateModels
::
END_MARK
}
#
#{
AnnotateModels
::
END_MARK
}
#++
#++
EOS
EOS
end
end
...
@@ -195,7 +191,7 @@ EOS
...
@@ -195,7 +191,7 @@ EOS
EOS
EOS
check_class_name
'foo_with_macro.rb'
,
'FooWithMacro'
check_class_name
'foo_with_macro.rb'
,
'FooWithMacro'
end
end
it
"should not care about known macros"
do
it
"should not care about known macros"
do
create
(
'foo_with_known_macro.rb'
,
<<-
EOS
)
create
(
'foo_with_known_macro.rb'
,
<<-
EOS
)
class FooWithKnownMacro < ActiveRecord::Base
class FooWithKnownMacro < ActiveRecord::Base
...
@@ -365,12 +361,12 @@ end
...
@@ -365,12 +361,12 @@ end
it
"should annotate the file before the model if position == 'before'"
do
it
"should annotate the file before the model if position == 'before'"
do
annotate_one_file
:position
=>
"before"
annotate_one_file
:position
=>
"before"
File
.
read
(
@model_file_name
).
should
==
"
#{
@schema_info
}#{
@file_content
}
"
File
.
read
(
@model_file_name
).
should
==
"
#{
@schema_info
}
\n
#{
@file_content
}
"
end
end
it
"should annotate before if given :position => :before"
do
it
"should annotate before if given :position => :before"
do
annotate_one_file
:position
=>
:before
annotate_one_file
:position
=>
:before
File
.
read
(
@model_file_name
).
should
==
"
#{
@schema_info
}#{
@file_content
}
"
File
.
read
(
@model_file_name
).
should
==
"
#{
@schema_info
}
\n
#{
@file_content
}
"
end
end
it
"should annotate after if given :position => :after"
do
it
"should annotate after if given :position => :after"
do
...
@@ -402,7 +398,7 @@ end
...
@@ -402,7 +398,7 @@ end
])
])
schema_info
=
AnnotateModels
.
get_schema_info
(
klass
,
"== Schema Info"
)
schema_info
=
AnnotateModels
.
get_schema_info
(
klass
,
"== Schema Info"
)
AnnotateModels
.
annotate_one_file
(
model_file_name
,
schema_info
,
:position
=>
:before
)
AnnotateModels
.
annotate_one_file
(
model_file_name
,
schema_info
,
:position
=>
:before
)
File
.
read
(
model_file_name
).
should
==
"
#{
schema_info
}#{
file_content
}
"
File
.
read
(
model_file_name
).
should
==
"
#{
schema_info
}
\n
#{
file_content
}
"
end
end
describe
"if a file can't be annotated"
do
describe
"if a file can't be annotated"
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