17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/controllers/apipie/apipies_controller.rb', line 17
def index
params[:version] ||= Apipie.configuration.default_version
get_format
respond_to do |format|
if Apipie.configuration.use_cache?
render_from_cache
return
end
@language = get_language
Apipie.load_documentation if Apipie.configuration.reload_controllers? || (Rails.version.to_i >= 4.0 && !Rails.application.config.eager_load)
I18n.locale = @language
@doc = Apipie.to_json(params[:version], params[:resource], params[:method], @language)
format.json do
if @doc
render :json => @doc
else
head :not_found
end
end
format.html do
unless @doc
render 'apipie_404', :status => 404
return
end
@versions = Apipie.available_versions
@doc = @doc[:docs]
@doc[:link_extension] = (@language ? ".#{@language}" : '')+Apipie.configuration.link_extension
if @doc[:resources].blank?
render "getting_started" and return
end
@resource = @doc[:resources].first if params[:resource].present?
@method = @resource[:methods].first if params[:method].present?
@languages = Apipie.configuration.languages
if @resource && @method
render 'method'
elsif @resource
render 'resource'
elsif params[:resource].present? || params[:method].present?
render 'apipie_404', :status => 404
else
render 'index'
end
end
end
end
|