Browse Source

Remove index_path and db_path from docs manifest

Thibaut Courouble 10 years ago
parent
commit
a639aedcd9

+ 2 - 0
assets/javascripts/app/config.coffee.erb

@@ -1,8 +1,10 @@
 app.config =
+  db_filename: 'db.json'
   default_docs: <%= App.default_docs.to_json %>
   docs_host: '<%= App.docs_host %>'
   env: '<%= App.environment %>'
   history_cache_size: 10
+  index_filename: 'index.json'
   index_path: '/<%= App.docs_prefix %>'
   max_results: 50
   production_host: 'devdocs.io'

+ 3 - 3
assets/javascripts/models/doc.coffee

@@ -1,5 +1,5 @@
 class app.models.Doc extends app.Model
-  # Attributes: name, slug, type, release, index_path, db_path, db_size, mtime, links
+  # Attributes: name, slug, type, release, db_size, mtime, links
 
   constructor: ->
     super
@@ -29,10 +29,10 @@ class app.models.Doc extends app.Model
     "#{app.config.docs_host}#{@fullPath(path)}?#{@mtime}"
 
   dbUrl: ->
-    "#{app.config.docs_host}/#{@db_path}?#{@mtime}"
+    "#{app.config.docs_host}/#{@slug}/#{app.config.db_filename}?#{@mtime}"
 
   indexUrl: ->
-    "#{app.indexHost()}/#{@index_path}?#{@mtime}"
+    "#{app.indexHost()}/#{@slug}/#{app.config.index_filename}?#{@mtime}"
 
   toEntry: ->
     @entry ||= new app.models.Entry

+ 1 - 1
lib/app.rb

@@ -118,7 +118,7 @@ class App < Sinatra::Application
     def doc_index_urls
       docs.each_with_object [] do |slug, result|
         if doc = settings.docs[slug]
-          result << File.join('', settings.docs_prefix, doc['index_path']) + "?#{doc['mtime']}"
+          result << File.join('', settings.docs_prefix, slug, 'index.json') + "?#{doc['mtime']}"
         end
       end
     end

+ 0 - 2
lib/docs/core/doc.rb

@@ -37,8 +37,6 @@ module Docs
           slug: slug,
           type: type,
           release: release,
-          index_path: index_path,
-          db_path: db_path,
           links: links }
       end
 

+ 7 - 5
lib/docs/core/manifest.rb

@@ -14,9 +14,11 @@ module Docs
     end
 
     def as_json
-      indexed_docs.map(&:as_json).each do |json|
-        json[:mtime] = doc_mtime(json)
-        json[:db_size] = doc_db_size(json)
+      indexed_docs.map do |doc|
+        json = doc.as_json
+        json[:mtime] = doc_mtime(doc)
+        json[:db_size] = doc_db_size(doc)
+        json
       end
     end
 
@@ -33,11 +35,11 @@ module Docs
     end
 
     def doc_mtime(doc)
-      [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max
+      [@store.mtime(doc.index_path).to_i, @store.mtime(doc.db_path).to_i].max
     end
 
     def doc_db_size(doc)
-      @store.size(doc[:db_path])
+      @store.size(doc.db_path)
     end
   end
 end

+ 1 - 1
test/files/docs.json

@@ -1 +1 @@
-[{"name":"CSS","slug":"css","type":"mdn","version":null,"index_path":"css/index.json","db_path":"css/db.json","mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","version":null,"index_path":"dom/index.json","db_path":"dom/db.json","mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","version":null,"index_path":"dom_events/index.json","db_path":"dom_events/db.json","mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html","type":"mdn","version":null,"index_path":"html/index.json","db_path":"html/db.json","mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","version":null,"index_path":"http/index.json","db_path":"http/db.json","mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","version":null,"index_path":"javascript/index.json","db_path":"javascript/db.json","mtime":1420139791,"db_size":4125477}]
+[{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html","type":"mdn","release":null,"mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477}]

+ 2 - 2
test/lib/docs/core/doc_test.rb

@@ -115,8 +115,8 @@ class DocsDocTest < MiniTest::Spec
       assert_instance_of Hash, doc.as_json
     end
 
-    it "includes the doc's name, slug, type, release, index_path and db_path" do
-      %w(name slug type release index_path db_path links).each do |attribute|
+    it "includes the doc's name, slug, type, and release" do
+      %w(name slug type release links).each do |attribute|
         eval "stub(doc).#{attribute} { attribute }"
         assert_equal attribute, doc.as_json[attribute.to_sym]
       end