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



27
28
29
30
# File 'lib/solargraph/pin/documenting.rb', line 27

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

Instance Attribute Details

#plaintextString (readonly)

Returns:

  • (String)


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

def plaintext
  @plaintext
end

Instance Method Details

#code?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/solargraph/pin/documenting.rb', line 32

def code?
  @code
end

#concat(text) ⇒ String

Parameters:

  • text (String)

Returns:

  • (String)


38
39
40
# File 'lib/solargraph/pin/documenting.rb', line 38

def concat text
  @plaintext.concat text
end

#to_sObject



42
43
44
45
46
47
48
49
# File 'lib/solargraph/pin/documenting.rb', line 42

def to_s
  return "\n```ruby\n#{@plaintext}#{@plaintext.end_with?("\n") ? '' : "\n"}```\n\n" if code?
  ReverseMarkdown.convert unescape_brackets(Maruku.new(escape_brackets(@plaintext), on_error: :raise).to_html)
rescue MaRuKu::Exception
  # Maruku exceptions usually indicate that the documentation is in
  # RDoc syntax.
  ReverseMarkdown.convert YARD::Templates::Helpers::Markup::RDocMarkup.new(@plaintext).to_html
end