Class: Fern::Documentation::MarkdownGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/fern/documentation/markdown_generator.rb

Constant Summary collapse

TEMPLATE =
%(# {{verb}} {{path}}

_{{controller}}\#{{action}}_

{{doc}}

{{#has_parameters}}
## Parameters

| Name | Type | Array | Required | Min | Max | Values | Default |
| ---- | ---- | ----- | -------- | --- | --- | ------ | ------- |
{{#parameters}}
| {{name}} | `{{ type }}` | {{ array }} | {{ required }} | {{ min }} | {{ max }} | {{ values }} | {{ default }} |
{{/parameters}}
{{/has_parameters}}

{{#has_form}}
## Form

{{#form}}
### Class

`{{klass}}`

{{#key}}
### Key

`{{key}}`
{{/key}}
{{/form}}

{{#presenter}}
## Presenter

### Class

`{{presenter}}`
{{/presenter}}
{{/has_form}}).freeze

Instance Method Summary collapse

Constructor Details

#initialize(analysis) ⇒ MarkdownGenerator

Returns a new instance of MarkdownGenerator.



46
47
48
# File 'lib/fern/documentation/markdown_generator.rb', line 46

def initialize(analysis)
  @analysis = analysis
end

Instance Method Details

#generateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fern/documentation/markdown_generator.rb', line 50

def generate
  params = build_params

  Mustache.render(
    TEMPLATE,
    verb: @analysis[:verb],
    path: @analysis[:path],
    controller: @analysis[:controller],
    action: @analysis[:action],
    doc: @analysis[:doc],
    has_parameters: params.present?,
    parameters: params,
    has_form: @analysis[:form].present?,
    form: @analysis[:form],
    presenter: @analysis[:presenter]
  )
end