Class: AnnotateRb::RouteAnnotator::HeaderGenerator
- Inherits:
-
Object
- Object
- AnnotateRb::RouteAnnotator::HeaderGenerator
- Defined in:
- lib/annotate_rb/route_annotator/header_generator.rb
Constant Summary collapse
- PREFIX =
"== Route Map".freeze
- PREFIX_MD =
"## Route Map".freeze
- HEADER_ROW =
["Prefix", "Verb", "URI Pattern", "Controller#Action"].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(options, routes_map) ⇒ HeaderGenerator
constructor
A new instance of HeaderGenerator.
Constructor Details
#initialize(options, routes_map) ⇒ HeaderGenerator
Returns a new instance of HeaderGenerator.
38 39 40 41 |
# File 'lib/annotate_rb/route_annotator/header_generator.rb', line 38 def initialize(, routes_map) @options = @routes_map = routes_map end |
Class Method Details
.generate(options = {}) ⇒ Object
9 10 11 |
# File 'lib/annotate_rb/route_annotator/header_generator.rb', line 9 def generate( = {}) new(, routes_map()).generate end |
Instance Method Details
#generate ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/annotate_rb/route_annotator/header_generator.rb', line 43 def generate magic_comments_map, contents_without_magic_comments = Helper.extract_magic_comments_from_array(routes_map) out = [] magic_comments_map.each do |magic_comment| out << magic_comment end out << "" if magic_comments_map.any? out << comment([:wrapper_open]) if [:wrapper_open] out << comment(markdown? ? PREFIX_MD : PREFIX) + out << comment return out if contents_without_magic_comments.size.zero? maxs = [HEADER_ROW.map(&:size)] + contents_without_magic_comments[1..-1].map { |line| line.split.map(&:size) } if markdown? max = maxs.map(&:max).compact.max out << comment(content(HEADER_ROW, maxs)) out << comment(content(["-" * max, "-" * max, "-" * max, "-" * max], maxs)) else out << comment(content(contents_without_magic_comments[0], maxs)) end out += contents_without_magic_comments[1..-1].map { |line| comment(content(markdown? ? line.split(" ") : line, maxs)) } out << comment([:wrapper_close]) if [:wrapper_close] out end |