mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-30 17:44:07 +03:00
Build amd module
This commit is contained in:
parent
7b7acb8679
commit
e1fbcb5030
|
@ -59,7 +59,7 @@ gulp.task('bundleSfx', ['inlineTemplates'], function(cb) {
|
|||
builder
|
||||
.buildStatic(path.join(paths.tmp, paths.sourceEntryPoint),
|
||||
paths.redocBuilt,
|
||||
{ globalName: 'Redoc', sourceMaps: true, lowResSourceMaps: true }
|
||||
{ format:'amd', sourceMaps: true, lowResSourceMaps: true }
|
||||
)
|
||||
.then(function() {
|
||||
cb();
|
||||
|
|
|
@ -9,10 +9,11 @@ import MethodsList from '../MethodsList/methods-list';
|
|||
import SideMenu from '../SideMenu/side-menu';
|
||||
import StickySidebar from '../../common/components/StickySidebar/sticky-sidebar';
|
||||
import OptionsManager from '../../options';
|
||||
import {redocEvents} from '../../events';
|
||||
|
||||
import {ChangeDetectionStrategy} from 'angular2/core';
|
||||
import {ElementRef} from 'angular2/core';
|
||||
import {BrowserDomAdapter} from 'angular2/platform/browser';
|
||||
import {BrowserDomAdapter, bootstrap} from 'angular2/platform/browser';
|
||||
import detectScollParent from 'scrollparent';
|
||||
|
||||
import {isFunction} from 'angular2/src/facade/lang';
|
||||
|
@ -79,6 +80,29 @@ export default class Redoc extends BaseComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static init(schemaUrl, options) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
|
||||
SchemaManager.instance().load(schemaUrl)
|
||||
.then(() => {
|
||||
(new OptionsManager()).options = options;
|
||||
return bootstrap(Redoc);
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
redocEvents.bootstrapped.next();
|
||||
console.log('ReDoc bootstrapped!');
|
||||
resolve();
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
reject();
|
||||
}
|
||||
);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
Redoc.parameters = Redoc.parameters.concat([[OptionsManager], [ElementRef], [BrowserDomAdapter]]);
|
||||
|
||||
|
|
|
@ -107,6 +107,31 @@ describe('Redoc components', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Redoc init', () => {
|
||||
it('should return promise', () => {
|
||||
let res = Redoc.init();
|
||||
res.should.be.instanceof(Promise);
|
||||
});
|
||||
|
||||
it('should reject promise for not specifed url', (done) => {
|
||||
let res = Redoc.init();
|
||||
res.then(() => { done.fail('Should not been called'); }, () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
//skip because of PhantomJS crashes on this testcase
|
||||
xit('should init redoc', (done) => {
|
||||
var node = document.createElement('redoc');
|
||||
document.body.appendChild(node);
|
||||
let res = Redoc.init('/tests/schemas/extended-petstore.json');
|
||||
res.then(() => { done(); }, () => {
|
||||
done.fail('Error handler should not been called');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/** Test component that contains a Redoc. */
|
||||
@Component({selector: 'test-app'})
|
||||
@View({
|
||||
|
|
28
lib/index.js
28
lib/index.js
|
@ -1,33 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import {bootstrap} from 'angular2/platform/browser';
|
||||
import {Redoc} from './components/index';
|
||||
import SchemaManager from './utils/SchemaManager';
|
||||
import {redocEvents} from './events';
|
||||
import OptionsManager from './options';
|
||||
export * from './components/index';
|
||||
|
||||
export function init(schemaUrl, options) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
|
||||
SchemaManager.instance().load(schemaUrl)
|
||||
.then(() => {
|
||||
(new OptionsManager()).options = options;
|
||||
return bootstrap(Redoc);
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
redocEvents.bootstrapped.next();
|
||||
console.log('ReDoc bootstrapped!');
|
||||
resolve();
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
reject();
|
||||
}
|
||||
);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
export var init = Redoc.init;
|
||||
|
||||
window.Redoc = Redoc;
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
'use strict';
|
||||
import {init} from 'lib/index';
|
||||
|
||||
describe('Redoc init', () => {
|
||||
it('should return promise', () => {
|
||||
let res = init();
|
||||
res.should.be.instanceof(Promise);
|
||||
});
|
||||
|
||||
it('should reject promise for not specifed url', (done) => {
|
||||
let res = init();
|
||||
res.then(() => { done.fail('Should not been called'); }, () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
//skip because of PhantomJS crashes on this testcase
|
||||
xit('should init redoc', (done) => {
|
||||
var node = document.createElement('redoc');
|
||||
document.body.appendChild(node);
|
||||
let res = init('/tests/schemas/extended-petstore.json');
|
||||
res.then(() => { done(); }, () => {
|
||||
done.fail('Error handler should not been called');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user