Class: AnnotateRoutes::HeaderGenerator
- Inherits:
-
Object
- Object
- AnnotateRoutes::HeaderGenerator
- Defined in:
- lib/annotate/annotate_routes/header_generator.rb
Constant Summary collapse
- PREFIX =
'== Route Map'- PREFIX_MD =
'## Route Map'- 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.
41 42 43 44 |
# File 'lib/annotate/annotate_routes/header_generator.rb', line 41 def initialize(, routes_map) = @routes_map = routes_map end |
Class Method Details
.generate(options = {}) ⇒ Object
12 13 14 |
# File 'lib/annotate/annotate_routes/header_generator.rb', line 12 def generate( = {}) new(, routes_map()).generate end |
Instance Method Details
#generate ⇒ Object
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 75 76 77 78 79 |
# File 'lib/annotate/annotate_routes/header_generator.rb', line 46 def generate magic_comments_map, contents_without_magic_comments = Helpers.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..].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..].map do |line| comment(content(markdown? ? line.split(' ') : line, maxs)) end out << comment([:wrapper_close]) if [:wrapper_close] out end |