Module: HaveAPI::Server::DocHelpers

Defined in:
lib/haveapi/server.rb

Instance Method Summary collapse

Instance Method Details

#escape_html(v) ⇒ Object



177
178
179
180
181
# File 'lib/haveapi/server.rb', line 177

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

  CGI.escapeHTML(v.to_s)
end

#format_param_type(param) ⇒ Object



155
156
157
158
159
# File 'lib/haveapi/server.rb', line 155

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

  "<a href=\"#root-#{param[:resource].join('-')}-show\">#{param[:type]}</a>"
end

#format_validators(validators) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/haveapi/server.rb', line 161

def format_validators(validators)
  ret = ''
  return ret if validators.nil?

  validators.each do |name, opts|
    ret += "<h5>#{name.to_s.capitalize}</h5>"
    ret += '<dl>'
    opts.each do |k, v|
      ret += "<dt>#{k}</dt><dd>#{escape_html(v.to_s)}</dd>"
    end
    ret += '</dl>'
  end

  ret
end