Commit da0adbdb by Shu Fujita Committed by Andrew W. Lee

Refactor AnnotateRoutes.header (#714)

I refactored `AnnotateRoutes.header` for performance, and add `AnnotateRoutes.comment` to make code DRY.
parent 3e3d6056
......@@ -88,10 +88,10 @@ module AnnotateRoutes
end
out << '' if magic_comments_map.any?
out += ["# #{options[:wrapper_open]}"] if options[:wrapper_open]
out << comment(options[:wrapper_open]) if options[:wrapper_open]
out += ["# #{options[:format_markdown] ? PREFIX_MD : PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : '')]
out += ['#']
out << comment(options[:format_markdown] ? PREFIX_MD : PREFIX) + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : '')
out << comment
return out if routes_map.size.zero?
maxs = [HEADER_ROW.map(&:size)] + routes_map[1..-1].map { |line| line.split.map(&:size) }
......@@ -99,18 +99,26 @@ module AnnotateRoutes
if options[:format_markdown]
max = maxs.map(&:max).compact.max
out += ["# #{content(HEADER_ROW, maxs, options)}"]
out += ["# #{content(['-' * max, '-' * max, '-' * max, '-' * max], maxs, options)}"]
out << comment(content(HEADER_ROW, maxs, options))
out << comment(content(['-' * max, '-' * max, '-' * max, '-' * max], maxs, options))
else
out += ["# #{content(routes_map[0], maxs, options)}"]
out << comment(content(routes_map[0], maxs, options))
end
out += routes_map[1..-1].map { |line| "# #{content(options[:format_markdown] ? line.split(' ') : line, maxs, options)}" }
out += ["# #{options[:wrapper_close]}"] if options[:wrapper_close]
out += routes_map[1..-1].map { |line| comment(content(options[:format_markdown] ? line.split(' ') : line, maxs, options)) }
out << comment(options[:wrapper_close]) if options[:wrapper_close]
out
end
def comment(row = '')
if row == ''
'#'
else
"# #{row}"
end
end
# TODO: write the method doc using ruby rdoc formats
# This method returns an array of 'real_content' and 'header_position'.
# 'header_position' will either be :before, :after, or
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment