Merge branch 'master' into releases

This commit is contained in:
Roman Hotsiy 2016-01-20 17:08:38 +02:00
commit 9d26d9b426
6 changed files with 110 additions and 15 deletions

View File

@ -44,6 +44,7 @@ deploy:
branch: master branch: master
- provider: npm - provider: npm
skip_cleanup: true skip_cleanup: true
email: gotsijroman@gmail.com
api_key: api_key:
secure: PuhWLERrCEFmXmdFpw2OVFlqpOIVDmgwk5JUJOYaFdVCh/smp0+jZCQ4vrdFpuG96rnDVirD+A8xvW6NgsNNaRthLgOB/LRdFN69rU6Gvn3At6wlnC55t5dlhxPvCfnzJcHVBLXX4EmMkjnZqDg2uczXTzPodr3FnQJNuXmP8B33fzDVLyHccvXZ90abwXWVrgRIXPU28niqCR8DOC2OTzs7wqz+BLNkYDRRbyYXsg62HWuD33x5iof5IqBmhzBt3usCGmF3QGcgHrXHdZw3sZnit8+Bua++3KrXR0x6HGXXN1AoXVmCAkCa5OTQ5R3tCRxiJN3P2KLnvWeZR74sTFkovJB/6pGCvbJ/c7Wnuw6sD7SgOUBD359ULB6lAf5OnxBLoNebX4JxxVXF+zA4E3Bl44VxkzDpPWc15xqBPMB5vBREzMVmJ5mExn2s5cmLQjADbl9h0y6gZnhnNJ+iTmqtrVyM0ZkF2rPrzrTdGD+ULmRIlTMkdD1bh+/TJ3RdXT3P4/zNUJmiNnvgnnJVYYvsGaXWF+7uCVHT/8k2RsoSHqgkqh0gkDqGSwVix55y5mC7T2Vk9lMBhm6MvFJXaonOX0kxJS4EDQ3plPd6/ybG+TLhwggYnQ8o9msU5Nt6FpUShKiezjKurIhbQZdwlVivX3tahjW2QjNDO58xGgY= secure: PuhWLERrCEFmXmdFpw2OVFlqpOIVDmgwk5JUJOYaFdVCh/smp0+jZCQ4vrdFpuG96rnDVirD+A8xvW6NgsNNaRthLgOB/LRdFN69rU6Gvn3At6wlnC55t5dlhxPvCfnzJcHVBLXX4EmMkjnZqDg2uczXTzPodr3FnQJNuXmP8B33fzDVLyHccvXZ90abwXWVrgRIXPU28niqCR8DOC2OTzs7wqz+BLNkYDRRbyYXsg62HWuD33x5iof5IqBmhzBt3usCGmF3QGcgHrXHdZw3sZnit8+Bua++3KrXR0x6HGXXN1AoXVmCAkCa5OTQ5R3tCRxiJN3P2KLnvWeZR74sTFkovJB/6pGCvbJ/c7Wnuw6sD7SgOUBD359ULB6lAf5OnxBLoNebX4JxxVXF+zA4E3Bl44VxkzDpPWc15xqBPMB5vBREzMVmJ5mExn2s5cmLQjADbl9h0y6gZnhnNJ+iTmqtrVyM0ZkF2rPrzrTdGD+ULmRIlTMkdD1bh+/TJ3RdXT3P4/zNUJmiNnvgnnJVYYvsGaXWF+7uCVHT/8k2RsoSHqgkqh0gkDqGSwVix55y5mC7T2Vk9lMBhm6MvFJXaonOX0kxJS4EDQ3plPd6/ybG+TLhwggYnQ8o9msU5Nt6FpUShKiezjKurIhbQZdwlVivX3tahjW2QjNDO58xGgY=
on: on:

View File

@ -12,16 +12,12 @@
</nav> </nav>
</nav> </nav>
<redoc scroll-y-offset="body > nav"> <redoc scroll-y-offset="body > nav" spec-url='swagger.json'>
Loading... Loading...
</redoc> </redoc>
<!-- ReDoc built file with all dependencies included --> <!-- ReDoc built file with all dependencies included -->
<script src="dist/redoc.full.js"> </script> <script src="dist/redoc.full.js"> </script>
<script src="main.js"> </script> <script src="main.js"> </script>
<script>
/* init redoc */
Redoc.init('swagger.json', {scrollYOffset: 'body>nav'});
</script>
</body> </body>
</html> </html>

