Skip to content

Commit 8750ef2

Browse files
committed
Add AnnotateRoutes.comment
1 parent c926044 commit 8750ef2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/annotate/annotate_routes.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,37 @@ def header(options = {})
8686
end
8787
out << '' if magic_comments_map.any?
8888

89-
out << "# #{options[:wrapper_open]}" if options[:wrapper_open]
89+
out << comment(options[:wrapper_open]) if options[:wrapper_open]
9090

91-
out << "# #{options[:format_markdown] ? PREFIX_MD : PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : '')
92-
out << '#'
91+
out << comment(options[:format_markdown] ? PREFIX_MD : PREFIX) + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : '')
92+
out << comment
9393
return out if routes_map.size.zero?
9494

9595
maxs = [HEADER_ROW.map(&:size)] + routes_map[1..-1].map { |line| line.split.map(&:size) }
9696

9797
if options[:format_markdown]
9898
max = maxs.map(&:max).compact.max
9999

100-
out << "# #{content(HEADER_ROW, maxs, options)}"
101-
out << "# #{content(['-' * max, '-' * max, '-' * max, '-' * max], maxs, options)}"
100+
out << comment(content(HEADER_ROW, maxs, options))
101+
out << comment(content(['-' * max, '-' * max, '-' * max, '-' * max], maxs, options))
102102
else
103-
out << "# #{content(routes_map[0], maxs, options)}"
103+
out << comment(content(routes_map[0], maxs, options))
104104
end
105105

106-
out += routes_map[1..-1].map { |line| "# #{content(options[:format_markdown] ? line.split(' ') : line, maxs, options)}" }
107-
out << "# #{options[:wrapper_close]}" if options[:wrapper_close]
106+
out += routes_map[1..-1].map { |line| comment(content(options[:format_markdown] ? line.split(' ') : line, maxs, options)) }
107+
out << comment(options[:wrapper_close]) if options[:wrapper_close]
108108

109109
out
110110
end
111111

112+
def comment(row = '')
113+
if row == ''
114+
'#'
115+
else
116+
"# #{row}"
117+
end
118+
end
119+
112120
# TODO: write the method doc using ruby rdoc formats
113121
# This method returns an array of 'real_content' and 'header_position'.
114122
# 'header_position' will either be :before, :after, or

0 commit comments

Comments
 (0)