lib/ghost_writer/document.rb in ghost_writer-0.2.0 vs lib/ghost_writer/document.rb in ghost_writer-0.3.0

- old
+ new

@@ -1,10 +1,12 @@ class GhostWriter::Document attr_reader :title, :description, :location, :url_example, :param_example, :status_example, :response_example, :output, :relative_path def initialize(output, attrs) - extend(GhostWriter::Format::Markdown) + 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] @@ -21,49 +23,47 @@ mode = overwrite ? "w" : "a" doc = File.open(output, mode) if overwrite - doc.write paragraph(<<EOP) + doc.write paragraph(document_header) + end + + doc.write(document_body) + + doc.close + end + + def document_header + <<EOP #{headword(title, 1)} --------------------------------- +#{separator(32)} EOP - end + end - doc.write paragraph(<<EOP) + def document_body + <<EOP #{headword(description, 2)} -EOP - doc.write paragraph(<<EOP) #{headword("access path:", 3)} #{quote(url_example)} -EOP - doc.write paragraph(<<EOP) #{headword("request params:", 3)} #{quote(param_example.inspect, :ruby)} -EOP - doc.write paragraph(<<EOP) #{headword("status code:", 3)} #{quote(status_example)} -EOP - doc.write paragraph(<<EOP) #{headword("response:", 3)} #{quote_response(response_example)} -EOP - doc.write paragraph(<<EOP) Generated by "#{description}\" at #{location} --------------------------------- +#{separator(32)} EOP - - doc.close end private def quote_response(body) if param_example[:format] && param_example[:format].to_sym == :json