From 25b3438fd78184cbbc420e2e051888f4f192a68a Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 7 Jun 2011 12:53:40 -0700 Subject: add appcache for docs site - caches only css/js/img resources --- Rakefile | 7 +++++++ docs/src/gen-docs.js | 29 +++++++++++++++++++++++++++++ docs/src/templates/index.html | 11 ++++++++++- docs/src/templates/offline.html | 4 ++++ lib/nodeserver/server.js | 3 ++- 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 docs/src/templates/offline.html diff --git a/Rakefile b/Rakefile index 31307c4f..c8ba1418 100644 --- a/Rakefile +++ b/Rakefile @@ -241,6 +241,13 @@ task :package => [:clean, :compile, :docs] do f.write text.sub('angular-scenario.js', "angular-scenario-#{version}.js") end + File.open("#{pkg_dir}/docs-#{version}/app-cache.manifest", File::RDWR) do |f| + text = f.read + f.rewind + f.write text.sub('angular.min.js', "angular-#{version}.min.js") + end + + %x(tar -czf #{path_to(tarball)} -C #{path_to('pkg')} .) puts "Package created: #{path_to(tarball)}" diff --git a/docs/src/gen-docs.js b/docs/src/gen-docs.js index 1e5a09c4..ead01c32 100644 --- a/docs/src/gen-docs.js +++ b/docs/src/gen-docs.js @@ -27,6 +27,10 @@ var writes = callback.chain(function(){ writer.copyDir('img', writes.waitFor()); writer.copyDir('examples', writes.waitFor()); writer.copyTpl('index.html', writes.waitFor()); + writer.copyTpl('offline.html', writes.waitFor()); + writer.output('app-cache.manifest', + appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()), + writes.waitFor()); writer.merge(['docs.js', 'doc_widgets.js'], 'docs-combined.js', @@ -59,3 +63,28 @@ writer.makeDir('build/docs/syntaxhighlighter', work); /////////////////////////////////// function now(){ return new Date().getTime(); } + + +function appCacheTemplate() { + return ["CACHE MANIFEST", + "# %TIMESTAMP%", + "", + "# cache all of these", + "CACHE:", + "jquery.min.js", + "syntaxhighlighter/syntaxhighlighter-combined.js", + "../angular.min.js", + "docs-combined.js", + "docs-keywords.js", + "docs-combined.css", + "syntaxhighlighter/syntaxhighlighter-combined.css", + "img/texture_1.png", + "img/yellow_bkgnd.jpg", + "", + "FALLBACK:", + "/ offline.html", + "", + "# allow access to google analytics and twitter when we are online", + "NETWORK:", + "*"].join('\n'); +} diff --git a/docs/src/templates/index.html b/docs/src/templates/index.html index 9e0c64ba..cdd04e1d 100644 --- a/docs/src/templates/index.html +++ b/docs/src/templates/index.html @@ -1,7 +1,8 @@ + ng:controller="DocsController" + manifest="app-cache.manifest">
This page if unavailable because your are offline.
+Please connect to the Internet and reload the page.
diff --git a/lib/nodeserver/server.js b/lib/nodeserver/server.js index d72bf02f..471bba94 100644 --- a/lib/nodeserver/server.js +++ b/lib/nodeserver/server.js @@ -79,7 +79,8 @@ StaticServlet.MimeMap = { 'jpg': 'image/jpeg', 'jpeg': 'image/jpeg', 'gif': 'image/gif', - 'png': 'image/png' + 'png': 'image/png', + 'manifest': 'text/cache-manifest' }; StaticServlet.prototype.handleRequest = function(req, res) { -- cgit v1.2.3