Module: Locomotive::Misc::ApiDocumentation

Defined in:
lib/locomotive/misc/api_documentation.rb

Overview

Class to generate the documentation about the LocomotiveCMS Rest API

Defined Under Namespace

Classes: BootstrapRenderer, Parser

Class Method Summary collapse

Class Method Details

.embedded_resourcesArray

Return the list of embedded resources

Returns:

  • (Array)

    The list of hashes (keys: name, getters, setters)



31
32
33
34
35
36
37
38
39
40
# File 'lib/locomotive/misc/api_documentation.rb', line 31

def self.embedded_resources
  %w(editable_element editable_text editable_file editable_control content_field).map do |name|
    klass = "Locomotive::#{name.camelize}Presenter".constantize
    {
      name:     name,
      getters:  klass.getters_to_hash,
      setters:  klass.setters_to_hash,
    }
  end
end

.generate(renderer = nil) ⇒ Object

Generate the documentation depending on the renderer which is by default the BoostrapRenderer.

Parameters:

  • renderer (Object) (defaults to: nil)

    The instance of the renderer.



16
17
18
19
20
21
22
23
24
25
# File 'lib/locomotive/misc/api_documentation.rb', line 16

def self.generate(renderer = nil)
  renderer ||= BootstrapRenderer.new

  raise 'You must provide a renderer' if renderer.nil?

  parser = Parser.new
  parser.parse

  renderer.render(parser.resources, self.embedded_resources)
end