Skip to content

Commit 4a4b28d

Browse files
committed
chore(docs): use GAE and Google CDN for docs
Short summary: if you use local node server everything should work as before, if you use GAE, everything should work now as well, but we pull assets from CDN. - GAE doesn't support ':' in filenames, so I had to replace it with '_' but only in the filename, all servers were reconfigured to rewrite the urls from : to _ when doing file lookup - We now pull angular assets from google CDN when deployed on GAE (locally or in production). When running on a non GAE server we pull assets from ../ directory as before - Since only certain versions of Angular are available on CDN and we want to be able to autodeploy docs, I had to pin down the Angular files to a "stable" version when running on GAE
1 parent 3e12bc4 commit 4a4b28d

9 files changed

Lines changed: 157 additions & 6 deletions

File tree

Rakefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ task :init do
1919
v = YAML::load( File.open( 'version.yaml' ) )
2020
match = v['version'].match(/^([^-]*)(-snapshot)?$/)
2121

22-
NG_VERSION = Struct.new(:full, :major, :minor, :dot, :codename).
22+
NG_VERSION = Struct.new(:full, :major, :minor, :dot, :codename, :stable).
2323
new(match[1] + (match[2] ? ('-' + %x(git rev-parse HEAD)[0..7]) : ''),
2424
match[1].split('.')[0],
2525
match[1].split('.')[1],
2626
match[1].split('.')[2].sub(/\D+.*$/, ''),
27-
v['codename'])
27+
v['codename'],
28+
v['stable'])
2829
end
2930

3031

@@ -115,6 +116,14 @@ task :docs => [:init] do
115116
rewrite_file(path_to('docs/.htaccess')) do |content|
116117
content.sub!('"NG_VERSION_FULL"', NG_VERSION.full)
117118
end
119+
rewrite_file(path_to('docs/index.html')) do |content|
120+
content.sub!('"NG_VERSION_FULL"', NG_VERSION.full).
121+
sub!('"NG_VERSION_STABLE"', NG_VERSION.stable)
122+
end
123+
rewrite_file(path_to('docs/docs-scenario.html')) do |content|
124+
content.sub!('"NG_VERSION_FULL"', NG_VERSION.full).
125+
sub!('"NG_VERSION_STABLE"', NG_VERSION.stable)
126+
end
118127
end
119128

120129

