From 9dea9de44917b0b72a786122e619d451ccb8b0dc Mon Sep 17 00:00:00 2001
From: Di Peng
Date: Wed, 20 Jul 2011 19:29:54 -0700
Subject: feat(docs): add full offline support
---
Rakefile | 17 ++++++++-
docs/src/appCache.js | 13 +++----
docs/src/gen-docs.js | 1 +
docs/src/templates/.htaccess | 64 +++++-----------------------------
docs/src/templates/docs.css | 81 +++++++++++++++++++++++++++++++++++++++++++
docs/src/templates/docs.js | 35 +++++++++++++++----
docs/src/templates/index.html | 20 +++++++++++
7 files changed, 163 insertions(+), 68 deletions(-)
diff --git a/Rakefile b/Rakefile
index aff1995f..5c953831 100644
--- a/Rakefile
+++ b/Rakefile
@@ -221,8 +221,14 @@ end
desc 'Generate docs'
-task :docs do
+task :docs => [:init] do
`node docs/src/gen-docs.js`
+ File.open(path_to('docs/.htaccess'), File::RDWR) do |f|
+ text = f.read
+ f.truncate 0
+ f.rewind
+ f.write text.sub('"NG_VERSION_FULL"', NG_VERSION.full)
+ end
end
@@ -250,19 +256,28 @@ task :package => [:clean, :compile, :docs] do
File.open("#{pkg_dir}/docs-#{NG_VERSION.full}/index.html", File::RDWR) do |f|
text = f.read
+ f.truncate 0
f.rewind
f.write text.sub('angular.min.js', "angular-#{NG_VERSION.full}.min.js")
end
File.open("#{pkg_dir}/docs-#{NG_VERSION.full}/docs-scenario.html", File::RDWR) do |f|
text = f.read
+ f.truncate 0
f.rewind
f.write text.sub('angular-scenario.js', "angular-scenario-#{NG_VERSION.full}.js")
end
File.open("#{pkg_dir}/docs-#{NG_VERSION.full}/appcache.manifest", File::RDWR) do |f|
+ text = f.read
+ f.truncate 0
+ f.rewind
+ f.write text.sub('angular.min.js', "angular-#{NG_VERSION.full}.min.js")
+ end
+ File.open("#{pkg_dir}/docs-#{NG_VERSION.full}/appcache-offline.manifest", File::RDWR) do |f|
text = f.read
+ f.truncate 0
f.rewind
f.write text.sub('angular.min.js', "angular-#{NG_VERSION.full}.min.js")
end
diff --git a/docs/src/appCache.js b/docs/src/appCache.js
index cf7827bf..ed35eb79 100644
--- a/docs/src/appCache.js
+++ b/docs/src/appCache.js
@@ -11,12 +11,13 @@ function appCache(path) {
if(!path) {
return appCacheTemplate();
}
- var blackList = ["offline.html",
- "sitemap.xml",
- "robots.txt",
- "docs-scenario.html",
- "docs-scenario.js",
- "appcache.manifest"
+ var blackList = ["build/docs/offline.html",
+ "build/docs/sitemap.xml",
+ "build/docs/robots.txt",
+ "build/docs/docs-scenario.html",
+ "build/docs/docs-scenario.js",
+ "build/docs/appcache.manifest",
+ "build/docs/.htaccess"
];
var result = ["CACHE MANIFEST",
diff --git a/docs/src/gen-docs.js b/docs/src/gen-docs.js
index 2cbc9267..4649bec3 100755
--- a/docs/src/gen-docs.js
+++ b/docs/src/gen-docs.js
@@ -57,6 +57,7 @@ function writeTheRest(writesFuture) {
writesFuture.push(writer.output('docs-scenario.js', ngdoc.scenarios(docs)));
writesFuture.push(writer.output('robots.txt', 'Sitemap: http://docs.angularjs.org/sitemap.xml\n'));
writesFuture.push(writer.output('appcache.manifest',appCache()));
+ writesFuture.push(writer.copyTpl('.htaccess'));
writesFuture.push(writer.merge(['docs.js',
'doc_widgets.js'],
diff --git a/docs/src/templates/.htaccess b/docs/src/templates/.htaccess
index 929e04b2..87487e9e 100644
--- a/docs/src/templates/.htaccess
+++ b/docs/src/templates/.htaccess
@@ -1,57 +1,11 @@
-Options +Indexes
-IndexIgnore favicon.ico
-RewriteEngine on
-
-# Enable Crawling of AJAX apps.
-# See: http://code.google.com/web/ajaxcrawling/docs/getting-started.html
-RewriteCond %{QUERY_STRING} ^_escaped_fragment_=\/(.*)$
-RewriteRule ^(.*)$ /$1/%1.html?
-
-# Map versiond angular files to root folder.
-RewriteRule ^angular([\-\w]+)(\d+\.\d+\.\d+)(.*)$ /$2/angular$1$2$3
-# Map 1.2.3/docs to 1.2.3/docs-1.2.3/ so that we don't need the version in the URL twice
-RewriteRule ^(\d+\.\d+\.\d+)/docs/(.*)$ /$1/docs-$1/$2
-
-# If the user has forgot the trailing slash than add it through redirect
-RewriteRule ^latest$ /latest/ [R]
-RewriteRule ^latest/docs$ /latest/docs/ [R]
-
-# To change the latest version just change this line.
-# IMPORTANT: the order of lines matters, do not move to top!
-RewriteRule ^latest/(.*)$ /0.9.17/$1
-
-# If the request comes on http://docs.angularjs.org then point it to latest/docs
-RewriteCond %{HTTP_HOST} ^docs\.angularjs\.org$
-RewriteCond %{REQUEST_URI} !^/\d+\.\d+\.\d+
-RewriteCond %{REQUEST_URI} !^/latest
-RewriteCond %{REQUEST_URI} !^/angular-
-RewriteCond %{REQUEST_URI} !^/favicon.ico
-RewriteRule ^(.*)$ /latest/docs/$1
-
-## PERFORMANCE ##
-
-ExpiresActive On
+## OFFLINE SUPPORT ##
-# cache js files for one year
-
+ If you want to be able to access the entire AngularJS documentation offline, click the
+ button below. This will reload the current page and trigger background downloads of all the
+ necessary files (approximately 3.5MB). The next time you load the docs, the browser will
+ use these cached files.
+
+ This feature is supported on all modern browsers, except for IE9 which lacks application
+ cache support.
+