-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All writers now inherit from a base writer
* the writers are now responsible for cleaning docs * added an append_json writer that does not delete docs and simply modifies index.json
- Loading branch information
Showing
14 changed files
with
111 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'rspec_api_documentation/writers/formatter' | ||
|
||
module RspecApiDocumentation | ||
module Writers | ||
class AppendJsonWriter < JsonWriter | ||
def write | ||
index_file = docs_dir.join("index.json") | ||
if File.exists?(index_file) && (output = File.read(index_file)).length >= 2 | ||
existing_index_hash = JSON.parse(output) | ||
end | ||
File.open(index_file, "w+") do |f| | ||
f.write Formatter.to_json(AppendJsonIndex.new(index, configuration, existing_index_hash)) | ||
end | ||
write_examples | ||
end | ||
|
||
def self.clear_docs(docs_dir) | ||
nil #noop | ||
end | ||
end | ||
|
||
class AppendJsonIndex < JsonIndex | ||
def initialize(index, configuration, existing_index_hash = nil) | ||
@index = index | ||
@configuration = configuration | ||
@existing_index_hash = clean_index_hash(existing_index_hash) | ||
end | ||
|
||
def as_json(opts = nil) | ||
sections.inject(@existing_index_hash) do |h, section| | ||
h[:resources].push(section_hash(section)) | ||
h | ||
end | ||
end | ||
|
||
def clean_index_hash(existing_index_hash) | ||
unless existing_index_hash.is_a?(Hash) && existing_index_hash["resources"].is_a?(Array) #check format | ||
existing_index_hash = {:resources => []} | ||
end | ||
existing_index_hash = existing_index_hash.deep_symbolize_keys | ||
existing_index_hash[:resources].map!(&:deep_symbolize_keys).reject! do |resource| | ||
resource_names = sections.map{|s| s[:resource_name]} | ||
resource_names.include? resource[:name] | ||
end | ||
existing_index_hash | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 1 addition & 13 deletions
14
lib/rspec_api_documentation/writers/general_markup_writer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module RspecApiDocumentation | ||
module Writers | ||
class Writer | ||
attr_accessor :index, :configuration | ||
|
||
def initialize(index, configuration) | ||
self.index = index | ||
self.configuration = configuration | ||
end | ||
|
||
def self.write(index, configuration) | ||
writer = new(index, configuration) | ||
writer.write | ||
end | ||
|
||
def self.clear_docs(docs_dir) | ||
if File.exists?(docs_dir) | ||
FileUtils.rm_rf(docs_dir, :secure => true) | ||
end | ||
FileUtils.mkdir_p(docs_dir) | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters