Unified · Split
| @@ -1,8 +1,10 @@ | |||
| 1 | app.config = | 1 | app.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: 10 | 6 | history_cache_size: 10 |
| 7 | index_filename: 'index.json' | ||
| 6 | index_path: '/<%= App.docs_prefix %>' | 8 | index_path: '/<%= App.docs_prefix %>' |
| 7 | max_results: 50 | 9 | max_results: 50 |
| 8 | production_host: 'devdocs.io' | 10 | production_host: 'devdocs.io' |
| @@ -1,5 +1,5 @@ | |||
| 1 | class app.models.Doc extends app.Model | 1 | class app.models.Doc extends app.Model |
| 2 | # Attributes: name, slug, type, release, index_path, db_path, db_size, mtime, links | 2 | # Attributes: name, slug, type, release, db_size, mtime, links |
| 3 | 3 | ||
| 4 | constructor: -> | 4 | constructor: -> |
| 5 | super | 5 | 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.Entry | 38 | @entry ||= new app.models.Entry |
| @@ -118,7 +118,7 @@ class App < Sinatra::Application · 117 unmodified lines | |||
| 118 | def doc_index_urls | 118 | 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 | end | 122 | end |
| 123 | end | 123 | end |
| 124 | end | 124 | end |
| @@ -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 | end | 41 | end |
| 44 | 42 | ||
| @@ -14,9 +14,11 @@ module Docs · 13 unmodified lines | |||
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | def as_json | 16 | 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 | end | 22 | end |
| 21 | end | 23 | end |
| 22 | 24 | ||
| @@ -33,11 +35,11 @@ module Docs · 10 unmodified lines | |||
| 33 | end | 35 | 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].max | 38 | [@store.mtime(doc.index_path).to_i, @store.mtime(doc.db_path).to_i].max |
| 37 | end | 39 | 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 | end | 43 | end |
| 42 | end | 44 | end |
| 43 | end | 45 | end |
| @@ -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}] |
| @@ -115,8 +115,8 @@ class DocsDocTest < MiniTest::Spec · 114 unmodified lines | |||
| 115 | assert_instance_of Hash, doc.as_json | 115 | assert_instance_of Hash, doc.as_json |
| 116 | end | 116 | end |
| 117 | 117 | ||
| 118 | it "includes the doc's name, slug, type, release, index_path and db_path" do | 118 | 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 | end | 122 | end |