lib/ghost_writer.rb in ghost_writer-0.3.1 vs lib/ghost_writer.rb in ghost_writer-0.4.0

- old
+ new

@@ -7,10 +7,11 @@ extend ActiveSupport::Concern module Format autoload "Markdown", "ghost_writer/format/markdown" autoload "Rst", "ghost_writer/format/rst" + autoload "Rack", "ghost_writer/format/rack" end DEFAULT_OUTPUT_DIR = "api_examples".freeze DEFAULT_FORMAT = :markdown DOCUMENT_INDEX_FILENAME = "document_index".freeze @@ -27,14 +28,14 @@ def generate_api_doc if output_flag unless File.exist?(output_path) FileUtils.mkdir_p(output_path) end - document_index = GhostWriter::DocumentIndex.new(output_path + "#{DOCUMENT_INDEX_FILENAME}.#{output_format}", document_group, GhostWriter.output_format) - document_index.write_file + document_index = GhostWriter::DocumentIndex.new(output_path + "#{DOCUMENT_INDEX_FILENAME}", document_group, GhostWriter.output_format) + document_index.write_index_file document_group.each do |output, docs| - docs.sort_by!(&:description) + docs.sort_by!(&:location) docs.shift.write_file(true) docs.each(&:write_file) end document_group.clear @@ -57,16 +58,17 @@ @output_format || DEFAULT_FORMAT end end def collect_example - output = File.join(doc_dir, "#{doc_name}.#{GhostWriter.output_format}") + output = File.join(doc_dir, "#{doc_name}") document = GhostWriter::Document.new(output, { title: "#{described_class} #{doc_name.titleize}", description: example.full_description.dup, location: example.location.dup, - url_example: "#{request.env["REQUEST_METHOD"]} #{request.env["PATH_INFO"]}", + request_method: request.env["REQUEST_METHOD"], + path_info: request.env["PATH_INFO"], param_example: controller.params.reject {|key, val| key == "controller" || key == "action"}, status_example: response.status.inspect, response_example: response.body, format: GhostWriter.output_format }) @@ -79,19 +81,23 @@ def doc_dir GhostWriter.output_path + described_class.to_s.underscore end def doc_name - if example.metadata[:generate_api_doc].is_a?(String) || example.metadata[:generate_api_doc].is_a?(Symbol) + metadata = example.metadata[:generate_api_doc] || example.metadata[:ghost_writer] + case metadata + when String, Symbol example.metadata[:generate_api_doc].to_s else controller.action_name end end included do after do - if (example.metadata[:type] == :controller || example.metadata[:type] == :request) && example.metadata[:generate_api_doc] + target_type = example.metadata[:type] == :controller || example.metadata[:type] == :request + target_metadata = example.metadata[:generate_api_doc] || example.metadata[:ghost_writer] + if target_type && target_metadata collect_example if GhostWriter.output_flag end end end end