Class: Apiculture::AppDocumentation

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

Defined Under Namespace

Classes: TaggedMarkdown

Instance Method Summary collapse

Constructor Details

#initialize(app, mountpoint, action_definitions_and_markdown_segments) ⇒ AppDocumentation

Returns a new instance of AppDocumentation.



19
20
21
22
23
# 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

Instance Method Details

#to_htmlObject

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



49
50
51
52
53
# File 'lib/apiculture/app_documentation.rb', line 49

def to_html
  require 'mustache'
  template = File.read(__dir__ + '/app_documentation_tpl.mustache')
  Mustache.render(template, :html_fragment => to_html_fragment)
end

#to_html_fragmentObject

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



31
32
33
34
35
# File 'lib/apiculture/app_documentation.rb', line 31

def to_html_fragment
  to_markdown_slices.map do |tagged_markdown|
    tagged_markdown.to_html
  end.join("\n\n")
end

#to_markdownObject

Generates a Markdown string that contains the entire API documentation



26
27
28
# File 'lib/apiculture/app_documentation.rb', line 26

def to_markdown
  (['## %s' % @app_title] + to_markdown_slices).join("\n\n")
end

#to_markdown_slicesObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/apiculture/app_documentation.rb', line 37

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