Class: Respect::JSONSchemaHTMLFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/respect/json_schema_html_formatter.rb

Overview

Format a JSON schema in HTML with CSS class to allow highlighting.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (JSONSchemaHTMLFormatter) initialize(json_schema)

A new instance of JSONSchemaHTMLFormatter



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/respect/json_schema_html_formatter.rb', line 4

def initialize(json_schema)
  @indent_level = 0
  @indent_size = 2
  @json_schema = json_schema
  @css_class ||= {
    json_highlight: "json_highlight",
    plain: "plain",
    key: "key",
    keyword: "keyword",
    string: "string",
    numeric: "numeric",
    comment: "comment",
  }
end

Instance Attribute Details

- (Object) css_class

Returns the value of attribute css_class



19
20
21
# File 'lib/respect/json_schema_html_formatter.rb', line 19

def css_class
  @css_class
end

Instance Method Details

- (Object) dump(output = "")



21
22
23
24
25
26
27
28
# File 'lib/respect/json_schema_html_formatter.rb', line 21

def dump(output = "")
  @output = output
  @output ||= String.new
  @output << "<div class=\"#{css_class[:json_highlight]}\"><pre>"
  @output << dump_json(@json_schema)
  @output << "</pre></div>\n"
  @output
end