class RamlDoc::View
Public Class Methods
new(raml)
click to toggle source
# File lib/raml_doc/view.rb, line 9 def initialize(raml) @raml = raml end
Public Instance Methods
markdown(string)
click to toggle source
# File lib/raml_doc/view.rb, line 24 def markdown(string) Kramdown::Document.new(string).to_html end
method_boostrap_label_css_class(method)
click to toggle source
# File lib/raml_doc/view.rb, line 52 def method_boostrap_label_css_class(method) case method.name when "get" then "label-success" when "post" then "label-primary" when "put" then "label-info" when "patch" then "label-warning" when "delete" then "label-danger" else "label-default" end end
method_element_id(method, *args)
click to toggle source
# File lib/raml_doc/view.rb, line 28 def method_element_id(method, *args) args << method.name args << method.parent.resource_path_name args.compact.join "-" end
method_querystring_example(parameters)
click to toggle source
# File lib/raml_doc/view.rb, line 34 def method_querystring_example(parameters) qs = [] parameters.each do |_, parameter| next if parameter.example.nil? next unless parameter.required || parameter.name.start_with?("utm_") qs << "#{parameter.name}=#{CGI.escape parameter.example}" end qs.join("&").strip end
method_uri_example(method)
click to toggle source
# File lib/raml_doc/view.rb, line 44 def method_uri_example(method) uri = [] uri << "#{method.parent.parent.base_uri}#{method.parent.resource_path}" uri << "#{method_querystring_example method.query_parameters}" uri.keep_if { |entry| present? entry } uri.join "?" end
present?(value)
click to toggle source
# File lib/raml_doc/view.rb, line 19 def present?(value) return !value.empty? if value.respond_to?(:empty?) !!value end
render(template, format)
click to toggle source
# File lib/raml_doc/view.rb, line 13 def render(template, format) template_path = File.join(File.expand_path("../templates", __FILE__), format, template, "index.#{format}.erb") template = ERB.new(File.read(template_path)) template.result binding end