Class: RTFDoc::Section

Inherits:
Object
  • Object
show all
Includes:
Anchorable, RenderAsSection
Defined in:
lib/rtfdoc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Anchorable

#anchor

Methods included from RenderAsSection

#content_to_html, included

Constructor Details

#initialize(name, raw_content, resource: nil) ⇒ Section

Returns a new instance of Section.



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/rtfdoc.rb', line 212

def initialize(name, raw_content, resource: nil)
  @name     = name
  @resource = resource
    = nil

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

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

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

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



210
211
212
# File 'lib/rtfdoc.rb', line 210

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



210
211
212
# File 'lib/rtfdoc.rb', line 210

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



210
211
212
# File 'lib/rtfdoc.rb', line 210

def path
  @path
end

Instance Method Details

#anchor_idObject



232
233
234
# File 'lib/rtfdoc.rb', line 232

def anchor_id
  @resource ? "#{@resource}-#{id}" : id
end

#example_to_htmlObject



248
249
250
251
# File 'lib/rtfdoc.rb', line 248

def example_to_html
  res = super
  @resource && res && !meta_section? ? res.sub('RESPONSE', sig) : res
end

#idObject



228
229
230
# File 'lib/rtfdoc.rb', line 228

def id
  @id ||= name
end


240
241
242
# File 'lib/rtfdoc.rb', line 240

def menu_output
  "<li>#{anchor(menu_title)}</li>"
end

#resource_nameObject



236
237
238
# File 'lib/rtfdoc.rb', line 236

def resource_name
  @resource
end

#signatureObject



244
245
246
# File 'lib/rtfdoc.rb', line 244

def signature
  anchor(sig)
end