Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possiblity to generate the json version of the documentation #186

Merged
merged 1 commit into from
Jan 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ This will copy the Apipie views to ``app/views/apipie/apipies`` and
To generate a static version of documentation (perhaps to put it on
project site or something) run ``rake apipie:static`` task. It will
create set of html files (multi-pages, single-page, plain) in your doc
directory. By default the documentation for default API version is
directory. If you prefer a json version run ``rake apipie:static_json``.
By default the documentation for default API version is
used, you can specify the version with ``rake apipie:static[2.0]``

When you want to avoid any unnecessary computation in production mode,
Expand Down
17 changes: 17 additions & 0 deletions lib/tasks/apipie.rake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ namespace :apipie do
end
end

desc "Generate static documentation json"
task :static_json, [:version] => :environment do |t, args|
with_loaded_documentation do
args.with_defaults(:version => Apipie.configuration.default_version)
out = ENV["OUT"] || File.join(::Rails.root, 'doc', 'apidoc')
doc = Apipie.to_json(args[:version])
generate_json_page(out, doc)
end
end

desc "Generate cache to avoid production dependencies on markup languages"
task :cache => :environment do
with_loaded_documentation do
Expand Down Expand Up @@ -79,6 +89,13 @@ namespace :apipie do
end
end

def generate_json_page(file_base, doc)
FileUtils.mkdir_p(file_base) unless File.exists?(file_base)

filename = 'schema_apipie.json'
File.open("#{file_base}/#{filename}", 'w') { |file| file.write(JSON.pretty_generate(doc)) }
end

def generate_one_page(file_base, doc)
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))

Expand Down