Class: Solargraph::Pin::Documenting::DocSection

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/pin/documenting.rb

Overview

A documentation formatter that either performs Markdown conversion for text, or applies backticks for code blocks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ DocSection

Returns a new instance of DocSection.

Parameters:

  • code (Boolean)

    True if this section is a code block



25
26
27
28
# File 'lib/solargraph/pin/documenting.rb', line 25

def initialize code
  @plaintext = String.new('')
  @code = code
end

Instance Attribute Details

#plaintextString (readonly)

Returns:

  • (String)


22
23
24
# File 'lib/solargraph/pin/documenting.rb', line 22

def plaintext
  @plaintext
end

Instance Method Details

#code?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/solargraph/pin/documenting.rb', line 30

def code?
  @code
end

#concat(text) ⇒ String

Parameters:

  • text (String)

Returns:

  • (String)


36
37
38
# File 'lib/solargraph/pin/documenting.rb', line 36

def concat text
  @plaintext.concat text
end

#to_sObject



40
41
42
43
# File 'lib/solargraph/pin/documenting.rb', line 40

def to_s
  return "\n```ruby\n#{@plaintext}#{@plaintext.end_with?("\n") ? '' : "\n"}```\n\n" if code?
  ReverseMarkdown.convert unescape_brackets(Kramdown::Document.new(escape_brackets(@plaintext), input: 'GFM').to_html)
end