Permalink
Browse files

Add more options to apipie:cache

  • Loading branch information...
1 parent 9c982b1 commit 0745ea21cdd8f2bf7b88d7f1051de658df1ef87e @mbacovsky mbacovsky committed Jul 2, 2014
Showing with 28 additions and 12 deletions.
  1. +4 −0 README.rst
  2. +1 −1 app/views/apipie/apipies/index.html.erb
  3. +23 −11 lib/tasks/apipie.rake
View
@@ -979,6 +979,10 @@ When you want to avoid any unnecessary computation in production mode,
you can generate a cache with ``rake apipie:cache`` and configure the
app to use it in production with ``config.use_cache = Rails.env.production?``
+If, for some complex casese, you need to generate/re-generate just part of the cache
+use ``rake apipie:cache cache_part=index`` resp. ``rake apipie:cache cache_part=resources``
+To generate it to different location for further processing use ``rake apipie:cache OUT=/tmp/apipie_cache``.
+
===================
JSON checksums
===================
@@ -1,5 +1,5 @@
<ul class='breadcrumb'>
- <li class='active'><a href='<%= @doc[:doc_url] %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @doc[:resources].values.first[:version] %></a></li>
+ <li class='active'><a href='<%= @doc[:doc_url] %><%= @doc[:link_extension] %>'><%= @doc[:name] %> <%= @doc[:resources].values.first && @doc[:resources].values.first[:version] %></a></li>
<%= render(:partial => "languages", :locals => {:doc_url => @doc[:doc_url]}) %>
<% if @versions && @versions.size > 1 %>
<li class='pull-right'>
View
@@ -51,32 +51,44 @@ namespace :apipie do
end
end
+ # By default the full cache is built.
+ # It is possible to generate index resp. resources only with
+ # rake apipie:cache cache_part=index (resources resp.)
+ # Default output dir ('public/apipie_cache') can be changed with OUT=/some/dir
desc "Generate cache to avoid production dependencies on markup languages"
task :cache => :environment do
puts "#{Time.now} | Started"
+ cache_part = ENV['cache_part']
+ generate_index = (cache_part == 'resources' ? false : true)
+ generate_resources = (cache_part == 'index' ? false : true)
with_loaded_documentation do
puts "#{Time.now} | Documents loaded..."
([nil] + Apipie.configuration.languages).each do |lang|
I18n.locale = lang || Apipie.configuration.default_locale
puts "#{Time.now} | Processing docs for #{lang}"
- cache_dir = Apipie.configuration.cache_dir
+ cache_dir = ENV["OUT"] || Apipie.configuration.cache_dir
subdir = Apipie.configuration.doc_base_url.sub(/\A\//,"")
-
file_base = File.join(cache_dir, Apipie.configuration.doc_base_url)
- Apipie.url_prefix = "./#{subdir}"
- doc = Apipie.to_json(Apipie.configuration.default_version, nil, nil, lang)
- doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
- generate_index_page(file_base, doc, true, false, lang)
+
+ if generate_index
+ Apipie.url_prefix = "./#{subdir}"
+ doc = Apipie.to_json(Apipie.configuration.default_version, nil, nil, lang)
+ doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
+ generate_index_page(file_base, doc, true, false, lang)
+ end
Apipie.available_versions.each do |version|
file_base_version = File.join(file_base, version)
Apipie.url_prefix = "../#{subdir}"
doc = Apipie.to_json(version, nil, nil, lang)
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
- generate_index_page(file_base_version, doc, true, true, lang)
- Apipie.url_prefix = "../../#{subdir}"
- generate_resource_pages(version, file_base_version, doc, true, lang)
- Apipie.url_prefix = "../../../#{subdir}"
- generate_method_pages(version, file_base_version, doc, true, lang)
+
+ generate_index_page(file_base_version, doc, true, true, lang) if generate_index
+ if generate_resources
+ Apipie.url_prefix = "../../#{subdir}"
+ generate_resource_pages(version, file_base_version, doc, true, lang)
+ Apipie.url_prefix = "../../../#{subdir}"
+ generate_method_pages(version, file_base_version, doc, true, lang)
+ end
end
end
end

0 comments on commit 0745ea2

Please sign in to comment.