History

Remove index_path and db_path from docs manifest

Thibaut Courouble committed 10 years ago

Commit a639aed1 parent e1c02187 files · +16 −14Browse files

Unified · Split

7 files
  1. assets/javascripts/app/config.coffee.erb +2 −0
  2. assets/javascripts/models/doc.coffee +3 −3
  3. lib/app.rb +1 −1
  4. lib/docs/core/doc.rb +0 −2
  5. lib/docs/core/manifest.rb +7 −5
  6. test/files/docs.json +1 −1
  7. test/lib/docs/core/doc_test.rb +2 −2
assets/javascripts/app/config.coffee.erb+2−0
@@ -1,8 +1,10 @@
1app.config =1app.config =
2 db_filename: 'db.json'
2 default_docs: <%= App.default_docs.to_json %>3 default_docs: <%= App.default_docs.to_json %>
3 docs_host: '<%= App.docs_host %>'4 docs_host: '<%= App.docs_host %>'
4 env: '<%= App.environment %>'5 env: '<%= App.environment %>'
5 history_cache_size: 106 history_cache_size: 10
7 index_filename: 'index.json'
6 index_path: '/<%= App.docs_prefix %>'8 index_path: '/<%= App.docs_prefix %>'
7 max_results: 509 max_results: 50
8 production_host: 'devdocs.io'10 production_host: 'devdocs.io'
assets/javascripts/models/doc.coffee+3−3
@@ -1,5 +1,5 @@
1class app.models.Doc extends app.Model1class app.models.Doc extends app.Model
2 # Attributes: name, slug, type, release, index_path, db_path, db_size, mtime, links2 # Attributes: name, slug, type, release, db_size, mtime, links
3 3
4 constructor: ->4 constructor: ->
5 super5 super
@@ -29,10 +29,10 @@ class app.models.Doc extends app.Model · 23 unmodified lines
29 "#{app.config.docs_host}#{@fullPath(path)}?#{@mtime}"29 "#{app.config.docs_host}#{@fullPath(path)}?#{@mtime}"
30 30
31 dbUrl: ->31 dbUrl: ->
32 "#{app.config.docs_host}/#{@db_path}?#{@mtime}"32 "#{app.config.docs_host}/#{@slug}/#{app.config.db_filename}?#{@mtime}"
33 33
34 indexUrl: ->34 indexUrl: ->
35 "#{app.indexHost()}/#{@index_path}?#{@mtime}"35 "#{app.indexHost()}/#{@slug}/#{app.config.index_filename}?#{@mtime}"
36 36
37 toEntry: ->37 toEntry: ->
38 @entry ||= new app.models.Entry38 @entry ||= new app.models.Entry
lib/app.rb+1−1
@@ -118,7 +118,7 @@ class App < Sinatra::Application · 117 unmodified lines
118 def doc_index_urls118 def doc_index_urls
119 docs.each_with_object [] do |slug, result|119 docs.each_with_object [] do |slug, result|
120 if doc = settings.docs[slug]120 if doc = settings.docs[slug]
121 result << File.join('', settings.docs_prefix, doc['index_path']) + "?#{doc['mtime']}"121 result << File.join('', settings.docs_prefix, slug, 'index.json') + "?#{doc['mtime']}"
122 end122 end
123 end123 end
124 end124 end
lib/docs/core/doc.rb+0−2
@@ -37,8 +37,6 @@ module Docs · 36 unmodified lines
37 slug: slug,37 slug: slug,
38 type: type,38 type: type,
39 release: release,39 release: release,
40 index_path: index_path,
41 db_path: db_path,
42 links: links }40 links: links }
43 end41 end
44 42
lib/docs/core/manifest.rb+7−5
@@ -14,9 +14,11 @@ module Docs · 13 unmodified lines
14 end14 end
15 15
16 def as_json16 def as_json
17 indexed_docs.map(&:as_json).each do |json|17 indexed_docs.map do |doc|
18 json[:mtime] = doc_mtime(json)18 json = doc.as_json
19 json[:db_size] = doc_db_size(json)19 json[:mtime] = doc_mtime(doc)
20 json[:db_size] = doc_db_size(doc)
21 json
20 end22 end
21 end23 end
22 24
@@ -33,11 +35,11 @@ module Docs · 10 unmodified lines
33 end35 end
34 36
35 def doc_mtime(doc)37 def doc_mtime(doc)
36 [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max38 [@store.mtime(doc.index_path).to_i, @store.mtime(doc.db_path).to_i].max
37 end39 end
38 40
39 def doc_db_size(doc)41 def doc_db_size(doc)
40 @store.size(doc[:db_path])42 @store.size(doc.db_path)
41 end43 end
42 end44 end
43end45end
test/files/docs.json+1−1
@@ -1 +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}]1[{"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}]
test/lib/docs/core/doc_test.rb+2−2
@@ -115,8 +115,8 @@ class DocsDocTest < MiniTest::Spec · 114 unmodified lines
115 assert_instance_of Hash, doc.as_json115 assert_instance_of Hash, doc.as_json
116 end116 end
117 117
118 it "includes the doc's name, slug, type, release, index_path and db_path" do118 it "includes the doc's name, slug, type, and release" do
119 %w(name slug type release index_path db_path links).each do |attribute|119 %w(name slug type release links).each do |attribute|
120 eval "stub(doc).#{attribute} { attribute }"120 eval "stub(doc).#{attribute} { attribute }"
121 assert_equal attribute, doc.as_json[attribute.to_sym]121 assert_equal attribute, doc.as_json[attribute.to_sym]
122 end122 end