From 977e991ff16f89468650a3d19ba12590ddffbba1 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sun, 1 Feb 2015 17:19:28 -0500 Subject: [PATCH] Include default docs in appcache manifest --- assets/javascripts/app/config.coffee.erb | 2 +- lib/app.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/app/config.coffee.erb b/assets/javascripts/app/config.coffee.erb index 6621d16f..e018b348 100644 --- a/assets/javascripts/app/config.coffee.erb +++ b/assets/javascripts/app/config.coffee.erb @@ -1,5 +1,5 @@ app.config = - default_docs: ['css', 'dom', 'dom_events', 'html', 'http', 'javascript'] + default_docs: <%= App.default_docs.to_json %> docs_host: '<%= App.docs_host %>' env: '<%= App.environment %>' history_cache_size: 10 diff --git a/lib/app.rb b/lib/app.rb index 05e10389..8204c95d 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -25,6 +25,7 @@ class App < Sinatra::Application set :docs_path, -> { File.join(public_folder, docs_prefix) } set :docs_manifest_path, -> { File.join(docs_path, 'docs.json') } set :docs, -> { Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc| [doc['slug'], doc] }] } + set :default_docs, %w(css dom dom_events html http javascript) set :news_path, -> { File.join(root, assets_prefix, 'javascripts', 'news.json') } set :news, -> { JSON.parse(File.read(news_path)) } @@ -94,9 +95,14 @@ class App < Sinatra::Application def doc_index_urls cookie = cookies[:docs] - return [] if cookie.nil? || cookie.empty? - cookie.split('/').inject [] do |result, slug| + docs = if cookie.nil? || cookie.empty? + settings.default_docs + else + cookie.split('/') + end + + docs.inject [] do |result, slug| if doc = settings.docs[slug] result << File.join('', settings.docs_prefix, doc['index_path']) + "?#{doc['mtime']}" end