Module: Generator::Formatter
Constant Summary collapse
- MAX_LINE_LENGTH =
120
Instance Method Summary collapse
- #convert_doc_links_to_full_url(text) ⇒ Object
- #convert_html_links_to_yard(text) ⇒ Object
- #format_method_definition(method_name, params, base_indent: 0, max_line_length: MAX_LINE_LENGTH) ⇒ Object
- #split_long_comment_line(line, base_indent: 0, wrap_indent: 0, max_line_length: MAX_LINE_LENGTH) ⇒ Object
Instance Method Details
#convert_doc_links_to_full_url(text) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/generator/formatter.rb', line 47 def convert_doc_links_to_full_url(text) text.gsub(/\[([^\]]+)\]\(doc:([^\)]+)\)/) do link_text = Regexp.last_match(1) path = Regexp.last_match(2) url = "https://developer-docs.amazon.com/sp-api/docs/#{path}" "{#{url} #{link_text}}" end end |
#convert_html_links_to_yard(text) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/generator/formatter.rb', line 57 def convert_html_links_to_yard(text) text.gsub(%r{<a href=['"]([^'"]+)['"]>([^<]+)</a>}) do url = Regexp.last_match(1) link_text = Regexp.last_match(2) "{#{url} #{link_text}}" end end |
#format_method_definition(method_name, params, base_indent: 0, max_line_length: MAX_LINE_LENGTH) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generator/formatter.rb', line 29 def format_method_definition(method_name, params, base_indent: 0, max_line_length: MAX_LINE_LENGTH) max_width = max_line_length - base_indent current_line = ["def #{method_name}("] lines = [] params.each do |param| if (current_line + ["#{param},"]).join.size <= max_width current_line << param + ", " else lines << " " * base_indent + current_line.join.strip current_line = [" " + param + ", "] end end lines << " " * base_indent + current_line.join[..-3] + ")" lines.join("\n") end |
#split_long_comment_line(line, base_indent: 0, wrap_indent: 0, max_line_length: MAX_LINE_LENGTH) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generator/formatter.rb', line 7 def split_long_comment_line(line, base_indent: 0, wrap_indent: 0, max_line_length: MAX_LINE_LENGTH) max_width = max_line_length - base_indent - 2 # Account for the space and `#` current_line = [] lines = [] line.sub(/^\s*#\s*/, "").split.each do |word| if lines.empty? && (current_line + [word]).join(" ").size <= max_width current_line << word elsif !lines.empty? && (current_line + [word]).join(" ").size <= max_width - wrap_indent current_line << word else lines << " " * base_indent + "# " + " " * (lines.empty? ? 0 : wrap_indent) + current_line.join(" ") current_line = [word] end end unless current_line.empty? lines << " " * base_indent + "# " + " " * (lines.empty? ? 0 : wrap_indent) + current_line.join(" ") end lines.empty? ? " " * base_indent + "#" : lines.join("\n") end |