|
19 | 19 | #
|
20 | 20 | # Released under the same license as Ruby. No Support. No Warranty.
|
21 | 21 | #
|
| 22 | + |
| 23 | +require_relative './annotate_routes/helpers' |
| 24 | + |
22 | 25 | module AnnotateRoutes
|
23 | 26 | PREFIX = '== Route Map'.freeze
|
24 | 27 | PREFIX_MD = '## Route Map'.freeze
|
25 | 28 | HEADER_ROW = ['Prefix', 'Verb', 'URI Pattern', 'Controller#Action'].freeze
|
26 | 29 |
|
27 |
| - MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/).freeze |
28 |
| - |
29 | 30 | class << self
|
30 | 31 | def do_annotations(options = {})
|
31 | 32 | if routes_file_exist?
|
@@ -73,7 +74,7 @@ def routes_file
|
73 | 74 | def header(options = {})
|
74 | 75 | routes_map = app_routes_map(options)
|
75 | 76 |
|
76 |
| - magic_comments_map, routes_map = extract_magic_comments_from_array(routes_map) |
| 77 | + magic_comments_map, routes_map = Helpers.extract_magic_comments_from_array(routes_map) |
77 | 78 |
|
78 | 79 | out = []
|
79 | 80 |
|
@@ -168,7 +169,7 @@ def rewrite_contents(existing_text, new_text)
|
168 | 169 | end
|
169 | 170 |
|
170 | 171 | def annotate_routes(header, content, header_position, options = {})
|
171 |
| - magic_comments_map, content = extract_magic_comments_from_array(content) |
| 172 | + magic_comments_map, content = Helpers.extract_magic_comments_from_array(content) |
172 | 173 | if %w(before top).include?(options[:position_in_routes])
|
173 | 174 | header = header << '' if content.first != ''
|
174 | 175 | magic_comments_map << '' if magic_comments_map.any?
|
@@ -208,24 +209,6 @@ def app_routes_map(options)
|
208 | 209 | routes_map
|
209 | 210 | end
|
210 | 211 |
|
211 |
| - # @param [Array<String>] content |
212 |
| - # @return [Array<String>] all found magic comments |
213 |
| - # @return [Array<String>] content without magic comments |
214 |
| - def extract_magic_comments_from_array(content_array) |
215 |
| - magic_comments = [] |
216 |
| - new_content = [] |
217 |
| - |
218 |
| - content_array.each do |row| |
219 |
| - if row =~ MAGIC_COMMENT_MATCHER |
220 |
| - magic_comments << row.strip |
221 |
| - else |
222 |
| - new_content << row |
223 |
| - end |
224 |
| - end |
225 |
| - |
226 |
| - [magic_comments, new_content] |
227 |
| - end |
228 |
| - |
229 | 212 | def content(line, maxs, options = {})
|
230 | 213 | return line.rstrip unless options[:format_markdown]
|
231 | 214 |
|
|
0 commit comments