docs/src/gen-docs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ writer.makeDir('build/docs/syntaxhighlighter').then(function() {
2121
var fileFutures = [];
2222
docs.forEach(function(doc){
2323
// this hack is here because on OSX angular.module and angular.Module map to the same file.
24-
var id = doc.id.replace('angular.Module', 'angular.IModule');
24+
var id = doc.id.replace('angular.Module', 'angular.IModule').
25+
replace(':', '_'); // rewrite : to _ to be GAE-friendly
2526
fileFutures.push(writer.output('partials/' + doc.section + '/' + id + '.html', doc.html()));
2627
});
2728

@@ -89,6 +90,10 @@ function writeTheRest(writesFuture) {
8990
writesFuture.push(writer.copyTpl('font/fontawesome-webfont.svgz'));
9091
writesFuture.push(writer.copyTpl('font/fontawesome-webfont.ttf'));
9192
writesFuture.push(writer.copyTpl('font/fontawesome-webfont.woff'));
93+
94+
writesFuture.push(writer.copyTpl('app.yaml'));
95+
writesFuture.push(writer.copyTpl('index.yaml'));
96+
writesFuture.push(writer.copyTpl('favicon.ico'));
9297
}
9398

9499

docs/src/templates/app.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
application: docs-angularjs-org
2+
version: 1
3+
runtime: python27
4+
api_version: 1
5+
threadsafe: yes
6+
default_expiration: "2h"
7+
8+
handlers:
9+
- url: /
10+
static_files: index.html
11+
upload: index.html
12+
13+
- url: /appcache.manifest
14+
static_files: appcache.manifest
15+
upload: appcache\.manifest
16+
17+
- url: /docs-scenario.html
18+
static_files: docs-scenario.html
19+
upload: docs-scenario\.html
20+
21+
- url: /docs-scenario.js
22+
static_files: docs-scenario.js
23+
upload: docs-scenario\.js
24+
25+
- url: /favicon\.ico
26+
static_files: favicon.ico
27+
upload: favicon\.ico
28+
29+
- url: /robots.txt
30+
static_files: robots.txt
31+
upload: robots\.txt
32+
33+
- url: /sitemap.xml
34+
static_files: sitemap.xml
35+
upload: sitemap\.xml
36+
37+
- url: /css
38+
static_dir: css
39+
40+
- url: /font
41+
static_dir: font
42+
43+
- url: /img
44+
static_dir: img
45+
46+
- url: /js
47+
static_dir: js
48+
49+
- url: /partials/(.+):(.+)
50+
static_files: partials/\1_\2
51+
upload: partials/.*
52+
53+
- url: /partials
54+
static_dir: partials
55+
56+
- url: /syntaxhighlighter
57+
static_dir: syntaxhighlighter
58+
59+
- url: /.*
60+
static_files: index.html
61+
upload: index.html
62+
63+
64+
libraries:
65+
- name: webapp2
66+
version: "2.5.1"

docs/src/templates/docs-scenario.html

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,43 @@
22
<html xmlns:ng="http://angularjs.org">
33
<head>
44
<title>AngularJS Docs E2E Test Runner</title>
5-
<script type="text/javascript" src="../angular-scenario.js" ng:autotest></script>
6-
<script type="text/javascript" src="docs-scenario.js"></script>
5+
<script>
6+
var gae = (location.pathname.split('/').length == 2),
7+
headEl = document.head,
8+
angularVersion = {
9+
current: '"NG_VERSION_FULL"', // rewrite during build
10+
stable: '"NG_VERSION_STABLE"'
11+
};
12+
13+
addTag('script', {src: path('angular-scenario.js')}, function() {
14+
addTag('script', {src: 'docs-scenario.js'}, function() {
15+
angular.scenario.setUpAndRun();
16+
});
17+
});
18+
19+
function addTag(name, attributes, callback) {
20+
var el = document.createElement(name),
21+
attrName;
22+
23+
for (attrName in attributes) {
24+
el.setAttribute(attrName, attributes[attrName]);
25+
}
26+
27+
if (callback) {
28+
el.onload = callback;
29+
}
30+
31+
headEl.appendChild(el);
32+
}
33+
34+
35+
function path(name) {
36+
return gae
37+
? 'http://code.angularjs.org/' + angularVersion.stable + '/' +
38+
name.replace(/\.js$/, '-' + angularVersion.stable + '.js')
39+
: '../' + name;
40+
}
41+
</script>
742
</head>
843
<body>
944
</body>

docs/src/templates/favicon.ico

1.12 KB
Binary file not shown.

docs/src/templates/index.html

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
baseUrl = location.href.replace(rUrl, indexFile),
2323
jQuery = /index-jq[^\.]*\.html$/.test(baseUrl),
2424
debug = /index[^\.]*-debug\.html$/.test(baseUrl),
25+
gae = (baseUrl.split('/').length == 4),
2526
headEl = document.getElementsByTagName('head')[0],
26-
sync = true;
27+
sync = true,
28+
angularVersion = {
29+
current: '"NG_VERSION_FULL"', // rewrite during build
30+
stable: '"NG_VERSION_STABLE"'
31+
};
2732

2833
addTag('base', {href: baseUrl});
2934
addTag('link', {rel: 'stylesheet', href: 'css/bootstrap.min.css', type: 'text/css'});
@@ -40,6 +45,20 @@
4045
addTag('script', {src: 'js/docs-keywords.js'}, sync);
4146

4247
function path(name) {
48+
if (gae) {
49+
if (name.match(/^angular(-\w+)?\.js/) && !name.match(/bootstrap/)) {
50+
name = '//ajax.googleapis.com/ajax/libs/angularjs/' +
51+
angularVersion.stable +
52+
'/' +
53+
name.replace(/\.js$/, '.min.js');
54+
} else {
55+
name = 'http://code.angularjs.org/' +
56+
angularVersion.stable +
57+
'/' +
58+
name.replace(/\.js$/, '-' + angularVersion.stable +'.min.js');
59+
}
60+
return name;
61+
}
4362
return '../' + name.replace(/\.js$/, debug ? '.js' : '.min.js');
4463
}
4564

docs/src/templates/index.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
indexes:
2+
3+
# AUTOGENERATED
4+
5+
# This index.yaml is automatically updated whenever the dev_appserver
6+
# detects that a new type of query is run. If you want to manage the
7+
# index.yaml file manually, remove the above marker line (the line
8+
# saying "# AUTOGENERATED"). If you want to manage some indexes
9+
# manually, move them above the marker line. The index.yaml file is
10+
# automatically uploaded to the admin console when you next deploy
11+
# your application using appcfg.py.
12+

lib/nodeserver/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ StaticServlet.prototype.handleRequest = function(req, res) {
108108
path = path.replace(match[0], '/index.html');
109109
sys.puts('Rewrite to ' + path);
110110
}
111+
112+
// rewrite : to _ to be GAE-friendly
113+
path = path.replace(':', '_');
114+
111115
// end of docs rewriting
112116

113117
fs.stat(path, function(err, stat) {

version.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
---
33
version: 1.1.0-snapshot
44
codename: increase-gravatas
5+
stable: 1.0.1

0 commit comments

Comments
 (0)