Class: Nexmo::OAS::Renderer::ResponseParserDecorator
- Inherits:
-
OasParser::ResponseParser
- Object
- OasParser::ResponseParser
- Nexmo::OAS::Renderer::ResponseParserDecorator
- Defined in:
- lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb
Instance Method Summary collapse
- #formatted_json ⇒ Object
- #formatted_xml(xml_options = {}) ⇒ Object
- #html(format = 'application/json', xml_options: nil, theme_light: nil) ⇒ Object
Instance Method Details
#formatted_json ⇒ Object
11 12 13 14 15 16 |
# File 'lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb', line 11 def formatted_json JSON.neat_generate(parse, { wrap: true, after_colon: 1, }) end |
#formatted_xml(xml_options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb', line 18 def formatted_xml( = {}) [:root] = ['name'] if xml_string = xml() xml_string.gsub!(%r{^(\s+?)(<(?:\w|=|"|_|\s)+?>)(.+?)(</.+?>)}).each do |s| indentation = Regexp.last_match(1) indentation_plus_one = "#{Regexp.last_match(1)} " opening_tag = Regexp.last_match(2) content = Regexp.last_match(3) closing_tag = Regexp.last_match(4) next(s) if (indentation.size + opening_tag.size + content.size) < 60 next "#{indentation}#{opening_tag}\n#{indentation_plus_one}#{content}\n#{indentation}#{closing_tag}" end xml_string.gsub('<', '<') end |
#html(format = 'application/json', xml_options: nil, theme_light: nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb', line 36 def html(format = 'application/json', xml_options: nil, theme_light: nil) case format when 'application/json' language = 'json' response = formatted_json when 'text/xml', 'application/xml' language = 'xml' response = formatted_xml() end output = <<~HEREDOC <pre class="pre-wrap language-#{language} #{theme_light ? 'Vlt-prism--dark' : ''} Vlt-prism--copy-disabled"><code>#{response}</code></pre> HEREDOC output end |