Skip to content

Commit

Permalink
Merge pull request #12 from mike-goodwin/techjeffharris-master
Browse files Browse the repository at this point in the history
Techjeffharris master
  • Loading branch information
mike-goodwin authored Dec 7, 2016
2 parents 45418c4 + 8013eea commit 17449c5
Show file tree
Hide file tree
Showing 32 changed files with 303 additions and 39 deletions.
18 changes: 9 additions & 9 deletions components/carousel.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ mixin carousel-caption(item)
p #{item.p}
unless !item.button
p
a.btn.btn-lg.btn-primary(href="#{item.button.url}" role="button") #{item.button.caption}
a.btn.btn-lg.btn-primary(href=item.button.url role="button") #{item.button.caption}

//- carousel
mixin carousel(id,items)
.carousel.slide(id="carousel-#{id}",data-ride="carousel")
.carousel.slide(id="carousel-" + id ,data-ride="carousel")
//- Indicators
ol.carousel-indicators
each item,index in items
if(index === 0)
li.active(data-target="#carousel-#{id}", data-slide-to="#{index}")
li.active(data-target="#carousel-" + id, data-slide-to=index)
else
li(data-target="#carousel-#{id}", data-slide-to="#{index}")
li(data-target="#carousel-" + id, data-slide-to=index)


//- Wrapper for slides
.carousel-inner(role="listbox")
each item,index in items
if(index === 0)
.item.active
img(src="#{item.image}")
img(src=item.image)
+carousel-caption(item)

else
.item
img(src="#{item.image}")
img(src=item.image)
+carousel-caption(item)

//- Controls
a.left.carousel-control(href="#carousel-#{id}", role="button", data-slide="prev")
a.left.carousel-control(href="#carousel-" + id, role="button", data-slide="prev")
+icon("chevron-left")
span.sr-only Previous
a.right.carousel-control(href="#carousel-#{id}", role="button", data-slide="next")
a.right.carousel-control(href="#carousel-" + id, role="button", data-slide="next")
+icon("chevron-right")
span.sr-only Next
41 changes: 21 additions & 20 deletions components/panels.pug
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
//- panel
mixin panel(type,title)
.panel(class="panel-#{type}")
.panel-heading
h3.panel-title= title
.panel-body
block
.panel(class="panel-" + type)
if undefined !== title
.panel-heading
h3.panel-title= title
.panel-body
block

//- panel-default
mixin panel-default(title)
+panel("default",title)
block
+panel("default",title)
block

//- panel-primary
mixin panel-primary(title)
+panel("primary",title)
block
+panel("primary",title)
block

//- panel-success
mixin panel-success(title)
+panel("success",title)
block
+panel("success",title)
block

//- panel-info
mixin panel-info(title)
+panel("info",title)
block
+panel("info",title)
block

//- panel-warning
mixin panel-warning(title)
+panel("warning",title)
block
+panel("warning",title)
block

//- panel-danger
mixin panel-danger(title)
+panel("danger",title)
block
+panel("danger",title)
block
16 changes: 8 additions & 8 deletions components/toggle.pug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//- toggle
mixin toggle(type,text)
button.btn(class="btn-#{type}",type="button",data-toggle="button",aria-pressed="false",autocomplete="off")
button.btn(class="btn-" + type,type="button",data-toggle="button",aria-pressed="false",autocomplete="off")
= text

//- toggle-primary
Expand Down Expand Up @@ -35,12 +35,12 @@ mixin toggle-danger(text)
mixin checkbox-toggle(type,items,active)
.btn-group(data-toggle="buttons")
each item,index in items
if(index === active)
label.btn.active(class="btn-#{type}")
if index === active
label.btn.active(class="btn-" + type)
input(type="checkbox",autocomplete="off",checked)
| #{item.caption}
else
label.btn(class="btn-#{type}")
label.btn(class="btn-" + type)
input(type="checkbox",autocomplete="off")
| #{item.caption}

