diff --git a/lib/annotate/annotate_routes.rb b/lib/annotate/annotate_routes.rb index 31c2f2da3..b15bfc9ca 100644 --- a/lib/annotate/annotate_routes.rb +++ b/lib/annotate/annotate_routes.rb @@ -86,10 +86,10 @@ def header(options = {}) 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) } @@ -97,18 +97,26 @@ def header(options = {}) 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