Class: RTFDoc::Resource
- Inherits:
-
Object
- Object
- RTFDoc::Resource
- Defined in:
- lib/rtfdoc.rb
Constant Summary collapse
- DEFAULT =
%w[desc object index show create update destroy]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, sections) ⇒ Resource
constructor
A new instance of Resource.
- #menu_output ⇒ Object
- #output ⇒ Object
Constructor Details
#initialize(name, sections) ⇒ Resource
Returns a new instance of Resource.
366 367 368 |
# File 'lib/rtfdoc.rb', line 366 def initialize(name, sections) @name, @sections = name, sections end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
364 365 366 |
# File 'lib/rtfdoc.rb', line 364 def name @name end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
364 365 366 |
# File 'lib/rtfdoc.rb', line 364 def sections @sections end |
Class Method Details
.build(name, paths, endpoints: nil) ⇒ Object
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/rtfdoc.rb', line 323 def self.build(name, paths, endpoints: nil) endpoints ||= DEFAULT desc = nil sections = endpoints.each_with_object([]) do |endpoint, res| if endpoint.is_a?(Hash) n, values = endpoint.each_pair.first next unless n.start_with?('scope|') dir_name = n.slice(6..-1) scope_name = values['title'] || dir_name scoped_endpoints = values['endpoints'] subsections = scoped_endpoints.each_with_object([]) do |e, r| filename = paths.dig(dir_name, e) next unless filename content = File.read(filename) r << Section.new(e, content, resource: name) end res << Scope.new(scope_name, subsections) next res end 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
#menu_output ⇒ Object
378 379 380 381 382 383 384 385 386 |
# File 'lib/rtfdoc.rb', line 378 def head, *tail = sections <<-HTML <li data-anchor="#{name}"> #{head.anchor(human_name, class_list: 'expandable')} <ul>#{tail.map(&:).join}</ul> </li> HTML end |
#output ⇒ Object
370 371 372 373 374 375 376 |
# File 'lib/rtfdoc.rb', line 370 def output head, *tail = sections head. = true inner = sections.flat_map(&:output).join("\n") %(<section class="head-section">#{inner}</section>) end |