Expand Down Expand Up @@ -74,12 +74,12 @@ mixin radio-toggle(type,name,items,active)
.btn-group(data-toggle="buttons")
each item,index in items
if(index === active)
label.btn.active(class="btn-#{type}")
input(type="radio",name="#{name}",autocomplete="off",checked)
label.btn.active(class="btn-" + type)
input(type="radio",name=name,autocomplete="off",checked)
| #{item.caption}
else
label.btn(class="btn-#{type}")
input(type="radio",name="#{name}",autocomplete="off")
label.btn(class="btn-" + type)
input(type="radio",name=name,autocomplete="off")
| #{item.caption}

//- radio-toggle-primary
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pug-bootstrap",
"version": "0.0.5",
"version": "0.0.6",
"description": "Bootstrap framework written completely using mixins in pug",
"main": "bootstrap.pug",
"scripts": {
Expand Down
40 changes: 39 additions & 1 deletion test/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@ var pug = require("pug");
var assert = require("assert");
var path = require("path");

describe("Carousel", function() {
var items = [
{
h1: 'heading 0',
p: 'para 0',
button: {
url: 'button url 0',
caption: 'button caption 0'
}
},
{
p: 'para 1',
button: {
url: 'button url 1',
caption: 'button caption 1'
}
},
{
h1: 'heading 2',
button: {
url: 'button url 2',
caption: 'button caption 2'
}
},
{
h1: 'heading 3',
p: 'para 3'
}
];

var locals = {
id: 'carousel-id',
items: items
};

describe("Carousel", function () {
fn = pug.compileFile(path.join(__dirname,"fixtures/carousel/carousel.pug"));
actual = '<div class="carousel slide" id="carousel-carousel-id" data-ride="carousel"><ol class="carousel-indicators"><li class="active" data-target="#carousel-carousel-id" data-slide-to="0"></li><li data-target="#carousel-carousel-id" data-slide-to="1"></li><li data-target="#carousel-carousel-id" data-slide-to="2"></li><li data-target="#carousel-carousel-id" data-slide-to="3"></li></ol><div class="carousel-inner" role="listbox"><div class="item active"><img/><div class="carousel-caption"><h1>heading 0</h1><p>para 0</p><p><a class="btn btn-lg btn-primary" href="button url 0" role="button">button caption 0</a></p></div></div><div class="item"><img/><div class="carousel-caption"><p>para 1</p><p><a class="btn btn-lg btn-primary" href="button url 1" role="button">button caption 1</a></p></div></div><div class="item"><img/><div class="carousel-caption"><h1>heading 2</h1><p><a class="btn btn-lg btn-primary" href="button url 2" role="button">button caption 2</a></p></div></div><div class="item"><img/><div class="carousel-caption"><h1>heading 3</h1><p>para 3</p></div></div></div><a class="left carousel-control" href="#carousel-carousel-id" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a><a class="right carousel-control" href="#carousel-carousel-id" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a></div>';
it("should generate a carousel", function() {
assert.equal(actual, fn(locals));
});
});
3 changes: 3 additions & 0 deletions test/fixtures/carousel/carousel.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include ../../../components/icons
include ../../../components/carousel
+carousel(id,items)
2 changes: 2 additions & 0 deletions test/fixtures/panels/panel-danger.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/panels.pug
+panel-danger(title)
2 changes: 2 additions & 0 deletions test/fixtures/panels/panel-default.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/panels.pug
+panel-default(title)
2 changes: 2 additions & 0 deletions test/fixtures/panels/panel-info.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/panels.pug
+panel-info(title)
2 changes: 2 additions & 0 deletions test/fixtures/panels/panel-primary.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/panels.pug
+panel-primary(title)
2 changes: 2 additions & 0 deletions test/fixtures/panels/panel-success.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/panels.pug
+panel-success(title)
2 changes: 2 additions & 0 deletions test/fixtures/panels/panel-warning.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/panels.pug
+panel-warning(title)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/checkbox-toggle-danger.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+checkbox-toggle-danger(items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/checkbox-toggle-default.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+checkbox-toggle-default(items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/checkbox-toggle-info.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+checkbox-toggle-info(items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/checkbox-toggle-primary.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+checkbox-toggle-primary(items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/checkbox-toggle-success.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+checkbox-toggle-success(items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/checkbox-toggle-warning.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+checkbox-toggle-warning(items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/radio-toggle-danger.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+radio-toggle-danger(name,items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/radio-toggle-default.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+radio-toggle-default(name,items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/radio-toggle-info.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+radio-toggle-info(name,items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/radio-toggle-primary.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+radio-toggle-primary(name,items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/radio-toggle-success.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+radio-toggle-success(name,items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/radio-toggle-warning.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+radio-toggle-warning(name,items,active)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/toggle-danger.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+toggle-danger(caption)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/toggle-default.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+toggle-default(caption)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/toggle-info.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+toggle-info(caption)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/toggle-primary.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+toggle-primary(caption)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/toggle-success.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+toggle-success(caption)
2 changes: 2 additions & 0 deletions test/fixtures/toggles/toggle-warning.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../components/toggle.pug
+toggle-warning(caption)
82 changes: 82 additions & 0 deletions test/panels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var assert = require('assert');
var pug = require('pug');
var fs = require('fs');
var path = require('path');

// Write fixture data
var mixins = ["panel-default", "panel-primary", "panel-success", "panel-info", "panel-warning", "panel-danger"];
mixins.forEach(function (m) {
var fileTemplate = `include ../../../components/panels.pug
+${m}(title)`;
var fileName = `${m}.pug`;
fs.writeFileSync(path.join(__dirname, "fixtures/panels", fileName), fileTemplate);
});

var testData = [
{
suite: 'panel-default mixin',
spec: 'should render a default panel',
fixture: 'panel-default.pug',
locals: { title: "Default Panel" },
actual: '<div class="panel panel-default">[HEADING]<div class="panel-body"></div></div>',
heading: '<div class="panel-heading"><h3 class="panel-title">[TITLE]</h3></div>'
},
{
suite: 'panel-danger mixin',
spec: 'should render a danger panel',
fixture: 'panel-danger.pug',
locals: { title: "Danger Panel" },
actual: '<div class="panel panel-danger">[HEADING]<div class="panel-body"></div></div>',
heading: '<div class="panel-heading"><h3 class="panel-title">[TITLE]</h3></div>'
},
{
suite: 'panel-info mixin',
spec: 'should render a info panel',
fixture: 'panel-info.pug',
locals: { title: "Info Panel" },
actual: '<div class="panel panel-info">[HEADING]<div class="panel-body"></div></div>',
heading: '<div class="panel-heading"><h3 class="panel-title">[TITLE]</h3></div>'
},
{
suite: 'panel-primary mixin',
spec: 'should render a primary panel',
fixture: 'panel-primary.pug',
locals: { title: "Primary Panel" },
actual: '<div class="panel panel-primary">[HEADING]<div class="panel-body"></div></div>',
heading: '<div class="panel-heading"><h3 class="panel-title">[TITLE]</h3></div>'
},
{
suite: 'panel-success mixin',
spec: 'should render a danger panel',
fixture: 'panel-success.pug',
locals: { title: "Success Panel" },
actual: '<div class="panel panel-success">[HEADING]<div class="panel-body"></div></div>',
heading: '<div class="panel-heading"><h3 class="panel-title">[TITLE]</h3></div>'
},
{
suite: 'panel-warning mixin',
spec: 'should render a warning panel',
fixture: 'panel-warning.pug',
locals: { title: "Warning Panel" },
actual: '<div class="panel panel-warning">[HEADING]<div class="panel-body"></div></div>',
heading: '<div class="panel-heading"><h3 class="panel-title">[TITLE]</h3></div>'
}
];

describe('Panels', function () {
testData.forEach(function (item) {
describe(item.suite, function () {
it(item.spec + ' (with supplied title)', function () {
var fn = pug.compileFile(path.join(__dirname, "fixtures/panels", item.fixture));
var heading = item.heading.replace('[TITLE]', item.locals.title);
var actual = item.actual.replace('[HEADING]', heading);
assert.equal(actual, fn(item.locals));
});
it(item.spec + ' (with default title)', function () {
var fn = pug.compileFile(path.join(__dirname, "fixtures/panels", item.fixture));
var actual = item.actual.replace('[HEADING]', '');
assert.equal(actual, fn());
});
});
});
});
Loading

0 comments on commit 17449c5

Please sign in to comment.