From 46491759fe6fcb0ab8f08fc572918a67c4b5c3e6 Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Thu, 27 Jun 2019 14:06:19 -0400 Subject: [PATCH] Render class-level examples Note: The code samples emitted by this change are not yet rendered with syntax highlighted. --- lib/filters/api_json_filter.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/filters/api_json_filter.rb b/lib/filters/api_json_filter.rb index f6e3f79718..6bc110435b 100644 --- a/lib/filters/api_json_filter.rb +++ b/lib/filters/api_json_filter.rb @@ -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 +
+ #{markdown(example['description'])} +
+ HTML + end + + <<~HTML +
+ #{description} + #{markdown(example['raw'])} +
+ HTML + end.join("\n") + + <<~HTML +

Examples

+
+ #{entries} +
+ HTML + end + def page_title(data) <<~HTML

@@ -277,6 +307,7 @@ def run(content, params = {}) page_title(data) + class_description(data) + + class_examples(data) + sections(data) end end