Module: Apipie::Helpers

Included in:
Apipie
Defined in:
lib/apipie/helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#url_prefixObject

Returns the value of attribute url_prefix.



12
13
14
# File 'lib/apipie/helpers.rb', line 12

def url_prefix
  @url_prefix
end

Instance Method Details

#full_url(path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/apipie/helpers.rb', line 22

def full_url(path)
  unless @url_prefix
    @url_prefix = ""
    @url_prefix << request_script_name
    @url_prefix << Apipie.configuration.doc_base_url
  end
  path = path.sub(/^\//,"")
  ret = "#{@url_prefix}/#{path}"
  ret.insert(0,"/") unless ret =~ /\A[.\/]/
  ret.sub!(/\/*\Z/,"")
  ret
end

#include_javascriptsObject



35
36
37
38
39
40
41
42
# File 'lib/apipie/helpers.rb', line 35

def include_javascripts
  %w[ bundled/jquery.js
      bundled/bootstrap-collapse.js
      bundled/prettify.js
      apipie.js ].map do |file|
    "<script type='text/javascript' src='#{Apipie.full_url("javascripts/#{file}")}'></script>"
  end.join("\n").html_safe
end

#include_stylesheetsObject



44
45
46
47
48
49
50
# File 'lib/apipie/helpers.rb', line 44

def include_stylesheets
  %w[ bundled/bootstrap.min.css
      bundled/prettify.css
      bundled/bootstrap-responsive.min.css ].map do |file|
    "<link type='text/css' rel='stylesheet' href='#{Apipie.full_url("stylesheets/#{file}")}'/>"
  end.join("\n").html_safe
end

#label_class_for_error(err) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/apipie/helpers.rb', line 52

def label_class_for_error(err)
  case err[:code]
    when 200
      'label label-info'
    when 201
      'label label-success'
    when 204
      'label label-info2'
    when 401
      'label label-warning'
    when 403
      'label label-warning2'
    when 422
      'label label-important'
    when 404
      'label label-inverse'
    else
      'label'
  end
end

#markup_to_html(text) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/apipie/helpers.rb', line 3

def markup_to_html(text)
  return "" if text.nil?
  if Apipie.configuration.markup.respond_to? :to_html
    Apipie.configuration.markup.to_html(text.strip_heredoc)
  else
    text.strip_heredoc
  end
end

#request_script_nameObject



14
15
16
# File 'lib/apipie/helpers.rb', line 14

def request_script_name
  Thread.current[:apipie_req_script_name] || ""
end

#request_script_name=(script_name) ⇒ Object



18
19
20
# File 'lib/apipie/helpers.rb', line 18

def request_script_name=(script_name)
  Thread.current[:apipie_req_script_name] = script_name
end