Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Render class-level examples
Browse files Browse the repository at this point in the history
Note: The code samples emitted by this change are not yet rendered with 
syntax highlighted.
  • Loading branch information
jasonrudolph committed Jun 27, 2019
1 parent 6cdbad6 commit 4649175
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/filters/api_json_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,36 @@ def class_description(data)
markdown(data["description"])
end

def class_examples(data)
examples = Array(data["examples"])
return '' if examples.empty?

entries = examples.map do |example|
description = ''
unless example['description'].empty?
description = <<~HTML
<div class="description markdown-body">
#{markdown(example['description'])}
</div>
HTML
end

<<~HTML
<div class="example">
#{description}
#{markdown(example['raw'])}
</div>
HTML
end.join("\n")

<<~HTML
<h2 class="section">Examples</h2>
<div class="document-examples markdown-body">
#{entries}
</div>
HTML
end

def page_title(data)
<<~HTML
<h2 class="page-title">
Expand Down Expand Up @@ -277,6 +307,7 @@ def run(content, params = {})

page_title(data) +
class_description(data) +
class_examples(data) +
sections(data)
end
end

0 comments on commit 4649175

Please sign in to comment.