manifest.rb 688 B

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