From db829f8620d7fb04b48adb5dd0ad297f0c930453 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Tue, 7 Jan 2014 21:43:12 -0800 Subject: [PATCH] add support for '//===' for

s in bs-lessdoc --- docs/_includes/customizer-variables.html | 4 +- docs/customizer-variables.jade | 25 +++++----- docs/grunt/bs-lessdoc-parser.js | 63 +++++++++++++++++++++--- less/variables.less | 2 +- 4 files changed, 72 insertions(+), 22 deletions(-) diff --git a/docs/_includes/customizer-variables.html b/docs/_includes/customizer-variables.html index 5093bd5f32..0b4429d721 100644 --- a/docs/_includes/customizer-variables.html +++ b/docs/_includes/customizer-variables.html @@ -726,9 +726,7 @@

-
-
-

Shared nav styles

+

Shared nav styles

diff --git a/docs/customizer-variables.jade b/docs/customizer-variables.jade index 0d6c83b0f1..19f3672b0b 100644 --- a/docs/customizer-variables.jade +++ b/docs/customizer-variables.jade @@ -4,15 +4,18 @@ each section in sections h2(id=section.id)= section.heading if section.docstring p!= section.docstring.html - div.row - each variable in section.variables - div.bs-customizer-input - label(for="input-" + variable.name)= variable.name - input.form-control( - id="input-" + variable.name - type="text" - value=variable.defaultValue - data-var=variable.name) - if variable.docstring - p.help-block!= variable.docstring.html + each subsection in section.subsections + if subsection.heading + h3(id=subsection.id)= subsection.heading + div.row + each variable in subsection.variables + div.bs-customizer-input + label(for="input-" + variable.name)= variable.name + input.form-control( + id="input-" + variable.name + type="text" + value=variable.defaultValue + data-var=variable.name) + if variable.docstring + p.help-block!= variable.docstring.html // NOTE: DO NOT EDIT THE PRECEDING SECTION DIRECTLY! It is autogenerated via the `build-customizer-vars-form` Grunt task using the customizer-variables.jade template. diff --git a/docs/grunt/bs-lessdoc-parser.js b/docs/grunt/bs-lessdoc-parser.js index 8c232d80cc..f4da4238ee 100644 --- a/docs/grunt/bs-lessdoc-parser.js +++ b/docs/grunt/bs-lessdoc-parser.js @@ -24,6 +24,7 @@ Mini-language: var CUSTOMIZABLE_HEADING = /^[/]{2}={2}(.*)$/; var UNCUSTOMIZABLE_HEADING = /^[/]{2}-{2}(.*)$/; +var SUBSECTION_HEADING = /^[/]{2}={3}(.*)$/; var SECTION_DOCSTRING = /^[/]{2}#{2}(.*)$/; var VAR_ASSIGNMENT = /^(@[a-zA-Z0-9_-]+):[ ]*([^ ;][^;]+);[ ]*$/; var VAR_DOCSTRING = /^[/]{2}[*]{2}(.*)$/; @@ -33,12 +34,23 @@ function Section(heading, customizable) { this.id = this.heading.replace(/\s+/g, '-').toLowerCase(); this.customizable = customizable; this.docstring = null; - this.variables = []; - this.addVar = function (variable) { - this.variables.push(variable); - }; + this.subsections = []; } +Section.prototype.addSubSection = function (subsection) { + this.subsections.push(subsection); +} + +function SubSection(heading) { + this.heading = heading.trim(); + this.id = this.heading.replace(/\s+/g, '-').toLowerCase(); + this.variables = []; +} + +SubSection.prototype.addVar = function (variable) { + this.variables.push(variable); +}; + function VarDocstring(markdownString) { this.html = markdown2html(markdownString); } @@ -78,6 +90,10 @@ Tokenizer.prototype._shift = function () { } var line = this._lines.shift(); var match = null; + match = SUBSECTION_HEADING.exec(line); + if (match !== null) { + return new SubSection(match[1]); + } match = CUSTOMIZABLE_HEADING.exec(line); if (match !== null) { return new Section(match[1], true); @@ -146,17 +162,50 @@ Parser.prototype.parseSection = function () { else { this._tokenizer.unshift(docstring); } - this.parseVars(section); + this.parseSubSections(section); + return section; }; -Parser.prototype.parseVars = function (section) { +Parser.prototype.parseSubSections = function (section) { + while (true) { + var subsection = this.parseSubSection(); + if (subsection === null) { + if (section.subsections.length === 0) { + // Presume an implicit initial subsection + subsection = new SubSection(''); + this.parseVars(subsection); + } + else { + break; + } + } + section.addSubSection(subsection); + } + + if (section.subsections.length === 1 && !(section.subsections[0].heading) && section.subsections[0].variables.length === 0) { + // Ignore lone empty implicit subsection + section.subsections = []; + } +}; + +Parser.prototype.parseSubSection = function () { + var subsection = this._tokenizer.shift(); + if (subsection instanceof SubSection) { + this.parseVars(subsection); + return subsection; + } + this._tokenizer.unshift(subsection); + return null; +}; + +Parser.prototype.parseVars = function (subsection) { while (true) { var variable = this.parseVar(); if (variable === null) { return; } - section.addVar(variable); + subsection.addVar(variable); } }; diff --git a/less/variables.less b/less/variables.less index 244b2309c4..2bb443a6ca 100644 --- a/less/variables.less +++ b/less/variables.less @@ -366,7 +366,7 @@ // //## -//== Shared nav styles +//=== Shared nav styles @nav-link-padding: 10px 15px; @nav-link-hover-bg: @gray-lighter;