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
2293d1e0
Commit
2293d1e0
authored
Mar 18, 2011
by
Paul Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for markdown
parent
6123aa49
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
+34
-8
README.rdoc
README.rdoc
+5
-0
annotate
bin/annotate
+6
-2
annotate_models.rb
lib/annotate/annotate_models.rb
+23
-6
No files found.
README.rdoc
View file @
2293d1e0
== Markdown Fork
Originally forked from https://github.com/openteam/annotated_models.git to add support for generating
annotations compatible with the markdown processor used by YARD.
== Annotate (aka AnnotateModels)
Add a comment summarizing the current schema to the top or bottom of each of your...
...
...
bin/annotate
View file @
2293d1e0
...
...
@@ -61,8 +61,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 @
2293d1e0
module
AnnotateModels
class
<<
self
def
fmt_header
(
string
)
return
string
unless
ENV
[
'format_markdown'
]
string
.
gsub
(
'=='
,
'##'
)
end
end
# Annotate Models plugin use this header
COMPAT_PREFIX
=
"== Schema Info"
PREFIX
=
"== Schema Information"
END_MARK
=
"== Schema Information End"
COMPAT_PREFIX
=
fmt_header
(
"== Schema Info"
)
PREFIX
=
fmt_header
(
"== Schema Information"
)
END_MARK
=
fmt_header
(
"== Schema Information End"
)
PATTERN
=
/^\n?#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
# File.join for windows reverse bar compat?
...
...
@@ -47,6 +55,8 @@ module AnnotateModels
value
.
inspect
end
end
# Use the column information in an ActiveRecord class
# to create a comment block containing a line for
...
...
@@ -55,11 +65,16 @@ module AnnotateModels
def
get_schema_info
(
klass
,
header
,
options
=
{})
info
=
"#
#{
header
}
\n
"
info
<<
"#
\n
"
info
<<
"# Table name:
#{
klass
.
table_name
}
\n
"
info
<<
"# Table name:
#{
klass
.
table_name
}
\n
"
unless
klass
.
table_name
==
klass
.
name
.
tableize
info
<<
"# Human name:
#{
klass
.
model_name
.
human
}
\n
"
unless
klass
.
model_name
.
human
(
:default
=>
""
).
blank?
info
<<
"#
\n
"
max_size
=
klass
.
column_names
.
map
{
|
name
|
name
.
size
}.
max
+
(
ENV
[
'format_rdoc'
]
?
5
:
1
)
if
ENV
[
'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
klass
.
columns
.
each
do
|
col
|
attrs
=
[]
attrs
<<
"'
#{
klass
.
human_attribute_name
(
col
.
name
)
}
'"
unless
klass
.
human_attribute_name
(
col
.
name
,
:default
=>
""
).
blank?
...
...
@@ -96,6 +111,8 @@ module AnnotateModels
if
ENV
[
'format_rdoc'
]
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col
.
name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
elsif
ENV
[
'format_markdown'
]
info
<<
sprintf
(
"# **%-
#{
max_size
}
.
#{
max_size
}
s** | `%-15.15s` | `%s `"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
else
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-15.15s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
end
...
...
@@ -110,7 +127,7 @@ module AnnotateModels
info
<<
"#
#{
END_MARK
}
\n
"
info
<<
"#++
\n\n
"
else
info
<<
"#
\n
\n
"
info
<<
"#
\n
"
end
end
...
...
@@ -150,7 +167,7 @@ module AnnotateModels
old_header
=
old_content
.
match
(
header
).
to_s
new_header
=
info_block
.
match
(
header
).
to_s
if
old_header
==
new_header
if
old_header
==
new_header
and
not
ENV
[
'force'
]
false
else
# Remove old schema info
...
...
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