From a639aedcd9bbe55dc83087e09ea841c6d353f503 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 17 Jan 2016 09:32:52 -0500 Subject: [PATCH] Remove index_path and db_path from docs manifest --- assets/javascripts/app/config.coffee.erb | 2 ++ assets/javascripts/models/doc.coffee | 6 +++--- lib/app.rb | 2 +- lib/docs/core/doc.rb | 2 -- lib/docs/core/manifest.rb | 12 +++++++----- test/files/docs.json | 2 +- test/lib/docs/core/doc_test.rb | 4 ++-- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/assets/javascripts/app/config.coffee.erb b/assets/javascripts/app/config.coffee.erb index e018b348..10883904 100644 --- a/assets/javascripts/app/config.coffee.erb +++ b/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' diff --git a/assets/javascripts/models/doc.coffee b/assets/javascripts/models/doc.coffee index 5f2adea1..c805d3a2 100644 --- a/assets/javascripts/models/doc.coffee +++ b/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 diff --git a/lib/app.rb b/lib/app.rb index 817cb644..a618a243 100644 --- a/lib/app.rb +++ b/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 diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index 25822bc6..2e7871bb 100644 --- a/lib/docs/core/doc.rb +++ b/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 diff --git a/lib/docs/core/manifest.rb b/lib/docs/core/manifest.rb index 5a00a102..8680ab5d 100644 --- a/lib/docs/core/manifest.rb +++ b/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 diff --git a/test/files/docs.json b/test/files/docs.json index 37a4147a..c010fc0b 100644 --- a/test/files/docs.json +++ b/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}] \ No newline at end of file +[{"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}] diff --git a/test/lib/docs/core/doc_test.rb b/test/lib/docs/core/doc_test.rb index 34bea691..7eeed6de 100644 --- a/test/lib/docs/core/doc_test.rb +++ b/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