Skip to content

Commit 72595c1

Browse files
committed
Don’t show the HTML tab when it’s empty
Fixes #20
1 parent 844f7dc commit 72595c1

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

demo_frame.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ module.exports = function(node) {
3030
var html = getHTML.call(this, demoEl);
3131
var js = getJS.call(this, sourceEl);
3232

33-
var dataForHtml = node.querySelector("[data-for=html] > pre code, [data-for=html] > div > pre code");
34-
dataForHtml.innerHTML = escape(html);
35-
prettify(dataForHtml);
33+
if (html && html.trim()) {
34+
var dataForHtml = node.querySelector("[data-for=html] > pre code, [data-for=html] > div > pre code");
35+
dataForHtml.innerHTML = escape(html);
36+
prettify(dataForHtml);
37+
38+
show(node.querySelector("[data-tab=html]"));
39+
}
3640

3741
if (js) {
3842
var dataForJS = node.querySelector("[data-for=js] > pre code, [data-for=js] > div > pre code");

demo_tpl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = `
22
<ul>
33
<li class="tab" data-tab="demo">Demo</li>
4-
<li class="tab" data-tab="html">HTML</li>
4+
<li class="tab" data-tab="html" style="display:none">HTML</li>
55
<li class="tab" data-tab="js" style="display:none;">JS</li>
66
</ul>
77
<div class="tab-content" data-for="demo">

test.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,38 @@ describe("bit-docs-tag-demo", function() {
281281
});
282282
});
283283

284+
describe("without html", function() {
285+
before(function() {
286+
return ctx.browser.newPage().then(function(p) {
287+
ctx.page = p;
288+
return ctx.page.goto(
289+
"http://127.0.0.1:8081/test/temp/withoutHtml.html"
290+
);
291+
});
292+
});
293+
294+
after(function() {
295+
return ctx.page.close().then(function() {
296+
ctx.page = null;
297+
});
298+
});
299+
300+
describe("HTML", function() {
301+
// expect no content
302+
dataForHtml("");
303+
304+
it("tab is hidden", function() {
305+
return ctx.page
306+
.evaluate(function() {
307+
return document.querySelector('[data-tab="html"]').style.display;
308+
})
309+
.then(function(display) {
310+
assert.equal(display, "none", "html tab is hidden");
311+
});
312+
});
313+
});
314+
});
315+
284316
describe("without js", function() {
285317
before(function() {
286318
return ctx.browser.newPage().then(function(p) {
@@ -448,8 +480,8 @@ describe("bit-docs-tag-demo", function() {
448480
};
449481
})
450482
.then(function(r) {
451-
assert.equal(r.wrappers, 6, "four wrappers exists");
452-
assert.equal(r.injected, 6, "four injected into wrappers");
483+
assert.equal(r.wrappers, 7, "demo wrappers exist");
484+
assert.equal(r.injected, 7, "demos injected into wrappers");
453485
});
454486
});
455487
});

test/demos/demo-without-html.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div id="demo-html">
2+
3+
</div>
4+
5+
<script id="demo-source">
6+
var div = document.createElement("div");
7+
div.textContent = "it worked!";
8+
document.body.appendChild(div);
9+
</script>

test/generate.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function makeWrapper(path) {
1313
function allDemos() {
1414
return [
1515
"demo-with-ids",
16+
"demo-without-html",
1617
"demo-without-ids",
1718
"demo-without-js",
1819
"demo-complex",
@@ -30,6 +31,10 @@ var docMap = Promise.resolve({
3031
name: "withIds",
3132
body: makeWrapper("demo-with-ids")
3233
},
34+
withoutHtml: {
35+
name: "withoutHtml",
36+
body: makeWrapper("demo-without-html")
37+
},
3338
withoutIds: {
3439
name: "withoutIds",
3540
body: makeWrapper("demo-without-ids")

0 commit comments

Comments
 (0)