class RTFDoc::Section

Attributes

method[R]
name[R]
path[R]

Public Class Methods

new(name, raw_content, resource: nil) click to toggle source
# File lib/rtfdoc.rb, line 212
def initialize(name, raw_content, resource: nil)
  @name     = name
  @resource = resource
  metadata  = nil

  if raw_content.start_with?('---')
    idx = raw_content.index('---', 4)
    raise 'bad format' unless idx
    parse_metadata(YAML.load(raw_content.slice!(0, idx + 3)))
  end

  raise 'missing metadata' if resource && !meta_section? && !@path && !@method

  @content, @example = raw_content.split('$$$')
end

Public Instance Methods

anchor_id() click to toggle source
# File lib/rtfdoc.rb, line 232
def anchor_id
  @resource ? "#{@resource}-#{id}" : id
end
example_to_html() click to toggle source
Calls superclass method RTFDoc::RenderAsSection#example_to_html
# File lib/rtfdoc.rb, line 248
def example_to_html
  res = super
  @resource && res && !meta_section? ? res.sub('RESPONSE', sig) : res
end
id() click to toggle source
# File lib/rtfdoc.rb, line 228
def id
  @id ||= name
end
menu_output() click to toggle source
resource_name() click to toggle source
# File lib/rtfdoc.rb, line 236
def resource_name
  @resource
end
signature() click to toggle source
# File lib/rtfdoc.rb, line 244
def signature
  anchor(sig)
end

Private Instance Methods

menu_title() click to toggle source
meta_section?() click to toggle source
# File lib/rtfdoc.rb, line 264
def meta_section?
  name == 'desc' || name == 'object'
end
parse_metadata(hash) click to toggle source
# File lib/rtfdoc.rb, line 272
def parse_metadata(hash)
  @id           = hash['id']
  @menu_title   = hash['menu_title']
  @path         = hash['path']
  @method       = hash['method']
end
sig() click to toggle source
# File lib/rtfdoc.rb, line 255
    def sig
      @sig ||= <<-HTML.strip!
        <div class="endpoint-def">
          <div class="method method__#{method.downcase}">#{method.upcase}</div>
          <div class="path">#{path}</div>
        </div>
      HTML
    end