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
693abdd2
Commit
693abdd2
authored
Nov 10, 2019
by
hasimoto1009
Committed by
Cuong Tran
Nov 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix shifted when format_markdown option enabled and used non-ascii (#650)
parent
5da92c47
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
.rubocop_todo.yml
.rubocop_todo.yml
+1
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+5
-1
annotate_models_spec.rb
spec/lib/annotate/annotate_models_spec.rb
+22
-0
No files found.
.rubocop_todo.yml
View file @
693abdd2
...
@@ -408,7 +408,7 @@ Lint/ShadowingOuterLocalVariable:
...
@@ -408,7 +408,7 @@ Lint/ShadowingOuterLocalVariable:
# Offense count: 20
# Offense count: 20
Metrics/AbcSize
:
Metrics/AbcSize
:
Max
:
13
8
Max
:
13
9
# Offense count: 28
# Offense count: 28
# Configuration parameters: CountComments, ExcludedMethods.
# Configuration parameters: CountComments, ExcludedMethods.
...
...
lib/annotate/annotate_models.rb
View file @
693abdd2
...
@@ -305,7 +305,7 @@ module AnnotateModels
...
@@ -305,7 +305,7 @@ module AnnotateModels
if
options
[
:format_rdoc
]
if
options
[
:format_rdoc
]
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col_name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col_name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
elsif
options
[
:format_markdown
]
elsif
options
[
:format_markdown
]
name_remainder
=
max_size
-
col_name
.
length
name_remainder
=
max_size
-
col_name
.
length
-
non_ascii_length
(
col_name
)
type_remainder
=
(
md_type_allowance
-
2
)
-
col_type
.
length
type_remainder
=
(
md_type_allowance
-
2
)
-
col_type
.
length
info
<<
(
sprintf
(
"# **`%s`**%
#{
name_remainder
}
s | `%s`%
#{
type_remainder
}
s | `%s`"
,
col_name
,
" "
,
col_type
,
" "
,
attrs
.
join
(
", "
).
rstrip
)).
gsub
(
'``'
,
' '
).
rstrip
+
"
\n
"
info
<<
(
sprintf
(
"# **`%s`**%
#{
name_remainder
}
s | `%s`%
#{
type_remainder
}
s | `%s`"
,
col_name
,
" "
,
col_type
,
" "
,
attrs
.
join
(
", "
).
rstrip
)).
gsub
(
'``'
,
' '
).
rstrip
+
"
\n
"
else
else
...
@@ -932,6 +932,10 @@ module AnnotateModels
...
@@ -932,6 +932,10 @@ module AnnotateModels
string
[
0
..
length
-
1
]
string
[
0
..
length
-
1
]
end
end
end
end
def
non_ascii_length
(
string
)
string
.
to_s
.
chars
.
reject
(
&
:ascii_only?
).
length
end
end
end
class
BadModelFileError
<
LoadError
class
BadModelFileError
<
LoadError
...
...
spec/lib/annotate/annotate_models_spec.rb
View file @
693abdd2
...
@@ -1046,6 +1046,28 @@ EOS
...
@@ -1046,6 +1046,28 @@ EOS
EOS
EOS
end
end
it
'should get schema info as Markdown with multibyte comment'
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
,
comment:
'ID'
),
mock_column
(
:name
,
:string
,
limit:
50
,
comment:
'NAME'
)
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
AnnotateModels
::
PREFIX
,
format_markdown:
true
,
with_comment:
true
)).
to
eql
(
<<-
EOS
.
strip_heredoc
)
#
#{
AnnotateModels
::
PREFIX
}
#
# Table name: `users`
#
# ### Columns
#
# Name | Type | Attributes
# --------------------- | ------------------ | ---------------------------
# **`id(ID)`** | `integer` | `not null, primary key`
# **`name(NAME)`** | `string(50)` | `not null`
#
EOS
end
it
'should get schema info as Markdown'
do
it
'should get schema info as Markdown'
do
klass
=
mock_class
(
:users
,
klass
=
mock_class
(
:users
,
:id
,
:id
,
...
...
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