manifest.rb 705 B

123456789101112131415161718192021222324252627282930313233
  1. require 'yajl/json_gem'
  2. module Docs
  3. class Manifest
  4. FILENAME = 'docs.json'
  5. def initialize(store, docs, aliases)
  6. @store = store
  7. @docs = docs
  8. @aliases = aliases
  9. end
  10. def store
  11. @store.write FILENAME, to_json
  12. end
  13. def as_json
  14. @docs.each_with_object [] do |doc, result|
  15. next unless @store.exist?(doc.meta_path)
  16. json = JSON.parse(@store.read(doc.meta_path))
  17. if doc.options[:attribution].is_a?(String)
  18. json[:attribution] = doc.options[:attribution].strip
  19. end
  20. json[:alias] = @aliases[doc.slug]
  21. result << json
  22. end
  23. end
  24. def to_json
  25. JSON.pretty_generate(as_json)
  26. end
  27. end
  28. end