Class: RTFDoc::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/rtfdoc.rb

Constant Summary collapse

DEFAULT =
%w[desc object index show create update destroy]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, sections) ⇒ Resource

Returns a new instance of Resource.



295
296
297
# File 'lib/rtfdoc.rb', line 295

def initialize(name, sections)
  @name, @sections = name, sections
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



293
294
295
# File 'lib/rtfdoc.rb', line 293

def name
  @name
end

#sectionsObject (readonly)

Returns the value of attribute sections.



293
294
295
# File 'lib/rtfdoc.rb', line 293

def sections
  @sections
end

Class Method Details

.build(name, paths, endpoints: nil) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/rtfdoc.rb', line 271

def self.build(name, paths, endpoints: nil)
  endpoints ||= DEFAULT
  desc = nil

  sections = endpoints.each_with_object([]) do |endpoint, res|
    filename = paths[endpoint]
    next unless filename

    content = File.read(filename)

    if endpoint == 'desc'
      desc = ResourceDesc.new(name, content)
      res << desc
    else
      res << Section.new(endpoint, content, resource: name)
    end
  end

  desc&.generate_example(sections)
  Resource.new(name, sections)
end

Instance Method Details



307
308
309
310
311
312
313
314
315
# File 'lib/rtfdoc.rb', line 307

def menu_output
  head, *tail = sections
  <<-HTML
    <li data-anchor="#{name}">
      #{head.anchor(name.capitalize, class_list: 'expandable')}
      <ul>#{tail.map(&:menu_output).join}</ul>
    </li>
  HTML
end

#outputObject



299
300
301
302
303
304
305
# File 'lib/rtfdoc.rb', line 299

def output
  head, *tail = sections
  head.include_show_button = true

  inner = sections.map(&:output).join("\n")
  %(<section class="head-section">#{inner}</section>)
end