lib/ghost_writer/document.rb in ghost_writer-0.1.1 vs lib/ghost_writer/document.rb in ghost_writer-0.2.0
- old
+ new
@@ -12,41 +12,55 @@
@param_example = attrs[:param_example]
@status_example = attrs[:status_example]
@response_example = attrs[:response_example]
end
- def write_file
+ def write_file(overwrite = false)
unless File.exist?(File.dirname(output))
FileUtils.mkdir_p(File.dirname(output))
end
- doc = File.open(output, "w")
- doc.write paragraph(<<EOP)
+ mode = overwrite ? "w" : "a"
+ doc = File.open(output, mode)
+
+ if overwrite
+ doc.write paragraph(<<EOP)
#{headword(title, 1)}
+
+--------------------------------
+
EOP
+ end
doc.write paragraph(<<EOP)
-#{headword("access path:", 2)}
+#{headword(description, 2)}
+EOP
+
+ doc.write paragraph(<<EOP)
+#{headword("access path:", 3)}
#{quote(url_example)}
EOP
doc.write paragraph(<<EOP)
-#{headword("request params:", 2)}
+#{headword("request params:", 3)}
#{quote(param_example.inspect, :ruby)}
EOP
doc.write paragraph(<<EOP)
-#{headword("status code:", 2)}
+#{headword("status code:", 3)}
#{quote(status_example)}
EOP
doc.write paragraph(<<EOP)
-#{headword("response:", 2)}
+#{headword("response:", 3)}
#{quote_response(response_example)}
EOP
doc.write paragraph(<<EOP)
-"Generated by \"#{description}\" at #{location}"
+Generated by "#{description}\" at #{location}
+
+--------------------------------
+
EOP
doc.close
end