@@ -87,15 +87,24 @@ def quote(value)
87
87
def get_schema_info ( klass , header , options = { } )
88
88
info = "# #{ header } \n "
89
89
info << "#\n "
90
- info << "# Table name: #{ klass . table_name } \n "
90
+ if ( options [ :format_markdown ] )
91
+ info << "# Table name: `#{ klass . table_name } `\n "
92
+ info << "#\n "
93
+ info << "# ### Columns\n "
94
+ else
95
+ info << "# Table name: #{ klass . table_name } \n "
96
+ end
91
97
info << "#\n "
92
98
93
99
max_size = klass . column_names . map { |name | name . size } . max || 0
94
100
max_size += options [ :format_rdoc ] ? 5 : 1
101
+ md_names_overhead = 6
102
+ md_type_allowance = 18
103
+ bare_type_allowance = 16
95
104
96
105
if ( options [ :format_markdown ] )
97
- info << sprintf ( "# %-#{ max_size + 4 } .#{ max_size + 4 } s | %-18.18s | %s\n " , 'Field ' , 'Type' , 'Attributes' )
98
- info << "# #{ '-' * ( max_size + 4 ) } | #{ '-' * 18 } | #{ '-' * 25 } \n "
106
+ info << sprintf ( "# %-#{ max_size + md_names_overhead } .#{ max_size + md_names_overhead } s | %-#{ md_type_allowance } . #{ md_type_allowance } s | %s\n " , 'Name ' , 'Type' , 'Attributes' )
107
+ info << "# #{ '-' * ( max_size + md_names_overhead ) } | #{ '-' * md_type_allowance } | #{ '-' * 27 } \n "
99
108
end
100
109
101
110
cols = klass . columns
@@ -136,14 +145,16 @@ def get_schema_info(klass, header, options = {})
136
145
if options [ :format_rdoc ]
137
146
info << sprintf ( "# %-#{ max_size } .#{ max_size } s<tt>%s</tt>" , "*#{ col . name } *::" , attrs . unshift ( col_type ) . join ( ", " ) ) . rstrip + "\n "
138
147
elsif options [ :format_markdown ]
139
- info << sprintf ( "# **%-#{ max_size } .#{ max_size } s** | `%-16.16s` | `%s`" , col . name , col_type , attrs . join ( ", " ) . rstrip ) + "\n "
148
+ name_remainder = max_size - col . name . length
149
+ type_remainder = ( md_type_allowance - 2 ) - col_type . length
150
+ info << ( sprintf ( "# **`%s`**%#{ name_remainder } s | `%s`%#{ type_remainder } s | `%s`" , col . name , " " , col_type , " " , attrs . join ( ", " ) . rstrip ) ) . gsub ( '``' , ' ' ) . rstrip + "\n "
140
151
else
141
- info << sprintf ( "# %-#{ max_size } .#{ max_size } s:%-16.16s %s" , col . name , col_type , attrs . join ( ", " ) ) . rstrip + "\n "
152
+ info << sprintf ( "# %-#{ max_size } .#{ max_size } s:%-#{ bare_type_allowance } . #{ bare_type_allowance } s %s" , col . name , col_type , attrs . join ( ", " ) ) . rstrip + "\n "
142
153
end
143
154
end
144
155
145
156
if options [ :show_indexes ] && klass . table_exists?
146
- info << get_index_info ( klass )
157
+ info << get_index_info ( klass , options )
147
158
end
148
159
149
160
if options [ :format_rdoc ]
@@ -155,15 +166,23 @@ def get_schema_info(klass, header, options = {})
155
166
end
156
167
end
157
168
158
- def get_index_info ( klass )
159
- index_info = "#\n # Indexes\n #\n "
169
+ def get_index_info ( klass , options = { } )
170
+ if ( options [ :format_markdown ] )
171
+ index_info = "#\n # ### Indexes\n #\n "
172
+ else
173
+ index_info = "#\n # Indexes\n #\n "
174
+ end
160
175
161
176
indexes = klass . connection . indexes ( klass . table_name )
162
177
return "" if indexes . empty?
163
178
164
179
max_size = indexes . collect { |index | index . name . size } . max + 1
165
180
indexes . sort_by { |index | index . name } . each do |index |
166
- index_info << sprintf ( "# %-#{ max_size } .#{ max_size } s %s %s" , index . name , "(#{ index . columns . join ( "," ) } )" , index . unique ? "UNIQUE" : "" ) . rstrip + "\n "
181
+ if ( options [ :format_markdown ] )
182
+ index_info << sprintf ( "# * `%s`%s:\n # * **`%s`**\n " , index . name , index . unique ? " (_unique_)" : "" , index . columns . join ( "`**\n # * **`" ) )
183
+ else
184
+ index_info << sprintf ( "# %-#{ max_size } .#{ max_size } s %s %s" , index . name , "(#{ index . columns . join ( "," ) } )" , index . unique ? "UNIQUE" : "" ) . rstrip + "\n "
185
+ end
167
186
end
168
187
return index_info
169
188
end
0 commit comments