ustyle 1.15.3 → 1.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.nvmrc +1 -1
- data/Gruntfile.js +104 -82
- data/README.md +45 -21
- data/dist/ustyle-content.css +1 -1
- data/dist/ustyle-latest.css +1 -1
- data/dist/ustyle.js +148 -97
- data/dist/ustyle.json +1 -1
- data/dist/ustyle.min.js +1 -1
- data/grunt/modules/dss-helper.js +103 -105
- data/grunt/modules/file.js +11 -13
- data/grunt/modules/html-parser.js +12 -14
- data/grunt/modules/templates.js +38 -40
- data/grunt/tasks/browser-sync.js +20 -16
- data/grunt/tasks/builder.js +43 -48
- data/grunt/tasks/styleguide.js +187 -182
- data/index.js +31 -0
- data/lib/ustyle/version.rb +1 -1
- data/package-lock.json +9261 -0
- data/package.json +20 -22
- data/styleguide/assets/javascripts/app.js +83 -56
- data/styleguide/assets/javascripts/modules/stats.js +23 -24
- data/styleguide/assets/javascripts/vendor/highlight.js +1 -1
- data/styleguide/assets/javascripts/vendor/svg4everybody.js +1 -1
- data/styleguide/partials/_footer.tpl +1 -1
- data/styleguide/partials/_sidebar.tpl +1 -1
- data/vendor/assets/javascripts/ustyle/tabs.js +153 -102
- data/vendor/assets/stylesheets/ustyle/mixins/_media-query.scss +0 -2
- metadata +4 -5
- data/JAVASCRIPT_STANDARDS.md +0 -88
- data/config/.jscsrc +0 -76
- data/styleguide/assets/javascripts/modules/cleanWhiteSpace.js +0 -34
data/dist/ustyle.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var slice=[].slice,hasProp={}.hasOwnProperty;null==this.Utils&&(this.Utils={modules:[]});var addClass=function(a,b){return removeClass(a,b),a.className+=" "+b+" "},removeClass=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)","gi");return a.className=a.className.replace(c,"")},hasClass=function(a,b){return new RegExp("(^| )"+b+"( |$)","gi").test(a.className)},merge=function(){var a,b,c,d,e=arguments[0],f=2<=arguments.length?slice.call(arguments,1):[];for(b=0,c=f.length;b<c;b++){a=f[b];for(d in a)hasProp.call(a,d)&&(e[d]=a[d])}return e},setOptions=function(a,b){return merge({},b,a)},deleteUndefined=function(a){var b,c,d=[];for(b in a)c=a[b],null===c||void 0===c?d.push(delete a[b]):d.push(void 0);return d},transformKey=function(){var a,b,c,d=document.createElement("div"),e=["transform","webkitTransform","OTransform","MozTransform","msTransform"];for(a=0,c=e.length;a<c;a++)if(b=e[a],void 0!==d.style[b])return b}(),requestAnimationFrame=function(a){var b,c,d,e=["ms","moz","webkit","o"];for(b=0,c=e.length;b<c&&(d=e[b],!a.requestAnimationFrame);b++)a.requestAnimationFrame=a[d+"RequestAnimationFrame"];return a.requestAnimationFrame||(a.requestAnimationFrame=function(a){return setTimeout(a,1e3/60)})}(window);this.Utils={addClass:addClass,removeClass:removeClass,hasClass:hasClass,merge:merge,setOptions:setOptions,deleteUndefined:deleteUndefined,transformKey:transformKey,requestAnimationFrame:requestAnimationFrame},window.Backdrop=function(){function a(){null==(d=document.querySelector(".us-backdrop"))&&(d=b())}var b,c=0,d=null;return a.prototype.element=d,b=function(){return d=document.createElement("div"),Utils.addClass(d,"us-backdrop"),document.body.appendChild(d)},a.prototype.retain=function(){var a;if(1===++c)return Utils.addClass(d,"us-backdrop--visible"),a=function(){if(c>=1)return Utils.addClass(d,"us-backdrop--active")},Utils.requestAnimationFrame.call(window,a)},a.prototype.release=function(){var a;return 1===c&&(Utils.removeClass(d,"us-backdrop--active"),a=function(){return setTimeout(function(){if(0===c)return Utils.removeClass(d,"us-backdrop--visible")},300)},Utils.requestAnimationFrame.call(window,a)),c=Math.max(0,c-1)},a}(),window.Overlay=function(a){function b(a){if(this.overlay=(this.options=f(a,h)).overlay,null==this.overlay||"undefined"==typeof Backdrop||null===Backdrop)throw new Error("There's no overlay or you haven't included Backdrop");this.backdrop=new Backdrop,this.addEventListeners()}var c=a.addClass,d=a.hasClass,e=a.removeClass,f=a.setOptions,g=a.requestAnimationFrame,h={bodyActiveClass:"us-overlay--open",activeClass:"us-overlay-parent--active",visibleClass:"us-overlay-parent--visible",overlay:$(".us-overlay-parent"),openButton:".js-open-overlay",closeButton:".js-close-overlay",historyStatus:"#seedeal",history:!1,preventDefault:!0,animationSpeed:300};return b.prototype.addEventListeners=function(){if($(this.options.openButton).on("click.open-overlay",function(a){return function(b){return a.options.preventDefault&&b.preventDefault(),a.show(b)}}(this)),this.overlay.on("click.close-overlay",function(a){return function(b){for(var c=[],d=a.overlay.find(a.options.closeButton).toArray(),e=[a.overlay[0]].concat(d),f=e.length-1;f>=0;f--){var g=e[f];if(b.target===g){a.options.preventDefault&&b.preventDefault(),a.hide(b);break}c.push(void 0)}return c}}(this)),this.hasHistory())return window.onpopstate=function(a){return function(b){if(a.isOpen())return a.hide(b)}}(this)},b.prototype.show=function(a){var b,d=this;if($(document.body).addClass(this.options.bodyActiveClass),this.backdrop.retain(),c(this.overlay[0],this.options.visibleClass),b=function(){return c(d.overlay[0],d.options.activeClass),setTimeout(function(){var b;return"function"==typeof(b=d.options).onOpen?b.onOpen(a):void 0},d.options.animationSpeed)},g.call(window,b),this.hasHistory())return history.pushState("open",window.document.title,this.options.historyStatus)},b.prototype.hide=function(a){var b,c=this;if($(document.body).removeClass(this.options.bodyActiveClass),this.backdrop.release(),b=function(){return e(c.overlay[0],c.options.activeClass),setTimeout(function(){var b;return e(c.overlay[0],c.options.visibleClass),"function"==typeof(b=c.options).onClose?b.onClose(a):void 0},c.options.animationSpeed)},g.call(window,b),this.hasHistory()&&"open"===history.state)return history.back()},b.prototype.isOpen=function(){return d(this.overlay[0],this.options.activeClass)},b.prototype.hasHistory=function(){return this.options.history&&window.history&&window.history.pushState},b}(this.Utils)
|
1
|
+
var slice=[].slice,hasProp={}.hasOwnProperty;null==this.Utils&&(this.Utils={modules:[]});var addClass=function(a,b){return removeClass(a,b),a.className+=" "+b+" "},removeClass=function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)","gi");return a.className=a.className.replace(c,"")},hasClass=function(a,b){return new RegExp("(^| )"+b+"( |$)","gi").test(a.className)},merge=function(){var a,b,c,d,e=arguments[0],f=2<=arguments.length?slice.call(arguments,1):[];for(b=0,c=f.length;b<c;b++){a=f[b];for(d in a)hasProp.call(a,d)&&(e[d]=a[d])}return e},setOptions=function(a,b){return merge({},b,a)},deleteUndefined=function(a){var b,c,d=[];for(b in a)c=a[b],null===c||void 0===c?d.push(delete a[b]):d.push(void 0);return d},transformKey=function(){var a,b,c,d=document.createElement("div"),e=["transform","webkitTransform","OTransform","MozTransform","msTransform"];for(a=0,c=e.length;a<c;a++)if(b=e[a],void 0!==d.style[b])return b}(),requestAnimationFrame=function(a){var b,c,d,e=["ms","moz","webkit","o"];for(b=0,c=e.length;b<c&&(d=e[b],!a.requestAnimationFrame);b++)a.requestAnimationFrame=a[d+"RequestAnimationFrame"];return a.requestAnimationFrame||(a.requestAnimationFrame=function(a){return setTimeout(a,1e3/60)})}(window);this.Utils={addClass:addClass,removeClass:removeClass,hasClass:hasClass,merge:merge,setOptions:setOptions,deleteUndefined:deleteUndefined,transformKey:transformKey,requestAnimationFrame:requestAnimationFrame},window.Backdrop=function(){function a(){null==(d=document.querySelector(".us-backdrop"))&&(d=b())}var b,c=0,d=null;return a.prototype.element=d,b=function(){return d=document.createElement("div"),Utils.addClass(d,"us-backdrop"),document.body.appendChild(d)},a.prototype.retain=function(){var a;if(1===++c)return Utils.addClass(d,"us-backdrop--visible"),a=function(){if(c>=1)return Utils.addClass(d,"us-backdrop--active")},Utils.requestAnimationFrame.call(window,a)},a.prototype.release=function(){var a;return 1===c&&(Utils.removeClass(d,"us-backdrop--active"),a=function(){return setTimeout(function(){if(0===c)return Utils.removeClass(d,"us-backdrop--visible")},300)},Utils.requestAnimationFrame.call(window,a)),c=Math.max(0,c-1)},a}(),window.Overlay=function(a){function b(a){if(this.overlay=(this.options=f(a,h)).overlay,null==this.overlay||"undefined"==typeof Backdrop||null===Backdrop)throw new Error("There's no overlay or you haven't included Backdrop");this.backdrop=new Backdrop,this.addEventListeners()}var c=a.addClass,d=a.hasClass,e=a.removeClass,f=a.setOptions,g=a.requestAnimationFrame,h={bodyActiveClass:"us-overlay--open",activeClass:"us-overlay-parent--active",visibleClass:"us-overlay-parent--visible",overlay:$(".us-overlay-parent"),openButton:".js-open-overlay",closeButton:".js-close-overlay",historyStatus:"#seedeal",history:!1,preventDefault:!0,animationSpeed:300};return b.prototype.addEventListeners=function(){if($(this.options.openButton).on("click.open-overlay",function(a){return function(b){return a.options.preventDefault&&b.preventDefault(),a.show(b)}}(this)),this.overlay.on("click.close-overlay",function(a){return function(b){for(var c=[],d=a.overlay.find(a.options.closeButton).toArray(),e=[a.overlay[0]].concat(d),f=e.length-1;f>=0;f--){var g=e[f];if(b.target===g){a.options.preventDefault&&b.preventDefault(),a.hide(b);break}c.push(void 0)}return c}}(this)),this.hasHistory())return window.onpopstate=function(a){return function(b){if(a.isOpen())return a.hide(b)}}(this)},b.prototype.show=function(a){var b,d=this;if($(document.body).addClass(this.options.bodyActiveClass),this.backdrop.retain(),c(this.overlay[0],this.options.visibleClass),b=function(){return c(d.overlay[0],d.options.activeClass),setTimeout(function(){var b;return"function"==typeof(b=d.options).onOpen?b.onOpen(a):void 0},d.options.animationSpeed)},g.call(window,b),this.hasHistory())return history.pushState("open",window.document.title,this.options.historyStatus)},b.prototype.hide=function(a){var b,c=this;if($(document.body).removeClass(this.options.bodyActiveClass),this.backdrop.release(),b=function(){return e(c.overlay[0],c.options.activeClass),setTimeout(function(){var b;return e(c.overlay[0],c.options.visibleClass),"function"==typeof(b=c.options).onClose?b.onClose(a):void 0},c.options.animationSpeed)},g.call(window,b),this.hasHistory()&&"open"===history.state)return history.back()},b.prototype.isOpen=function(){return d(this.overlay[0],this.options.activeClass)},b.prototype.hasHistory=function(){return this.options.history&&window.history&&window.history.pushState},b}(this.Utils),window.Tabs=function(a){function b(a){var b=this.options=f(a,this.defaults),c=b.tabContainer,d=b.tabLinks;if(this.activeTabEvent=new CustomEvent("ustyle.tab.active"),this.tabs=document.querySelectorAll(c+" "+d),this.tabs.length){this.filter=this.tabs.item(0).getAttribute("data-target")?"data-target":"href",this.init();var e=function(a){return function(b){var c=b.currentTarget;return a.isAccordion()&&a.options.collapsible&&a.isActive(c)?(a.collapse(c),a.hashClear()):(a.navigateTo(c),a.scrollToTab(c),a.hashChange(c)),b.preventDefault()}}(this);h(this.tabs,function(a,b){b.addEventListener("click",e)})}}var c=a.addClass,d=a.hasClass,e=a.removeClass,f=a.setOptions;b.prototype.defaults={tabContainer:".us-tabs",tabLinks:".us-tabs-nav-mainlink",tabNav:".us-tabs-nav",changeUrls:!0,activeClass:"active",collapsible:!1,autoScroll:!0},b.prototype.init=function(){var a=this.activeTab(),b=this.tabFromHash();return b?this.navigateTo(b):a?this.navigateTo(a):this.options.collapsible&&this.isAccordion()?void 0:this.navigateTo(this.tabs.item(0))},b.prototype.hashChange=function(a){if(this.options.changeUrls)return window.location.replace("#!"+g(a).replace(/#/,""))},b.prototype.hashClear=function(){if(this.options.changeUrls){var a=window.location.pathname+window.location.search;return"function"==typeof history.replaceState?history.replaceState("",document.title,a):void 0}},b.prototype.navigateTo=function(a){var b=g(a),d=document.querySelector(b),f=this.options.activeClass,i=this.filter;return h(this.tabs,function(a,b){e(b,f)}),h(this.tabs,function(a,d){if(d.getAttribute(i)===b)return c(d,f)}),h(d.parentNode.children,function(a,b){b!==d&&e(b,f)}),c(d,f),d.dispatchEvent(this.activeTabEvent)},b.prototype.collapse=function(a){var b=document.querySelector(g(a)),c=this.options.activeClass;return h(this.tabs,function(a,b){e(b,c)}),e(b,c)},b.prototype.scrollToTab=function(a){if(this.isAccordion()&&this.options.autoScroll){return document.querySelector(g(a)).scrollIntoView()}},b.prototype.activeTab=function(){var a=this.options.activeClass,b=null;return h(this.tabs,function(c,e){if(d(e,a))return b=e}),b},b.prototype.tabFromHash=function(){var a=window.location.hash.replace("!",""),b=this.filter,c=null;return h(this.tabs,function(d,e){if(e.getAttribute(b)===a)return c=e}),c},b.prototype.isActive=function(a){return g(a)===g(this.activeTab())},b.prototype.isAccordion=function(){var a=document.querySelector(this.options.tabNav);return!(a.offsetWidth>0||a.offsetHeight>0)};var g=function(a){return a.getAttribute("data-target")||a.getAttribute("href")},h=function(a,b,c){for(var d=a.length-1;d>=0;d--)b.call(c,d,a[d])};return b}(this.Utils),window.ClassToggler=function(){function a(a){this.options=Utils.setOptions(a,b),this.options.$target?this.addEventListeners():console.trace("ClassToggle",this.options)}var b;return b={containerClass:null,$target:null,activeClass:"active",inactiveClass:null,toggleOn:"click"},a.prototype.addEventListeners=function(){return this.options.$target.on(this.options.toggleOn,function(a){return function(b){var c=a.options.containerClass?$(b.target).closest(a.options.containerClass):$(b.delegateTarget);return a.isActive(c)?a.hide(c,b):a.show(c,b)}}(this))},a.prototype.isActive=function(a){return a.hasClass(this.options.activeClass)},a.prototype.show=function(a,b){var c;return"function"==typeof(c=this.options).onShow&&c.onShow(a,b),a.addClass(this.options.activeClass)},a.prototype.hide=function(a,b){var c;return"function"==typeof(c=this.options).onHide&&c.onHide(a,b),a.removeClass(this.options.activeClass)},a}(),window.RadioToggle=function(){var a="RadioToggle is now deprecated";window.Raven&&window.Raven.captureMessage(a),console.warn(a)};
|
data/grunt/modules/dss-helper.js
CHANGED
@@ -1,117 +1,115 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
marked = require('marked'),
|
6
|
-
escaped = require("underscore.string/escapeHTML");
|
1
|
+
const dss = require('dss')
|
2
|
+
const crypto = require('crypto')
|
3
|
+
const marked = require('marked')
|
4
|
+
const escaped = require('underscore.string/escapeHTML')
|
7
5
|
|
8
6
|
module.exports = {
|
7
|
+
/**
|
8
|
+
* Register DSS parsers
|
9
|
+
*
|
10
|
+
* @param {object} parsers - An object containing the declared parsers to register
|
11
|
+
*/
|
12
|
+
addParsers: function (parsers) {
|
13
|
+
for (var key in parsers) {
|
14
|
+
dss.parser(key, parsers[key])
|
15
|
+
}
|
16
|
+
},
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
},
|
21
|
-
|
22
|
-
/**
|
23
|
-
* Removing ${modifiers} text from markup
|
24
|
-
*
|
25
|
-
* @param {string} escaped markup - The file to extract the variable values from
|
26
|
-
* @return {string} Escaped string without ${modifiers}
|
27
|
-
*/
|
28
|
-
|
29
|
-
addStateToExample: function(markup, state){
|
30
|
-
return markup.replace(/{\$modifiers}/g, state);
|
31
|
-
},
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Removing ${modifiers} text from markup
|
35
|
-
*
|
36
|
-
* @param {string} escaped markup - The file to extract the variable values from
|
37
|
-
* @return {string} Escaped string without ${modifiers}
|
38
|
-
*/
|
39
|
-
removeModifiersFromMarkup: function(escaped){
|
40
|
-
return escaped.replace(/(\sclass=('|"){\$modifiers}('|")|\s{\$modifiers})/g, "");
|
41
|
-
},
|
18
|
+
/**
|
19
|
+
* Removing ${modifiers} text from markup
|
20
|
+
*
|
21
|
+
* @param {string} escaped markup - The file to extract the variable values from
|
22
|
+
* @return {string} Escaped string without ${modifiers}
|
23
|
+
*/
|
24
|
+
addStateToExample: function (markup, state) {
|
25
|
+
return markup.replace(/{\$modifiers}/g, state)
|
26
|
+
},
|
42
27
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
28
|
+
/**
|
29
|
+
* Removing ${modifiers} text from markup
|
30
|
+
*
|
31
|
+
* @param {string} escaped markup - The file to extract the variable values from
|
32
|
+
* @return {string} Escaped string without ${modifiers}
|
33
|
+
*/
|
34
|
+
removeModifiersFromMarkup: function (escaped) {
|
35
|
+
return escaped.replace(/(\sclass=('|"){\$modifiers}('|")|\s{\$modifiers})/g, '')
|
36
|
+
},
|
50
37
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
38
|
+
/**
|
39
|
+
* Get parser for a file which will extract "@variable {name} - {description}"
|
40
|
+
*
|
41
|
+
* @param {object} file - The file to extract the variable values from
|
42
|
+
* @return {function} A DSS parser
|
43
|
+
*/
|
44
|
+
variableDssParser: function () {
|
45
|
+
const fileVariablesRx = /^[$|@]([a-zA-Z0-9_-]+):([^;]+);/gim
|
46
|
+
const lineSplitRx = /(( - )+)/
|
47
|
+
var fileVariables = {}
|
48
|
+
var variables = {}
|
49
|
+
var match
|
50
|
+
var hash
|
51
|
+
var tokens
|
52
|
+
var name
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
return function (i, line, block, css) {
|
55
|
+
hash = crypto.createHash('md5').update(css).digest('hex')
|
56
|
+
if (!fileVariables[hash]) {
|
57
|
+
while ((match = fileVariablesRx.exec(css)) !== null) {
|
58
|
+
variables[match[1].trim()] = match[2].trim()
|
59
|
+
}
|
60
|
+
fileVariables[hash] = variables
|
61
|
+
}
|
65
62
|
|
66
63
|
// Extract name and any delimiter with description
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
tokens = line.split(lineSplitRx, 2)
|
65
|
+
name = tokens[0].trim()
|
66
|
+
if (variables.hasOwnProperty(name)) {
|
67
|
+
return {
|
68
|
+
name: name,
|
72
69
|
// Description is line with name and any delimiter replaced
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
/**
|
80
|
-
* Read over multiple description lines and return a markdown version
|
81
|
-
*
|
82
|
-
* @param {number} i - line number
|
83
|
-
* @param {string} line - Line matching parser
|
84
|
-
* @param {string} block - Entire block of text matching
|
85
|
-
* @return {string} A markdown version of the description
|
86
|
-
*/
|
87
|
-
descriptionDssParser: function(i, line, block){
|
88
|
-
var nextParserIndex = block.indexOf("@", i+1),
|
89
|
-
markupLength = nextParserIndex > -1 ? nextParserIndex - i : block.length,
|
90
|
-
markup = block.split('')
|
91
|
-
.splice(i, markupLength)
|
92
|
-
.join('')
|
93
|
-
.replace(/\n/g, '\n\n')
|
94
|
-
.replace(/@description/, '');
|
70
|
+
description: line.replace(tokens.join(''), ''),
|
71
|
+
value: variables[name]
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
},
|
95
76
|
|
96
|
-
|
97
|
-
|
77
|
+
/**
|
78
|
+
* Read over multiple description lines and return a markdown version
|
79
|
+
*
|
80
|
+
* @param {number} i - line number
|
81
|
+
* @param {string} line - Line matching parser
|
82
|
+
* @param {string} block - Entire block of text matching
|
83
|
+
* @return {string} A markdown version of the description
|
84
|
+
*/
|
85
|
+
descriptionDssParser: function (i, line, block) {
|
86
|
+
var nextParserIndex = block.indexOf('@', i + 1)
|
87
|
+
var markupLength = nextParserIndex > -1 ? nextParserIndex - i : block.length
|
88
|
+
var markup = block.split('')
|
89
|
+
.splice(i, markupLength)
|
90
|
+
.join('')
|
91
|
+
.replace(/\n/g, '\n\n')
|
92
|
+
.replace(/@description/, '')
|
98
93
|
|
99
|
-
|
100
|
-
|
101
|
-
*
|
102
|
-
* @param {number} i - line number
|
103
|
-
* @param {string} line - Line matching parser
|
104
|
-
* @param {string} block - Entire block of text matching
|
105
|
-
* @return {string} JavaScript code snipper
|
106
|
-
*/
|
107
|
-
javascriptParser: function(i, line, block){
|
108
|
-
var nextParserIndex = block.indexOf("@", i+1),
|
109
|
-
markupLength = nextParserIndex > -1 ? nextParserIndex - i : block.length,
|
110
|
-
markup = block.split('')
|
111
|
-
.splice(i, markupLength)
|
112
|
-
.join('')
|
113
|
-
.replace(/@javascript/, '');
|
94
|
+
return marked(markup)
|
95
|
+
},
|
114
96
|
|
115
|
-
|
116
|
-
|
117
|
-
|
97
|
+
/**
|
98
|
+
* Read over multiple lines and return a javascript code snippet
|
99
|
+
*
|
100
|
+
* @param {number} i - line number
|
101
|
+
* @param {string} line - Line matching parser
|
102
|
+
* @param {string} block - Entire block of text matching
|
103
|
+
* @return {string} JavaScript code snipper
|
104
|
+
*/
|
105
|
+
javascriptParser: function (i, line, block) {
|
106
|
+
var nextParserIndex = block.indexOf('@', i + 1)
|
107
|
+
var markupLength = nextParserIndex > -1 ? nextParserIndex - i : block.length
|
108
|
+
var markup = block.split('')
|
109
|
+
.splice(i, markupLength)
|
110
|
+
.join('')
|
111
|
+
.replace(/@javascript/, '')
|
112
|
+
|
113
|
+
return escaped(markup)
|
114
|
+
}
|
115
|
+
}
|
data/grunt/modules/file.js
CHANGED
@@ -1,26 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
var grunt = require('grunt');
|
1
|
+
const grunt = require('grunt')
|
4
2
|
|
5
3
|
module.exports = {
|
6
|
-
writeFile: function(file, dest, message){
|
7
|
-
var outputType = 'created'
|
8
|
-
|
4
|
+
writeFile: function (file, dest, message) {
|
5
|
+
var outputType = 'created'
|
6
|
+
var oldFile = null
|
9
7
|
|
10
8
|
if (grunt.file.exists(dest)) {
|
11
|
-
outputType = 'overwritten'
|
12
|
-
oldFile = grunt.file.read(dest)
|
9
|
+
outputType = 'overwritten'
|
10
|
+
oldFile = grunt.file.read(dest)
|
13
11
|
}
|
14
12
|
|
15
13
|
if (oldFile !== file) {
|
16
|
-
grunt.file.write(dest, file)
|
17
|
-
grunt.log.writeln('✓ '+ message +' ' + outputType + ' at: ' + grunt.log.wordlist([dest], {color: 'cyan'}))
|
14
|
+
grunt.file.write(dest, file)
|
15
|
+
grunt.log.writeln('✓ ' + message + ' ' + outputType + ' at: ' + grunt.log.wordlist([dest], {color: 'cyan'}))
|
18
16
|
} else {
|
19
|
-
grunt.log.writeln('‣ '+ message +' unchanged')
|
17
|
+
grunt.log.writeln('‣ ' + message + ' unchanged')
|
20
18
|
}
|
21
19
|
},
|
22
20
|
|
23
|
-
isMarkdown: function(extension){
|
24
|
-
return extension ===
|
21
|
+
isMarkdown: function (extension) {
|
22
|
+
return extension === '.md'
|
25
23
|
}
|
26
24
|
}
|
@@ -1,24 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
var cheerio = require('cheerio');
|
1
|
+
const cheerio = require('cheerio')
|
4
2
|
|
5
3
|
module.exports = {
|
6
|
-
extractSubNav: function(content){
|
7
|
-
var $ = cheerio.load(content)
|
8
|
-
|
4
|
+
extractSubNav: function (content) {
|
5
|
+
var $ = cheerio.load(content)
|
6
|
+
var contents = []
|
9
7
|
|
10
|
-
function buildHashOfContents(i, el) {
|
11
|
-
contents.push({name: $(el).text(), link: $(el).attr('href')})
|
8
|
+
function buildHashOfContents (i, el) {
|
9
|
+
contents.push({name: $(el).text(), link: $(el).attr('href')})
|
12
10
|
}
|
13
11
|
|
14
|
-
$('ul.table-of-contents a').map(buildHashOfContents)
|
15
|
-
return contents
|
12
|
+
$('ul.table-of-contents a').map(buildHashOfContents)
|
13
|
+
return contents
|
16
14
|
},
|
17
15
|
|
18
|
-
removeSubNav: function(content){
|
19
|
-
var $ = cheerio.load(content)
|
16
|
+
removeSubNav: function (content) {
|
17
|
+
var $ = cheerio.load(content)
|
20
18
|
|
21
|
-
$('ul.table-of-contents').remove()
|
22
|
-
return $.html()
|
19
|
+
$('ul.table-of-contents').remove()
|
20
|
+
return $.html()
|
23
21
|
}
|
24
22
|
}
|
data/grunt/modules/templates.js
CHANGED
@@ -1,59 +1,57 @@
|
|
1
|
-
|
1
|
+
const handlebars = require('handlebars')
|
2
|
+
const humanize = require('underscore.string/humanize')
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
if(size < 1024) return size;
|
8
|
-
var i = Math.floor( Math.log(size) / Math.log(1024) );
|
9
|
-
return new handlebars.SafeString( ( size / Math.pow(1024, i) ).toFixed(2) * 1 + '<span> ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]+'</span>');
|
4
|
+
function humanFileSize (size) {
|
5
|
+
if (size < 1024) return size
|
6
|
+
var i = Math.floor(Math.log(size) / Math.log(1024))
|
7
|
+
return new handlebars.SafeString((size / Math.pow(1024, i)).toFixed(2) * 1 + '<span> ' + ['B', 'kB', 'MB', 'GB', 'TB'][i] + '</span>')
|
10
8
|
};
|
11
9
|
|
12
10
|
module.exports = {
|
13
|
-
registerHelpers: function(){
|
14
|
-
handlebars.registerHelper(
|
15
|
-
return new handlebars.SafeString(humanize(name))
|
16
|
-
})
|
11
|
+
registerHelpers: function () {
|
12
|
+
handlebars.registerHelper('humanize', function (name, options) {
|
13
|
+
return new handlebars.SafeString(humanize(name))
|
14
|
+
})
|
17
15
|
|
18
|
-
handlebars.registerHelper('json', function(context) {
|
19
|
-
|
20
|
-
})
|
16
|
+
handlebars.registerHelper('json', function (context) {
|
17
|
+
return JSON.stringify(context)
|
18
|
+
})
|
21
19
|
|
22
|
-
handlebars.registerHelper(
|
20
|
+
handlebars.registerHelper('partial', function (name, options) {
|
23
21
|
// Get the partial with the given name. This is a string.
|
24
|
-
var partial = handlebars.partials[name]
|
22
|
+
var partial = handlebars.partials[name]
|
25
23
|
|
26
24
|
// Return empty string if the partial is not defined
|
27
|
-
if (!partial) return
|
25
|
+
if (!partial) return ''
|
28
26
|
// Compile and call the partial with this as context
|
29
|
-
return new handlebars.SafeString(handlebars.compile(partial)(this))
|
30
|
-
})
|
27
|
+
return new handlebars.SafeString(handlebars.compile(partial)(this))
|
28
|
+
})
|
31
29
|
|
32
|
-
handlebars.registerHelper('activeClass', function(name, attribute, context) {
|
33
|
-
var active = ''
|
34
|
-
if(name === context.data.root.page[attribute]) {
|
30
|
+
handlebars.registerHelper('activeClass', function (name, attribute, context) {
|
31
|
+
var active = ''
|
32
|
+
if (name === context.data.root.page[attribute]) {
|
35
33
|
active = 'active'
|
36
34
|
}
|
37
|
-
return new handlebars.SafeString(active)
|
38
|
-
})
|
35
|
+
return new handlebars.SafeString(active)
|
36
|
+
})
|
39
37
|
|
40
|
-
handlebars.registerHelper('isActive', function(name, attribute, context) {
|
41
|
-
if(name === attribute){
|
42
|
-
return context.fn(this)
|
38
|
+
handlebars.registerHelper('isActive', function (name, attribute, context) {
|
39
|
+
if (name === attribute) {
|
40
|
+
return context.fn(this)
|
43
41
|
}
|
44
|
-
return context.inverse(this)
|
45
|
-
})
|
42
|
+
return context.inverse(this)
|
43
|
+
})
|
46
44
|
|
47
|
-
handlebars.registerHelper('humanFileSize', function(size, context) {
|
48
|
-
return new handlebars.SafeString(humanFileSize(size))
|
49
|
-
})
|
45
|
+
handlebars.registerHelper('humanFileSize', function (size, context) {
|
46
|
+
return new handlebars.SafeString(humanFileSize(size))
|
47
|
+
})
|
50
48
|
|
51
|
-
handlebars.registerHelper('number', function(number, context) {
|
52
|
-
return new handlebars.SafeString(number.toPrecision(2))
|
53
|
-
})
|
49
|
+
handlebars.registerHelper('number', function (number, context) {
|
50
|
+
return new handlebars.SafeString(number.toPrecision(2))
|
51
|
+
})
|
54
52
|
|
55
|
-
handlebars.registerHelper('classSanitizer', function(klass){
|
56
|
-
return new handlebars.SafeString(klass.split('.')[1])
|
57
|
-
})
|
53
|
+
handlebars.registerHelper('classSanitizer', function (klass) {
|
54
|
+
return new handlebars.SafeString(klass.split('.')[1])
|
55
|
+
})
|
58
56
|
}
|
59
|
-
}
|
57
|
+
}
|
data/grunt/tasks/browser-sync.js
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
-
|
1
|
+
'use strict'
|
2
2
|
|
3
|
-
module.exports = function(grunt){
|
4
|
-
var browserSync = require(
|
5
|
-
|
6
|
-
grunt.registerTask("browserSync-init", function() {
|
7
|
-
var done = this.async();
|
8
|
-
browserSync({
|
9
|
-
server: "./docs",
|
10
|
-
notify: false
|
11
|
-
}, function (err, bs) {
|
12
|
-
done();
|
13
|
-
});
|
14
|
-
});
|
3
|
+
module.exports = function (grunt) {
|
4
|
+
var browserSync = require('browser-sync')
|
15
5
|
|
16
|
-
grunt.registerTask(
|
17
|
-
|
18
|
-
|
6
|
+
grunt.registerTask('browserSync-init', function () {
|
7
|
+
var done = this.async()
|
8
|
+
browserSync({
|
9
|
+
server: './docs',
|
10
|
+
notify: false
|
11
|
+
}, function (err, bs) {
|
12
|
+
if (err) {
|
13
|
+
console.log(err)
|
14
|
+
}
|
15
|
+
|
16
|
+
done()
|
17
|
+
})
|
18
|
+
})
|
19
|
+
|
20
|
+
grunt.registerTask('browserSync-inject', function () {
|
21
|
+
browserSync.reload(['docs/css/main.css'])
|
22
|
+
})
|
19
23
|
}
|
data/grunt/tasks/builder.js
CHANGED
@@ -1,72 +1,67 @@
|
|
1
|
-
|
1
|
+
const handlebars = require('handlebars')
|
2
|
+
const async = require('async')
|
3
|
+
const path = require('path')
|
4
|
+
const template = require('../modules/templates')
|
5
|
+
const fileHelper = require('../modules/file')
|
6
|
+
const slugify = require('underscore.string/slugify')
|
2
7
|
|
3
|
-
module.exports = function(grunt){
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
var handlebars = require('handlebars'),
|
8
|
-
async = require('async'),
|
9
|
-
path = require('path'),
|
10
|
-
fs = require('fs'),
|
11
|
-
template = require('../modules/templates'),
|
12
|
-
fileHelper = require('../modules/file'),
|
13
|
-
slugify = require("underscore.string/slugify"),
|
14
|
-
promise = this.async(),
|
15
|
-
files = this.files;
|
8
|
+
module.exports = function (grunt) {
|
9
|
+
grunt.registerMultiTask('builder', function () {
|
10
|
+
var promise = this.async()
|
11
|
+
var files = this.files
|
16
12
|
|
17
13
|
var options = this.options({
|
18
14
|
templates: './styleguide/**/*.tpl'
|
19
|
-
})
|
15
|
+
})
|
20
16
|
|
21
17
|
async.waterfall([
|
22
|
-
|
23
|
-
|
24
|
-
], completeTask)
|
18
|
+
init,
|
19
|
+
generateStyleguide
|
20
|
+
], completeTask)
|
25
21
|
|
26
|
-
function completeTask(){
|
27
|
-
promise()
|
22
|
+
function completeTask () {
|
23
|
+
promise()
|
28
24
|
}
|
29
25
|
|
30
|
-
function init(callback){
|
31
|
-
template.registerHelpers()
|
32
|
-
generateTemplates(options.templates)
|
33
|
-
callback(null)
|
26
|
+
function init (callback) {
|
27
|
+
template.registerHelpers()
|
28
|
+
generateTemplates(options.templates)
|
29
|
+
callback(null)
|
34
30
|
}
|
35
31
|
|
36
|
-
function generateStyleguide(callback){
|
37
|
-
files.forEach(function(file){
|
38
|
-
|
39
|
-
|
40
|
-
generatePages(datum, datum.pages, dest)
|
41
|
-
})
|
42
|
-
callback(null, 'done')
|
32
|
+
function generateStyleguide (callback) {
|
33
|
+
files.forEach(function (file) {
|
34
|
+
const dest = file.dest
|
35
|
+
const datum = grunt.file.readJSON(file.src[0])
|
36
|
+
generatePages(datum, datum.pages, dest)
|
37
|
+
})
|
38
|
+
callback(null, 'done')
|
43
39
|
}
|
44
40
|
|
45
|
-
function generatePages(data, pages, dest){
|
46
|
-
pages.map(function(page){
|
47
|
-
|
41
|
+
function generatePages (data, pages, dest) {
|
42
|
+
pages.map(function (page) {
|
43
|
+
const model = {
|
48
44
|
project: data.project,
|
49
45
|
navigation: data.navigation,
|
50
46
|
page: page,
|
51
47
|
pages: data.pages
|
52
|
-
}
|
53
|
-
|
54
|
-
|
48
|
+
}
|
49
|
+
const outputFilePath = dest + slugify(page.section) + '/' + page.page
|
50
|
+
const template = handlebars.compile(grunt.file.read(page.template))(model)
|
55
51
|
|
56
|
-
fileHelper.writeFile(template, outputFilePath,
|
57
|
-
})
|
52
|
+
fileHelper.writeFile(template, outputFilePath, 'Build')
|
53
|
+
})
|
58
54
|
}
|
59
55
|
|
60
|
-
function generateTemplates(templatePath){
|
61
|
-
var templates = {}
|
56
|
+
function generateTemplates (templatePath) {
|
57
|
+
var templates = {}
|
62
58
|
|
63
|
-
grunt.file.expand(templatePath).forEach(function(file){
|
64
|
-
var templateName = path.basename(file, '.tpl')
|
65
|
-
templates[templateName] = grunt.file.read(file)
|
66
|
-
})
|
59
|
+
grunt.file.expand(templatePath).forEach(function (file) {
|
60
|
+
var templateName = path.basename(file, '.tpl')
|
61
|
+
templates[templateName] = grunt.file.read(file)
|
62
|
+
})
|
67
63
|
|
68
|
-
handlebars.registerPartial(templates)
|
64
|
+
handlebars.registerPartial(templates)
|
69
65
|
}
|
70
|
-
|
71
|
-
});
|
66
|
+
})
|
72
67
|
}
|