Skip to content

Commit

Permalink
Merge pull request #21 from bit-docs/20-no-content-tabs
Browse files Browse the repository at this point in the history
Don’t show the HTML tab when it’s empty
  • Loading branch information
chasenlehara authored Apr 16, 2018
2 parents 0d74462 + 72595c1 commit fd611f2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 22 deletions.
10 changes: 7 additions & 3 deletions demo_frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ module.exports = function(node) {
var html = getHTML.call(this, demoEl);
var js = getJS.call(this, sourceEl);

var dataForHtml = node.querySelector("[data-for=html] > pre code, [data-for=html] > div > pre code");
dataForHtml.innerHTML = escape(html);
prettify(dataForHtml);
if (html && html.trim()) {
var dataForHtml = node.querySelector("[data-for=html] > pre code, [data-for=html] > div > pre code");
dataForHtml.innerHTML = escape(html);
prettify(dataForHtml);

show(node.querySelector("[data-tab=html]"));
}

if (js) {
var dataForJS = node.querySelector("[data-for=js] > pre code, [data-for=js] > div > pre code");
Expand Down
16 changes: 0 additions & 16 deletions demo_frame.stache

This file was deleted.

2 changes: 1 addition & 1 deletion demo_tpl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = `
<ul>
<li class="tab" data-tab="demo">Demo</li>
<li class="tab" data-tab="html">HTML</li>
<li class="tab" data-tab="html" style="display:none">HTML</li>
<li class="tab" data-tab="js" style="display:none;">JS</li>
</ul>
<div class="tab-content" data-for="demo">
Expand Down
36 changes: 34 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,38 @@ describe("bit-docs-tag-demo", function() {
});
});

describe("without html", function() {
before(function() {
return ctx.browser.newPage().then(function(p) {
ctx.page = p;
return ctx.page.goto(
"http://127.0.0.1:8081/test/temp/withoutHtml.html"
);
});
});

after(function() {
return ctx.page.close().then(function() {
ctx.page = null;
});
});

describe("HTML", function() {
// expect no content
dataForHtml("");

it("tab is hidden", function() {
return ctx.page
.evaluate(function() {
return document.querySelector('[data-tab="html"]').style.display;
})
.then(function(display) {
assert.equal(display, "none", "html tab is hidden");
});
});
});
});

describe("without js", function() {
before(function() {
return ctx.browser.newPage().then(function(p) {
Expand Down Expand Up @@ -448,8 +480,8 @@ describe("bit-docs-tag-demo", function() {
};
})
.then(function(r) {
assert.equal(r.wrappers, 6, "four wrappers exists");
assert.equal(r.injected, 6, "four injected into wrappers");
assert.equal(r.wrappers, 7, "demo wrappers exist");
assert.equal(r.injected, 7, "demos injected into wrappers");
});
});
});
Expand Down
9 changes: 9 additions & 0 deletions test/demos/demo-without-html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div id="demo-html">

</div>

<script id="demo-source">
var div = document.createElement("div");
div.textContent = "it worked!";
document.body.appendChild(div);
</script>
5 changes: 5 additions & 0 deletions test/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function makeWrapper(path) {
function allDemos() {
return [
"demo-with-ids",
"demo-without-html",
"demo-without-ids",
"demo-without-js",
"demo-complex",
Expand All @@ -30,6 +31,10 @@ var docMap = Promise.resolve({
name: "withIds",
body: makeWrapper("demo-with-ids")
},
withoutHtml: {
name: "withoutHtml",
body: makeWrapper("demo-without-html")
},
withoutIds: {
name: "withoutIds",
body: makeWrapper("demo-without-ids")
Expand Down

0 comments on commit fd611f2

Please sign in to comment.