diff --git a/build/tasks/build.js b/build/tasks/build.js index a2519f19..a9eed6c0 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -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(); diff --git a/lib/components/Redoc/redoc.js b/lib/components/Redoc/redoc.js index 2d9c20d3..3c7dc32f 100644 --- a/lib/components/Redoc/redoc.js +++ b/lib/components/Redoc/redoc.js @@ -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]]); diff --git a/lib/components/Redoc/redoc.spec.js b/lib/components/Redoc/redoc.spec.js index 4e6be661..a9642299 100644 --- a/lib/components/Redoc/redoc.spec.js +++ b/lib/components/Redoc/redoc.spec.js @@ -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({ diff --git a/lib/index.js b/lib/index.js index 9f6594f6..d2af96ce 100644 --- a/lib/index.js +++ b/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; diff --git a/lib/index.spec.js b/lib/index.spec.js deleted file mode 100644 index 1ee1d0bb..00000000 --- a/lib/index.spec.js +++ /dev/null @@ -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'); - }); - }); -});