class Apiculture::AppDocumentation

Public Class Methods

new(app, mountpoint, action_definitions_and_markdown_segments) click to toggle source
# File lib/apiculture/app_documentation.rb, line 19
def initialize(app, mountpoint, action_definitions_and_markdown_segments)
  @app_title = app.to_s
  @mountpoint = mountpoint
  @chunks = action_definitions_and_markdown_segments
end

Public Instance Methods

to_html() click to toggle source

Generates a complete HTML document string that can be saved into a file

# File lib/apiculture/app_documentation.rb, line 53
def to_html
  require 'mustache'
  template = File.read(__dir__ + '/app_documentation_tpl.mustache')
  Mustache.render(template, :html_fragment => to_html_fragment)
end
to_html_fragment() click to toggle source

Generates an HTML fragment string that can be included into another HTML document

# File lib/apiculture/app_documentation.rb, line 35
def to_html_fragment
  to_markdown_slices.map do |tagged_markdown|
    tagged_markdown.to_html
  end.join("\n\n")
end
to_markdown() click to toggle source

Generates a Markdown string that contains the entire API documentation

# File lib/apiculture/app_documentation.rb, line 26
def to_markdown
  (['## %s' % @app_title] + to_markdown_slices).join("\n\n")
end
to_markdown_slices() click to toggle source
# File lib/apiculture/app_documentation.rb, line 41
def to_markdown_slices
  markdown_slices = @chunks.map do | action_def_or_doc |
    if action_def_or_doc.respond_to?(:http_verb) # ActionDefinition
      s = Apiculture::MethodDocumentation.new(action_def_or_doc, @mountpoint).to_markdown
      TaggedMarkdown.new(s, 'apiculture-method')
    elsif action_def_or_doc.respond_to?(:to_markdown)
      TaggedMarkdown.new(action_def_or_doc, 'apiculture-verbatim')
    end
  end
end
to_openapi() click to toggle source
# File lib/apiculture/app_documentation.rb, line 30
def to_openapi
  OpenApiDocumentation::Base.new(@app_title, @mountpoint, @chunks)
end