Class: Apiculture::AppDocumentation
- Inherits:
-
Object
- Object
- Apiculture::AppDocumentation
- Defined in:
- lib/apiculture/app_documentation.rb
Defined Under Namespace
Classes: TaggedMarkdown
Instance Method Summary collapse
-
#initialize(app, mountpoint, action_definitions_and_markdown_segments) ⇒ AppDocumentation
constructor
A new instance of AppDocumentation.
-
#to_html ⇒ Object
Generates a complete HTML document string that can be saved into a file.
-
#to_html_fragment ⇒ Object
Generates an HTML fragment string that can be included into another HTML document.
-
#to_markdown ⇒ Object
Generates a Markdown string that contains the entire API documentation.
- #to_markdown_slices ⇒ Object
- #to_openapi ⇒ Object
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_html ⇒ Object
Generates a complete HTML document string that can be saved into a file
53 54 55 56 57 |
# 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 ⇒ Object
Generates an HTML fragment string that can be included into another HTML document
35 36 37 38 39 |
# 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 ⇒ Object
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_slices ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/apiculture/app_documentation.rb', line 30 def to_openapi OpenApiDocumentation::Base.new(@app_title, @mountpoint, @chunks) end |