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-1.7.2.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

#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