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.



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rtfdoc.rb', line 162

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.



160
161
162
# File 'lib/rtfdoc.rb', line 160

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



160
161
162
# File 'lib/rtfdoc.rb', line 160

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



160
161
162
# File 'lib/rtfdoc.rb', line 160

def path
  @path
end

Instance Method Details

#anchor_idObject



182
183
184
# File 'lib/rtfdoc.rb', line 182

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

#example_to_htmlObject



198
199
200
201
# File 'lib/rtfdoc.rb', line 198

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

#idObject



178
179
180
# File 'lib/rtfdoc.rb', line 178

def id
  @id ||= name
end


190
191
192
# File 'lib/rtfdoc.rb', line 190

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

#resource_nameObject



186
187
188
# File 'lib/rtfdoc.rb', line 186

def resource_name
  @resource
end

#signatureObject



194
195
196
# File 'lib/rtfdoc.rb', line 194

def signature
  anchor(sig)
end