aboutsummaryrefslogtreecommitdiffstats
path: root/docs/src/gen-docs.js
blob: 1ca40c60ef1b25e6bbb195886e091911e4650d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var reader = require('./reader.js'),
    ngdoc = require('./ngdoc.js'),
    writer = require('./writer.js'),
    SiteMap = require('./SiteMap.js').SiteMap,
    appCache = require('./appCache.js').appCache,
    Q = require('qq');

process.on('uncaughtException', function(err) {
  console.error(err.stack || err);
});

var start = now();
var docs;

writer.makeDir('build/docs/syntaxhighlighter').then(function() {
  console.log('Generating Angular Reference Documentation...');
  return reader.collect();
}).then(function generateHtmlDocPartials(docs_) {
  docs = docs_;
  ngdoc.merge(docs);
  var fileFutures = [];
  docs.forEach(function(doc){
    fileFutures.push(writer.output('partials/' + doc.section + '/' + doc.id + '.html', doc.html()));
  });

  writeTheRest(fileFutures);

  return Q.deep(fileFutures);
}).then(function generateManifestFile() {
  return appCache('build/docs/').then(function(list) {
    writer.output('appcache-offline.manifest', list);
  });
}).then(function printStats() {
  console.log('DONE. Generated ' + docs.length + ' pages in ' + (now()-start) + 'ms.' );
}).end();


function writeTheRest(writesFuture) {
  var metadata = ngdoc.metadata(docs);

  writesFuture.push(writer.copyDir('img'));
  writesFuture.push(writer.copyDir('examples'));

  var manifest = 'manifest="/build/docs/appcache.manifest"';

  writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index.html',
                                writer.replace, {'doc:manifest': manifest}));

  writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-nocache.html',
                                writer.replace, {'doc:manifest': ''}));


  writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html',
                                writer.replace, {'doc:manifest': manifest}));

  writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-jq-nocache.html',
                                writer.replace, {'doc:manifest': ''}));


  writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-debug.html',
                                writer.replace, {'doc:manifest': ''}));

  writesFuture.push(writer.copy('docs/src/templates/index.html', 'build/docs/index-jq-debug.html',
                                writer.replace, {'doc:manifest': ''}));

  writesFuture.push(writer.copyTpl('offline.html'));
  writesFuture.push(writer.copyTpl('docs-scenario.html'));
  writesFuture.push(writer.copyTpl('jquery.min.js'));

  writesFuture.push(writer.output('docs-keywords.js',
                                ['NG_PAGES=', JSON.stringify(metadata).replace(/{/g, '\n{'), ';']));
  writesFuture.push(writer.output('sitemap.xml', new SiteMap(docs).render()));
  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'],
                                  'docs-combined.js'));
  writesFuture.push(writer.merge(['docs.css',
                                  'doc_widgets.css'],
                                  'docs-combined.css'));
  writesFuture.push(writer.merge(['syntaxhighlighter/shCore.js',
                                  'syntaxhighlighter/shBrushJScript.js',
                                  'syntaxhighlighter/shBrushXml.js'],
                                  'syntaxhighlighter/syntaxhighlighter-combined.js'));
  writesFuture.push(writer.merge(['syntaxhighlighter/shCore.css',
                                  'syntaxhighlighter/shThemeDefault.css'],
                                  'syntaxhighlighter/syntaxhighlighter-combined.css'));
}


function now() { return new Date().getTime(); }