View File

@ -103,19 +103,36 @@ export default class Redoc extends BaseComponent {
); );
} }
static autoInit() {
const specUrlAttributeName = 'spec-url';
let dom = new BrowserDomAdapter();
let redocEl = dom.query('redoc');
if (!redocEl) return;
if (dom.hasAttribute(redocEl, specUrlAttributeName)) {
let url = dom.getAttribute(redocEl, specUrlAttributeName);
Redoc.init(url);
}
}
static dispose() { static dispose() {
let dom = new BrowserDomAdapter(); let dom = new BrowserDomAdapter();
let el = dom.query('redoc'); let el = dom.query('redoc');
let parent = el.parentElement; let parent;
let nextSibling = el.nextElementSibling; let nextSibling;
if (el) {
parent = el.parentElement;
nextSibling = el.nextElementSibling;
}
Redoc.appRef && Redoc.appRef.dispose(); if (Redoc.appRef) {
Redoc.appRef = null; Redoc.appRef.dispose();
Redoc.appRef = null;
// Redoc dispose removes host element, so need to restore it // Redoc dispose removes host element, so need to restore it
el = dom.createElement('redoc'); el = dom.createElement('redoc');
el.innerText = 'Loading...'; el.innerText = 'Loading...';
parent.insertBefore(el, nextSibling); parent && parent.insertBefore(el, nextSibling);
}
} }
} }
Redoc.parameters = Redoc.parameters.concat([[OptionsManager], [ElementRef], [BrowserDomAdapter]]); Redoc.parameters = Redoc.parameters.concat([[OptionsManager], [ElementRef], [BrowserDomAdapter]]);

View File

@ -129,8 +129,88 @@ describe('Redoc init', () => {
done.fail('Error handler should not been called'); done.fail('Error handler should not been called');
}); });
}); });
});
describe('Redoc dispose', () => {
let builder;
let fixture;
let element;
let disposeSpy;
let dom = new BrowserDomAdapter();
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(OptionsManager, {useValue: optsMgr})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; });
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement;
disposeSpy = jasmine.createSpy('spy');
Redoc.appRef = {
dispose: disposeSpy
};
fixture.detectChanges();
done();
}, err => { throw err; });
});
afterEach(()=> {
fixture.destroy();
Redoc.appRef = null;
});
it('should call componentRef.dispose', () => {
Redoc.dispose();
expect(disposeSpy).toHaveBeenCalled();
});
it('should create new host element', () => {
element.parentElement.removeChild(element);
Redoc.dispose();
expect(dom.query('redoc')).not.toBeNull();
dom.query('redoc').should.not.be.equal(element);
});
it('should set to null appRef', () => {
Redoc.dispose();
expect(Redoc.appRef).toBeNull();
});
});
describe('Redoc autoInit', () => {
const testURL = 'testurl';
let dom = new BrowserDomAdapter();
let elem;
beforeEach(() => {
spyOn(Redoc, 'init').and.stub();
elem = dom.createElement('redoc');
dom.defaultDoc().body.appendChild(elem);
dom.setAttribute(elem, 'spec-url', testURL);
});
it('should call Redoc.init with url from param spec-url', () => {
Redoc.autoInit();
expect(Redoc.init).toHaveBeenCalled();
expect(Redoc.init.calls.argsFor(0)).toEqual([testURL]);
});
it('should not call Redoc.init when spec-url param is not provided', () => {
dom.removeAttribute(elem, 'spec-url');
Redoc.autoInit();
expect(Redoc.init).not.toHaveBeenCalled();
});
afterEach(() => {
Redoc.init.and.callThrough();
dom.defaultDoc().body.removeChild(elem);
});
});
});
/** Test component that contains a Redoc. */ /** Test component that contains a Redoc. */
@Component({selector: 'test-app'}) @Component({selector: 'test-app'})

View File

@ -7,3 +7,4 @@ export var init = Redoc.init;
window.Redoc = Redoc; window.Redoc = Redoc;
enableProdMode(); enableProdMode();
Redoc.autoInit();

View File

@ -1,7 +1,7 @@
{ {
"name": "redoc", "name": "redoc",
"description": "Swagger-generated API Reference Documentation", "description": "Swagger-generated API Reference Documentation",
"version": "0.1.0", "version": "0.2.0",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/Rebilly/ReDoc" "url": "git://github.com/Rebilly/ReDoc"