Class: DocsUI::JsonResponse
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- DocsUI::JsonResponse
- Defined in:
- app/components/docs_ui/json_response.rb
Overview
A pretty-printed JSON response block. Give it a Ruby Hash (deep-stringified and JSON.pretty_generate'd) or a pre-formatted String; it renders a DocsUI::Code with the json lexer and a filename title bar. Kills the hand-rolled deep_stringify + JSON.pretty_generate every API page was copy-pasting.
render DocsUI::JsonResponse.new({ id: "obj_1", status: "active" })
render DocsUI::JsonResponse.new(raw_json_string, filename: "webhook.json")
A Hash with symbol keys renders as real JSON (string keys, no :symbol / => leaking through). A String is passed through verbatim (already formatted).
Instance Method Summary collapse
-
#initialize(body, filename: "response.json") ⇒ JsonResponse
constructor
A new instance of JsonResponse.
- #view_template ⇒ Object
Constructor Details
#initialize(body, filename: "response.json") ⇒ JsonResponse
Returns a new instance of JsonResponse.
17 18 19 20 |
# File 'app/components/docs_ui/json_response.rb', line 17 def initialize(body, filename: "response.json") @body = body @filename = filename end |