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, #example_to_html, included

Constructor Details

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

Returns a new instance of Section.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/rtfdoc.rb', line 147

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 && !@path && !@method

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

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



145
146
147
# File 'lib/rtfdoc.rb', line 145

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



145
146
147
# File 'lib/rtfdoc.rb', line 145

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



145
146
147
# File 'lib/rtfdoc.rb', line 145

def path
  @path
end

Instance Method Details

#anchor_idObject



167
168
169
# File 'lib/rtfdoc.rb', line 167

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

#idObject



163
164
165
# File 'lib/rtfdoc.rb', line 163

def id
  @id ||= name
end


175
176
177
# File 'lib/rtfdoc.rb', line 175

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

#resource_nameObject



171
172
173
# File 'lib/rtfdoc.rb', line 171

def resource_name
  @resource
end

#signatureObject



179
180
181
182
183
184
185
186
187
188
# File 'lib/rtfdoc.rb', line 179

def signature
  sig = <<-HTML.strip!
    <div class="endpoint-def">
      <div class="method method__#{method.downcase}">#{method.upcase}</div>
      <div class="path">#{path}</div>
    </div>
  HTML

  anchor(sig)
end