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.



269
270
271
# File 'lib/rtfdoc.rb', line 269

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



267
268
269
# File 'lib/rtfdoc.rb', line 267

def name
  @name
end

#sectionsObject (readonly)

Returns the value of attribute sections.



267
268
269
# File 'lib/rtfdoc.rb', line 267

def sections
  @sections
end

Class Method Details

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



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/rtfdoc.rb', line 245

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



281
282
283
284
285
286
287
288
289
# File 'lib/rtfdoc.rb', line 281

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



273
274
275
276
277
278
279
# File 'lib/rtfdoc.rb', line 273

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

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