function noop() {};
class="p">({name:'misko', age:1}, {name:'misko'})).toEqual(false); expect(equals({name:'misko'}, {name:'misko', age:1})).toEqual(false); expect(equals({name:'misko'}, {name:'adam'})).toEqual(false); expect(equals(['misko'], ['misko'])).toEqual(true); expect(equals(['misko'], ['adam'])).toEqual(false); expect(equals(['misko'], ['misko', 'adam'])).toEqual(false); }); it('should ignore $ member variables', function(){ expect(equals({name:'misko', $id:1}, {name:'misko', $id:2})).toEqual(true); expect(equals({name:'misko'}, {name:'misko', $id:2})).toEqual(true); expect(equals({name:'misko', $id:1}, {name:'misko'})).toEqual(true); }); it('should ignore functions', function(){ expect(equals({func: function() {}}, {bar: function() {}})).toEqual(true); }); }); describe('parseKeyValue', function() { it('should parse a string into key-value pairs', function() { expect(parseKeyValue('')).toEqual({}); expect(parseKeyValue('simple=pair')).toEqual({simple: 'pair'}); expect(parseKeyValue('first=1&second=2')).toEqual({first: '1', second: '2'}); expect(parseKeyValue('escaped%20key=escaped%20value')). toEqual({'escaped key': 'escaped value'}); expect(parseKeyValue('emptyKey=')).toEqual({emptyKey: ''}); expect(parseKeyValue('flag1&key=value&flag2')). toEqual({flag1: true, key: 'value', flag2: true}); }); }); describe('toKeyValue', function() { it('should parse key-value pairs into string', function() { expect(toKeyValue({})).toEqual(''); expect(toKeyValue({simple: 'pair'})).toEqual('simple=pair'); expect(toKeyValue({first: '1', second: '2'})).toEqual('first=1&second=2'); expect(toKeyValue({'escaped key': 'escaped value'})). toEqual('escaped%20key=escaped%20value'); expect(toKeyValue({emptyKey: ''})).toEqual('emptyKey='); }); it('should parse true values into flags', function() { expect(toKeyValue({flag1: true, key: 'value', flag2: true})).toEqual('flag1&key=value&flag2'); }); }); describe ('rngScript', function() { it('should match angular.js', function() { expect('angular.js'.match(rngScript)).not.toBeNull(); expect('../angular.js'.match(rngScript)).not.toBeNull(); expect('foo/angular.js'.match(rngScript)).not.toBeNull(); expect('foo.js'.match(rngScript)).toBeNull(); expect('foo/foo.js'.match(rngScript)).toBeNull(); expect('my-angular-app.js'.match(rngScript)).toBeNull(); expect('foo/../my-angular-app.js'.match(rngScript)).toBeNull(); }); it('should match angular.min.js', function() { expect('angular.min.js'.match(rngScript)).not.toBeNull(); expect('../angular.min.js'.match(rngScript)).not.toBeNull(); expect('foo/angular.min.js'.match(rngScript)).not.toBeNull(); expect('my-angular-app.min.js'.match(rngScript)).toBeNull(); expect('foo/../my-angular-app.min.js'.match(rngScript)).toBeNull(); }); it('should match angular-bootstrap.js', function() { expect('angular-bootstrap.js'.match(rngScript)).not.toBeNull(); expect('../angular-bootstrap.js'.match(rngScript)).not.toBeNull(); expect('foo/angular-bootstrap.js'.match(rngScript)).not.toBeNull(); expect('my-angular-app-bootstrap.js'.match(rngScript)).toBeNull(); expect('foo/../my-angular-app-bootstrap.js'.match(rngScript)).toBeNull(); }); it('should match angular-0.9.0.js', function() { expect('angular-0.9.0.js'.match(rngScript)).not.toBeNull(); expect('../angular-0.9.0.js'.match(rngScript)).not.toBeNull(); expect('foo/angular-0.9.0.js'.match(rngScript)).not.toBeNull(); expect('my-angular-app-0.9.0.js'.match(rngScript)).toBeNull(); expect('foo/../my-angular-app-0.9.0.js'.match(rngScript)).toBeNull(); }); it('should match angular-0.9.0.min.js', function() { expect('angular-0.9.0.min.js'.match(rngScript)).not.toBeNull(); expect('../angular-0.9.0.min.js'.match(rngScript)).not.toBeNull(); expect('foo/angular-0.9.0.min.js'.match(rngScript)).not.toBeNull(); expect('my-angular-app-0.9.0.min.js'.match(rngScript)).toBeNull(); expect('foo/../my-angular-app-0.9.0.min.js'.match(rngScript)).toBeNull(); }); it('should match angular-0.9.0-de0a8612.js', function() { expect('angular-0.9.0-de0a8612.js'.match(rngScript)).not.toBeNull(); expect('../angular-0.9.0-de0a8612.js'.match(rngScript)).not.toBeNull(); expect('foo/angular-0.9.0-de0a8612.js'.match(rngScript)).not.toBeNull(); expect('my-angular-app-0.9.0-de0a8612.js'.match(rngScript)).toBeNull(); expect('foo/../my-angular-app-0.9.0-de0a8612.js'.match(rngScript)).toBeNull(); }); it('should match angular-0.9.0-de0a8612.min.js', function() { expect('angular-0.9.0-de0a8612.min.js'.match(rngScript)).not.toBeNull(); expect('../angular-0.9.0-de0a8612.min.js'.match(rngScript)).not.toBeNull(); expect('foo/angular-0.9.0-de0a8612.min.js'.match(rngScript)).not.toBeNull(); expect('my-angular-app-0.9.0-de0a8612.min.js'.match(rngScript)).toBeNull(); expect('foo/../my-angular-app-0.9.0-de0a8612.min.js'.match(rngScript)).toBeNull(); }); }); describe('angularJsConfig', function() { it('should find angular.js script tag and config', function() { var doc = { getElementsByTagName: function(tagName) { expect(tagName).toEqual('script'); return [{nodeName: 'SCRIPT', src: 'random.js'}, {nodeName: 'SCRIPT', src: 'angular.js'}, {nodeName: 'SCRIPT', src: 'my-angular-app.js'}]; } }; expect(angularJsConfig(doc)).toEqual({base_url: '', ie_compat: 'angular-ie-compat.js', ie_compat_id: 'ng-ie-compat'}); }); it('should extract angular config from the ng: attributes', function() { var doc = { getElementsByTagName: function(tagName) { expect(lowercase(tagName)).toEqual('script'); return [{nodeName: 'SCRIPT', src: 'angularjs/angular.js', attributes: [{name: 'ng:autobind', value:undefined}, {name: 'ng:css', value: 'css/my_custom_angular.css'}, {name: 'ng:ie-compat', value: 'myjs/angular-ie-compat.js'}, {name: 'ng:ie-compat-id', value: 'ngcompat'}] }]; }}; expect(angularJsConfig(doc)).toEqual({base_url: 'angularjs/', autobind: true, css: 'css/my_custom_angular.css', ie_compat: 'myjs/angular-ie-compat.js', ie_compat_id: 'ngcompat'}); }); it("should default to versioned ie-compat file if angular file is versioned", function() { var doc = { getElementsByTagName: function(tagName) { expect(lowercase(tagName)).toEqual('script'); return [{nodeName: 'SCRIPT', src: 'js/angular-0.9.0.js'}]; }}; expect(angularJsConfig(doc)).toEqual({base_url: 'js/', ie_compat: 'js/angular-ie-compat-0.9.0.js', ie_compat_id: 'ng-ie-compat'}); }); it("should default to versioned ie-compat file if angular file is versioned and minified", function() { var doc = { getElementsByTagName: function(tagName) { expect(lowercase(tagName)).toEqual('script'); return [{nodeName: 'SCRIPT', src: 'js/angular-0.9.0-cba23f00.min.js'}]; }}; expect(angularJsConfig(doc)).toEqual({base_url: 'js/', ie_compat: 'js/angular-ie-compat-0.9.0-cba23f00.js', ie_compat_id: 'ng-ie-compat'}); }); });