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

- old
+ new

@@ -1,18 +1,19 @@ class GhostWriter::Document - attr_reader :title, :description, :location, :url_example, :param_example, :status_example, :response_example, :output, :relative_path + attr_reader :title, :description, :location, :request_method, :path_info, :param_example, :status_example, :response_example, :output, :relative_path def initialize(output, attrs) format_module = "GhostWriter::Format::#{attrs[:format].to_s.classify}" extend(format_module.constantize) @output = output @relative_path = Pathname.new(output).relative_path_from(GhostWriter.output_path) @title = attrs[:title] @description = attrs[:description] @location = attrs[:location] - @url_example = attrs[:url_example] + @request_method = attrs[:request_method] + @path_info = attrs[:path_info] @param_example = attrs[:param_example] @status_example = attrs[:status_example] @response_example = attrs[:response_example] end @@ -20,11 +21,11 @@ unless File.exist?(File.dirname(output)) FileUtils.mkdir_p(File.dirname(output)) end mode = overwrite ? "w" : "a" - doc = File.open(output, mode) + doc = File.open("#{output}.#{extname}", mode) if overwrite doc.write paragraph(document_header) end @@ -33,30 +34,28 @@ doc.close end def document_header <<EOP -#{headword(title, 1)} +#{headword(title, 2)} -#{separator(32)} - EOP end def document_body <<EOP -#{headword(description, 2)} +#{headword(description, 3)} -#{headword("access path:", 3)} -#{quote(url_example)} +#{headword("access path:", 4)} +#{quote("#{request_method} #{path_info}")} -#{headword("request params:", 3)} +#{headword("request params:", 4)} #{quote(param_example.inspect, :ruby)} -#{headword("status code:", 3)} +#{headword("status code:", 4)} #{quote(status_example)} -#{headword("response:", 3)} +#{headword("response:", 4)} #{quote_response(response_example)} Generated by "#{description}\" at #{location} #{separator(32)}