Module: HaveAPI::Server::DocHelpers

Defined in:
lib/haveapi/server.rb

Instance Method Summary collapse

Instance Method Details

#escape_html(v) ⇒ Object



348
349
350
351
352
# File 'lib/haveapi/server.rb', line 348

def escape_html(v)
  return '' if v.nil?

  CGI.escapeHTML(v.to_s)
end

#format_param_type(param) ⇒ Object



334
335
336
337
338
339
340
341
342
# File 'lib/haveapi/server.rb', line 334

def format_param_type(param)
  return param[:type] if param[:type] != 'Resource'

  entry = documentation_resources.find { |resource| resource[:path] == param[:resource].map(&:to_s) }
  return param[:type] unless entry

  anchor = entry[:info][:actions].has_key?('show') || entry[:info][:actions].has_key?(:show) ? "#{entry[:id]}-show" : entry[:id]
  "<a href=\"#{escape_html(documentation_url(resource: entry[:key], anchor:))}\">#{param[:type]}</a>"
end

#format_validators(validators, type: nil) ⇒ Object



344
345
346
# File 'lib/haveapi/server.rb', line 344

def format_validators(validators, type: nil)
  DocumentationValidators.render(validators, type:)
end