module Solargraph::Pin::Documenting
A module to add the Pin::Base#documentation method.
Public Class Methods
Source
# File lib/solargraph/pin/documenting.rb, line 103 def self.normalize_indentation text left = text.lines.map do |line| match = line.match(/^ +/) next 0 unless match match[0].length end.min return text if left.nil? || left.zero? text.lines.map { |line| line[left..] }.join end
@param text [String] @return [String]
Source
# File lib/solargraph/pin/documenting.rb, line 97 def self.strip_html_comments text text.gsub(/<!--([\s\S]*?)-->/, '').strip end
@param text [String] @return [String]
Public Instance Methods
Source
# File lib/solargraph/pin/documenting.rb, line 75 def documentation @documentation ||= begin # Using DocSections allows for code blocks that start with an empty # line and at least two spaces of indentation. This is a common # convention in Ruby core documentation, e.g., String#split. sections = [DocSection.new(false)] Documenting.normalize_indentation(Documenting.strip_html_comments(docstring.to_s.gsub("\t", ' '))).lines.each do |l| if l.start_with?(' ') # Code block sections.push DocSection.new(true) unless sections.last.code? elsif sections.last.code? # Regular documentation sections.push DocSection.new(false) end sections.last.concat l end sections.map(&:to_s).join.strip end end
@return [String]