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
56e6930e
Commit
56e6930e
authored
Mar 01, 2012
by
Jon Frisby
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'appsinyourpants/restart' into development
Conflicts: lib/annotate/annotate_models.rb
parents
bb88aa6c
2293d1e0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
9 deletions
+30
-9
History.txt
History.txt
+3
-1
annotate_models
bin/annotate_models
+6
-2
annotate_models.rb
lib/annotate/annotate_models.rb
+17
-6
auto_annotate_models.rake
...ators/annotate_models/templates/auto_annotate_models.rake
+2
-0
annotate_models.rake
lib/tasks/annotate_models.rake
+2
-0
No files found.
History.txt
View file @
56e6930e
...
...
@@ -28,7 +28,9 @@
* Accept String or Symbol for :position (et al) options.
* Rename "annotate" bin to "annotate_models" to avoid conflicting with
ImageMagick.
* Add rdoc output formatting as an option.
* Add RDoc output formatting as an option.
* Add Markdown output formatting as an option.
* Add option to force annotation regeneration.
* Add new configuration option for controlling where info is placed in
fixtures/factories.
* Fix for models without tables.
...
...
bin/annotate_models
View file @
56e6930e
...
...
@@ -73,8 +73,12 @@ OptionParser.new do |opts|
exclusions
.
each
{
|
exclusion
|
ENV
[
"exclude_
#{
exclusion
}
"
]
=
"yes"
}
end
opts
.
on
(
'-f'
,
'--format [bare|rdoc]'
,
[
'bare'
,
'rdoc'
],
'rdoc: render Schema Infomation as RDoc'
)
do
|
fmt
|
ENV
[
'format_#{fmt}'
]
=
'yes'
opts
.
on
(
'-f'
,
'--format [bare|rdoc|markdown]'
,
[
'bare'
,
'rdoc'
,
'markdown'
],
'rdoc: render Schema Infomation as RDoc'
)
do
|
fmt
|
ENV
[
"format_
#{
fmt
}
"
]
=
'yes'
end
opts
.
on
(
'--force'
,
'Force new annotations even if there are no changes.'
)
do
|
force
|
ENV
[
'force'
]
=
'yes'
end
end
.
parse!
...
...
lib/annotate/annotate_models.rb
View file @
56e6930e
module
AnnotateModels
# Annotate Models plugin use this header
COMPAT_PREFIX
=
"== Schema Info"
PREFIX
=
"== Schema Information"
END_MARK
=
"== Schema Information End"
PATTERN
=
/\n?#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n*/
COMPAT_PREFIX
=
"== Schema Info"
COMPAT_PREFIX_MD
=
"## Schema Info"
PREFIX
=
"== Schema Information"
PREFIX_MD
=
"## Schema Information"
END_MARK
=
"== Schema Information End"
PATTERN
=
/^\n?# (?:
#{
COMPAT_PREFIX
}
|
#{
COMPAT_PREFIX_MD
}
).*?\n(#.*\n)*\n/
# File.join for windows reverse bar compat?
# I dont use windows, can`t test
UNIT_TEST_DIR
=
File
.
join
(
"test"
,
"unit"
)
...
...
@@ -62,6 +65,12 @@ module AnnotateModels
max_size
=
klass
.
column_names
.
map
{
|
name
|
name
.
size
}.
max
||
0
max_size
+=
options
[
:format_rdoc
]
?
5
:
1
if
(
options
[
:format_markdown
])
info
<<
sprintf
(
"# %-
#{
max_size
+
4
}
.
#{
max_size
+
4
}
s | %-17.17s | %s
\n
"
,
'Field'
,
'Type'
,
'Attributes'
)
info
<<
"#
#{
'-'
*
(
max_size
+
4
)
}
|
#{
'-'
*
17
}
|
#{
'-'
*
25
}
\n
"
end
cols
=
klass
.
columns
cols
=
cols
.
sort_by
(
&
:name
)
unless
(
options
[
:no_sort
])
cols
.
each
do
|
col
|
...
...
@@ -99,6 +108,8 @@ module AnnotateModels
if
options
[
:format_rdoc
]
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col
.
name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
elsif
options
[
:format_markdown
]
info
<<
sprintf
(
"# **%-
#{
max_size
}
.
#{
max_size
}
s** | `%-16.16s` | `%s `"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
else
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-16.16s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
end
...
...
@@ -162,7 +173,7 @@ module AnnotateModels
encoding
=
Regexp
.
new
(
/(^#\s*encoding:.*\n)|(^# coding:.*\n)|(^# -\*- coding:.*\n)/
)
encoding_header
=
old_content
.
match
(
encoding
).
to_s
if
old_columns
==
new_columns
if
old_columns
==
new_columns
&&
!
options
[
:force
]
false
else
# Strip the old schema info, and insert new schema info.
...
...
@@ -304,7 +315,7 @@ module AnnotateModels
end
end
header
=
PREFIX
.
dup
header
=
options
[
:format_markdown
]
?
PREFIX_MD
.
dup
:
PREFIX
.
dup
if
options
[
:include_version
]
version
=
ActiveRecord
::
Migrator
.
current_version
rescue
0
...
...
lib/generators/annotate_models/templates/auto_annotate_models.rake
View file @
56e6930e
...
...
@@ -14,5 +14,7 @@ if(Rails.env.development?)
ENV
[
'ignore_model_sub_dir'
]
=
"false"
ENV
[
'skip_on_db_migrate'
]
=
"false"
ENV
[
'format_rdoc'
]
=
"false"
ENV
[
'format_markdown'
]
=
"false"
ENV
[
'no_sort'
]
=
"false"
ENV
[
'force'
]
=
"false"
end
lib/tasks/annotate_models.rake
View file @
56e6930e
...
...
@@ -18,7 +18,9 @@ task :annotate_models => :environment do
options
[
:exclude_fixtures
]
=
ENV
[
'exclude_fixtures'
]
=~
true_re
options
[
:ignore_model_sub_dir
]
=
ENV
[
'ignore_model_sub_dir'
]
=~
true_re
options
[
:format_rdoc
]
=
ENV
[
'format_rdoc'
]
=~
true_re
options
[
:format_markdown
]
=
ENV
[
'format_markdown'
]
=~
true_re
options
[
:no_sort
]
=
ENV
[
'no_sort'
]
=~
true_re
options
[
:force
]
=
ENV
[
'force'
]
=~
true_re
AnnotateModels
.
do_annotations
(
options
)
end
...
...
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