From 39861714a80b68cd42a2e2b812be53f0b0f6b70d Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 17 Oct 2013 19:52:16 -0700 Subject: Use JS & Jade to generate the customizer variables form HTML from variables.less; fixes #11095 also updates variables file organization (courtesy @mdo) --- docs/_includes/customizer-variables.html | 1684 ++++++++++++++++++++++++++++++ docs/assets/css/docs.css | 7 + docs/customize.html | 1365 +----------------------- docs/customizer-variables.jade | 18 + docs/grunt/bs-lessdoc-parser.js | 179 ++++ 5 files changed, 1889 insertions(+), 1364 deletions(-) create mode 100644 docs/_includes/customizer-variables.html create mode 100644 docs/customizer-variables.jade create mode 100644 docs/grunt/bs-lessdoc-parser.js (limited to 'docs') diff --git a/docs/_includes/customizer-variables.html b/docs/_includes/customizer-variables.html new file mode 100644 index 000000000..5093bd5f3 --- /dev/null +++ b/docs/_includes/customizer-variables.html @@ -0,0 +1,1684 @@ + + +

Colors

+

Gray and brand colors for use across Bootstrap.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Scaffolding

+
+
+ + +

Background color for <body>.

+
+
+ + +

Global text color on <body>.

+
+
+ + +

Global textual link color.

+
+
+ + +

Link hover color set via darken() function.

+
+
+

Typography

+

Font, line-height, and color for body text, headings, and more.

+
+
+ + +
+
+ + +
+
+ + +

Default monospace fonts for <code>, <kbd>, and <pre>.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +

Unit-less line-height for use in components like buttons.

+
+
+ + +

Computed "line-height" (font-size &times; line-height) for use with margin, padding, etc.

+
+
+ + +

By default, this inherits from the <body>.

+
+
+ + +
+
+ + +
+
+ + +
+
+

Components

+

Define common padding and border radius sizes and more. Values based on 14px text and 1.428 line-height (~20px to start).

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +

Global color for active items (e.g., navs or dropdowns).

+
+
+ + +

Global background color for active items (e.g., navs or dropdowns).

+
+
+ + +

Width of the border for generating carets that indicator dropdowns.

+
+
+ + +

Carets increase slightly in size for larger components.

+
+
+

Tables

+

Customizes the .table component with basic values, each used across all table variations.

+
+
+ + +

Padding for <th>s and <td>s.

+
+
+ + +

Padding for cells in .table-condensed.

+
+
+ + +

Default background color used for all tables.

+
+
+ + +

Background color used for .table-striped.

+
+
+ + +

Background color used for .table-hover.

+
+
+ + +
+
+ + +

Border color for table and cell borders.

+
+
+

Buttons

+

For each of Bootstrap's buttons, define text, background and border color.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Forms

+

+
+
+ + +

<input> background color

+
+
+ + +

<input disabled> background color

+
+
+ + +

Text color for <input>s

+
+
+ + +

<input> border color

+
+
+ + +

<input> border radius

+
+
+ + +

Border color for inputs on focus

+
+
+ + +

Placeholder text color

+
+
+ + +

Default .form-control height

+
+
+ + +

Large .form-control height

+
+
+ + +

Small .form-control height

+
+
+ + +
+
+ + +
+
+ + +

Background color for textual input addons

+
+
+ + +

Border color for textual input addons

+
+
+ +

Dropdown menu container and contents.

+
+
+ + +

Background for the dropdown menu.

+
+
+ + +

Dropdown menu border-color.

+
+
+ + +

Dropdown menu border-color for IE8.

+
+
+ + +

Divider color for between dropdown items.

+
+
+ + +

Dropdown link text color.

+
+
+ + +

Hover color for dropdown links.

+
+
+ + +

Hover background for dropdown links.

+
+
+ + +

Active dropdown menu item text color.

+
+
+ + +

Active dropdown menu item background color.

+
+
+ + +

Disabled dropdown menu item background color.

+
+
+ + +

Text color for headers within dropdown menus.

+
+
+ + +
+
+

Media queries breakpoints

+

Define the breakpoints at which your layout will change, adapting to different screen sizes.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Grid system

+

Define your custom responsive grid.

+
+
+ + +

Number of columns in the grid.

+
+
+ + +

Padding between columns. Gets divided in half for the left and right.

+
+
+ + +

Point at which the navbar becomes uncollapsed.

+
+
+ + +

Point at which the navbar begins collapsing.

+
+
+ +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +

+
+
+

Shared nav styles

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Tabs

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Pills

+
+
+ + +
+
+ + +
+
+ + +
+
+

Pagination

+

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Pager

+

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Jumbotron

+

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Form states and alerts

+

Define colors for form feedback states and, by default, alerts.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Tooltips

+

+
+
+ + +

Tooltip max width

+
+
+ + +

Tooltip text color

+
+
+ + +

Tooltip background color

+
+
+ + +
+
+ + +

Tooltip arrow width

+
+
+ + +

Tooltip arrow color

+
+
+

Popovers

+

+
+
+ + +

Popover body background color

+
+
+ + +

Popover maximum width

+
+
+ + +

Popover border color

+
+
+ + +

Popover fallback border color

+
+
+ + +

Popover title background color

+
+
+ + +

Popover arrow width

+
+
+ + +

Popover arrow color

+
+
+ + +

Popover outer arrow width

+
+
+ + +

Popover outer arrow color

+
+
+ + +

Popover outer arrow fallback color

+
+
+

Labels

+

+
+
+ + +

Default label background color

+
+
+ + +

Primary label background color

+
+
+ + +

Success label background color

+
+
+ + +

Info label background color

+
+
+ + +

Warning label background color

+
+
+ + +

Danger label background color

+
+
+ + +

Default label text color

+
+
+ + +

Default text color of a linked label

+
+
+

Modals

+

+
+
+ + +

Padding applied to the modal body

+
+
+ + +

Padding applied to the modal title

+
+
+ + +

Modal title line-height

+
+
+ + +

Background color of modal content area

+
+
+ + +

Modal content border color

+
+
+ + +

Modal content border color <strong>for IE8</strong>

+
+
+ + +

Modal backdrop background color

+
+
+ + +

Modal backdrop opacity

+
+
+ + +

Modal header border color

+
+
+ + +

Modal footer border color

+
+
+ + +
+
+ + +
+
+

Alerts

+

Define alert colors, border radius, and padding.

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Progress bars

+

+
+
+ + +

Background color of the whole progress component

+
+
+ + +

Progress bar text color

+
+
+ + +

Default progress bar color

+
+
+ + +

Success progress bar color

+
+
+ + +

Warning progress bar color

+
+
+ + +

Danger progress bar color

+
+
+ + +

Info progress bar color

+
+
+

List group

+

+
+
+ + +

Background color on .list-group-item

+
+
+ + +

.list-group-item border color

+
+
+ + +

List group border radius

+
+
+ + +

Background color of single list elements on hover

+
+
+ + +

Text color of active list elements

+
+
+ + +

Background color of active list elements

+
+
+ + +

Border color of active list elements

+
+
+ + +
+
+ + +
+
+ + +
+
+

Panels

+

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +

Border color for elements within panels

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Thumbnails

+

+
+
+ + +

Padding around the thumbnail image

+
+
+ + +

Thumbnail background color

+
+
+ + +

Thumbnail border color

+
+
+ + +

Thumbnail border radius

+
+
+ + +

Custom text color for thumbnail captions

+
+
+ + +

Padding around the thumbnail caption

+
+
+

Wells

+

+
+
+ + +
+
+ + +
+
+

Badges

+

+
+
+ + +
+
+ + +

Linked badge text color on hover

+
+
+ + +
+
+ + +

Badge text color in active nav link

+
+
+ + +

Badge background color in active nav link

+
+
+ + +
+
+ + +
+
+ +

+
+
+ + +
+
+ + +
+
+ + +

Breadcrumb background color

+
+
+ + +

Breadcrumb text color

+
+
+ + +

Text color of current page in the breadcrumb

+
+
+ + +

Textual separator for between breadcrumb elements

+
+
+ +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Close

+

+
+
+ + +
+
+ + +
+
+ + +
+
+

Code

+

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Type

+

+
+
+ + +

Text muted color

+
+
+ + +

Abbreviations and acronyms border color

+
+
+ + +

Headings small color

+
+
+ + +

Blockquote small color

+
+
+ + +

Blockquote border color

+
+
+ + +

Page header border color

+
+
+

Miscellaneous

+

+
+
+ + +

Horizontal line color.

+
+
+ + +

Horizontal offset for forms and lists.

+
+
+

Container sizes

+

Define the maximum width of .container for different screen sizes.

+
+
+ + +
+
+ + +

For @screen-sm-min and up.

+
+
+ + +
+
+ + +

For @screen-md-min and up.

+
+
+ + +
+
+ + +

For @screen-lg-min and up.

+
+
+ \ No newline at end of file diff --git a/docs/assets/css/docs.css b/docs/assets/css/docs.css index 4be2536aa..072f39b04 100644 --- a/docs/assets/css/docs.css +++ b/docs/assets/css/docs.css @@ -1161,6 +1161,13 @@ h1[id] { font-weight: normal; } +.bs-customizer-input { + float: left; + width: 33.333333%; + padding-left: 15px; + padding-right: 15px; +} + /* Downloads */ .bs-customize-download .btn-outline { padding: 20px; diff --git a/docs/customize.html b/docs/customize.html index bd095c63f..3f6987c4b 100644 --- a/docs/customize.html +++ b/docs/customize.html @@ -343,1370 +343,7 @@ lead: Customize Bootstrap's components, LESS variables, and jQuery plugins to ge

LESS variables

Customize LESS variables to define colors, sizes and more inside your custom CSS stylesheets.

- -

Basics

- - -

Color system

-
-
- - - - - - -
-
- - - - -
-
- - -

Body scaffolding

-
-
- - -

Background color for <body>.

- - -

Global text color on <body>.

-
-
- - -

Global textual link color

- - -

Link hover color set via darken() function

-
-
- - -

Typography

-
-
-

Generic font variables

- - -

Default sans-serif fonts.

- - -

Default serif fonts.

- - -

Default monospace fonts for <code> and <pre>.

- -

Base type styles

- - - - - - - - - - -
-
-

Heading font sizes

- - - - - - - - - - - - -
-
- - -

Headings

-
-
- - - - -
-
- - - - -
-
- - -

Code blocks

-
-
- - - - -
-
- - - - - - -
-
- - -

Media queries breakpoints

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- -

Layout and grid system

-
-
- - -

For @screen-sm-min and up.

-
-
- - -

For @screen-md-min and up.

-
-
-
- - -

For @screen-lg-min and up.

-
-
- -
-
- - -

Number of columns in the grid.

-
-
- - -

Padding between columns.

-
-
-
- - -

Point at which the navbar stops collapsing.

-
-
- - -

Components

- -

Padding

-
-
- - - - -
-
- - - - -
-
- - - - -
-
- -

Rounded corners

-
-
- - -
-
- - -
-
- - -
-
- -

Component active state

-
-
- - -

Global color for active items (e.g., navs or dropdowns)

-
-
- - -

Global background color for active items (e.g., navs or dropdowns)

-
-
- -

Carets

-
-
- - -
-
- - -
-
- - -

Buttons

-
-
- - -
-
- - -
-
-
-
-

Default

- - - - - - -

Primary

- - - - - - -

Info

- - - - - - -
-
-

Success

- - - - - - -

Warning

- - - - - - -

Danger

- - - - - - -
-
- - -

Form states and alerts

-
-
-

Success

- - - - - - -

Warning

- - - - - - -
-
-

Danger

- - - - - - -

Info

- - - - - - -
-
- - -

Alerts

- -

Base styles

-
-
- - -
-
- - -
-
- - -
-
- -
-
-

Warning

- - - - - - - -

Success

- - - - - - -
-
-

Danger

- - - - - - - -

Info

- - - - - - -
-
- - -

Navbar

- -

Base styles

-
-
- - - - -
-
- - - - -
-
- - -
-
- -
-
-

Default navbar

-

Basics

- - - - - - - -

Links

- - - - - - - - - - - - - - - -

Brand

- - - - - - - -

Toggle

- - - - - - -
- -
-

Inverted navbar

- -

Basics

- - - - - - - -

Links

- - - - - - - - - - - - - - - -

Brand

- - - - - - - -

Toggle

- - - - - - -
-
- - -

Nav

- -

Default nav

-
-
-

Common values

- - - - - - - - - - - - - -

Pills

- - - - -
-
-

Tabs

- - - - - - - - - - - - - - -
-
- - -

Tables

-
-
- - -

Default padding for <th>s and <td>s

- - -

Default padding cells in .table-condensed

-
-
- - -

Default background color used for all tables.

- - -

Background color used for .table-striped.

-
-
- - -

Background color used for .table-hover.

- - -

Border color for table and cell borders.

-
-
- - -

Forms

- -

Inputs

-
-
- - -

Text color for <input>s

- - -

<input> background color

-
-
- - -

<input> border color

- - -

<input> border radius

-
-
- - -

Placeholder text color

-
-
- -

Input states

-
-
- - -

Border color for inputs on focus

-
-
- - -

<input disabled> background color

-
-
- -

Input sizes

-
-
- - -

Default .form-control height

-
-
- - -

Large .form-control height

-
-
- - -

Small .form-control height

-
-
- -

Legend

-
-
- - -
-
- - -
-
- -

Input groups

-
-
- - -

Background color for textual input addons

-
-
- - -

Border color for textual input addons

-
-
- - -

Dropdowns

-
-
-

Dropdown menu

- - -

Dropdown menu background color

- - -

Dropdown menu border color

- - -

Dropdown menu border color for IE8

- - -

Indicator arrow for showing an element has a dropdown

- - -

Dropdown divider top border color

- - -

Text color for headers within dropdown menus

-
-
-

Dropdown items

- - -

Dropdown text color

- - - -

Hovered dropdown menu entry text color

- - -

Hovered dropdown menu entry background color

- - - -

Active dropdown menu entry text color

- - -

Active dropdown menu entry background color

- - - -

Disabled dropdown menu entry background color

-
-
- - -

Panels and wells

- -

Common panel styles

-
-
- - - - -

Border color for elements within panels

-
-
- - - - -
-
-

Contextual panel colors

-
-
-

Default

- - - - - - - -

Primary

- - - - - - - -

Success

- - - - - - -
-
-

Info

- - - - - - - -

Warning

- - - - - - - -

Danger

- - - - - - -
-
- -

Wells

- - - - - - -

Accordion

- - - - -

Badges

- -

Base styles

-
-
- - - - -
-
- - -
-
- - -
-
- -

States

-
-
- - -

Linked badge text color on hover

-
-
- - -

Badge text color in active nav link

-
-
- - -

Badge background color in active nav link

-
-
- - -

Breadcrumbs

-
-
- - -

Breadcrumb text color

- - -

Breadcrumb background color

-
-
- - -

Text color of current page in the breadcrumb

- - -

Textual separator for between breadcrumb elements

-
-
- -

Jumbotron

-
-
- - - - - - -
-
- - - - -
-
- - -

Modals

- -

Base modal

-
-
- - -

Padding applied to the modal body

-
-
- - -

Modal backdrop background color

-
-
- - -

Modal backdrop opacity

-
-
- -

Modal header and footer

-
-
- - -

Padding applied to the modal title

-
-
- - -

Modal title line-height

-
-
- - -

Modal header border color

- - -

Modal footer border color

-
-
- -

Modal content

-
-
- - -

Background color of modal content area

-
-
- - -

Modal content border color

-
-
- - -

Modal content border color for IE8

-
-
- - - -
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -

List group

- -

Base styles

-
-
- - -

Background color on .list-group-item

-
-
- - -

.list-group-item border color

-
-
- - -

List group border radius

-
-
- -

Hover and active states

-
-
- - -

Background color of single list elements on hover

-
-
-
-
- - -

Text color of active list elements

-
-
- - -

Background color of active list elements

-
-
- - -

Border color of active list elements

-
-
- - -

Thumbnails

- -

Base thumbnail

-
-
- - -

Padding around the thumbnail image

- - -

Thumbnail background color

-
-
- - -

Thumbnail border color

- - -

Thumbnail border radius

-
-
- -

Thumbnail captions

-
-
- - -

Padding around the thumbnail caption

-
-
- - -

Custom text color for thumbnail captions

-
-
- - -

Progress bars

- -

Shared styles

-
-
- - -

Background color of the whole progress component

-
-
- - -

Info progress bar text color

-
-
- - -

Info progress bar text shadow

-
-
- - -

Default progress bar color

-
-
- -

Contextual states

-
-
- - -

Success progress bar color

- - -

Info progress bar color

-
-
- - -

Warning progress bar color

- - -

Danger progress bar color

-
-
- - -

Pagination

- -

Default styles

-
-
- - -

Background color

-
-
- - -

Border color

-
-
- - -

Background hover color

-
-
- -

Disabled and active states

-
-
- - -

Disabled text color

-
-
- - -

Active background color

-
-
- - -

Active text color

-
-
- - -

Pager

-
-
- - -

Pager border radius

-
-
- - -

Pager disabled state color

-
-
- - -

Labels

-
-
- - -

Default label text color

-
-
- - -

Default text color of a linked label

-
-
- - -

Default label background color

-
-
- -
-
- - -

Primary label background color

- - -

Success label background color

-
-
- - -

Info label background color

- - -

Warning label background color

-
-
- - -

Danger label background color

-
-
- - -

Tooltips and popovers

- -

Tooltip

-
-
- - -

Tooltip text color

- - -

Tooltip background color

-
-
- - -

Tooltip arrow width

- - -

Tooltip arrow color

-
-
- - -

Tooltip max width

-
-
- -

Popovers

- -

Base styles

-
-
- - -

Popover body background color

- - -

Popover maximum width

-
-
- - -

Popover border color

- - -

Popover fallback border color

-
-
- - -

Popover title background color

-
-
- -

Popover arrows

-
-
- - -

Popover arrow width

-
-
- - -

Popover arrow color

-
-
-
-
- - -

Popover outer arrow width

-
-
- - -

Popover outer arrow color

-
-
- - -

Popover outer arrow fallback color

-
-
- - -

Close button

-
-
- - -
-
- - -
-
- - -
-
- - -

Type

-
-
- - -

Text muted color

-
-
- - -

Abbreviations and acronyms border color

-
-
- - -

Headings small color

-
-
- - -

Blockquote small color

-
-
- - -

Blockquote border color

-
-
- - -

Page header border color

-
-
- - -

Other

-
-
- - -

Horizontal line color

-
-
- - -

Horizontal offset for forms and lists

-
-
+ {% include customizer-variables.html %}
diff --git a/docs/customizer-variables.jade b/docs/customizer-variables.jade new file mode 100644 index 000000000..0d6c83b0f --- /dev/null +++ b/docs/customizer-variables.jade @@ -0,0 +1,18 @@ +// NOTE: DO NOT EDIT THE FOLLOWING SECTION DIRECTLY! It is autogenerated via the `build-customizer-vars-form` Grunt task using the customizer-variables.jade template. +each section in sections + if section.customizable + 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 +// 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 new file mode 100644 index 000000000..8c232d80c --- /dev/null +++ b/docs/grunt/bs-lessdoc-parser.js @@ -0,0 +1,179 @@ +/* jshint node: true */ + +var markdown = require('markdown').markdown; + +function markdown2html(markdownString) { + // the slice removes the

...

wrapper output by Markdown processor + return markdown.toHTML(markdownString.trim()).slice(3, -4); +} + + +/* +Mini-language: + //== This is a normal heading, which starts a section. Sections group variables together. + //## Optional description for the heading + + //** Optional description for the following variable. You **can** use Markdown in descriptions to discuss `` stuff. + @foo: #ffff; + + //-- This is a heading for a section whose variables shouldn't be customizable + + All other lines are ignored completely. +*/ + + +var CUSTOMIZABLE_HEADING = /^[/]{2}={2}(.*)$/; +var UNCUSTOMIZABLE_HEADING = /^[/]{2}-{2}(.*)$/; +var SECTION_DOCSTRING = /^[/]{2}#{2}(.*)$/; +var VAR_ASSIGNMENT = /^(@[a-zA-Z0-9_-]+):[ ]*([^ ;][^;]+);[ ]*$/; +var VAR_DOCSTRING = /^[/]{2}[*]{2}(.*)$/; + +function Section(heading, customizable) { + this.heading = heading.trim(); + this.id = this.heading.replace(/\s+/g, '-').toLowerCase(); + this.customizable = customizable; + this.docstring = null; + this.variables = []; + this.addVar = function (variable) { + this.variables.push(variable); + }; +} + +function VarDocstring(markdownString) { + this.html = markdown2html(markdownString); +} + +function SectionDocstring(markdownString) { + this.html = markdown2html(markdownString); +} + +function Variable(name, defaultValue) { + this.name = name; + this.defaultValue = defaultValue; + this.docstring = null; +} + +function Tokenizer(fileContent) { + this._lines = fileContent.split('\n'); + this._next = undefined; +} + +Tokenizer.prototype.unshift = function (token) { + if (this._next !== undefined) { + throw new Error('Attempted to unshift twice!'); + } + this._next = token; +}; + +Tokenizer.prototype._shift = function () { + // returning null signals EOF + // returning undefined means the line was ignored + if (this._next !== undefined) { + var result = this._next; + this._next = undefined; + return result; + } + if (this._lines.length <= 0) { + return null; + } + var line = this._lines.shift(); + var match = null; + match = CUSTOMIZABLE_HEADING.exec(line); + if (match !== null) { + return new Section(match[1], true); + } + match = UNCUSTOMIZABLE_HEADING.exec(line); + if (match !== null) { + return new Section(match[1], false); + } + match = SECTION_DOCSTRING.exec(line); + if (match !== null) { + return new SectionDocstring(match[1]); + } + match = VAR_DOCSTRING.exec(line); + if (match !== null) { + return new VarDocstring(match[1]); + } + var commentStart = line.lastIndexOf('//'); + var varLine = (commentStart === -1) ? line : line.slice(0, commentStart); + match = VAR_ASSIGNMENT.exec(varLine); + if (match !== null) { + return new Variable(match[1], match[2]); + } + return undefined; +}; + +Tokenizer.prototype.shift = function () { + while (true) { + var result = this._shift(); + if (result === undefined) { + continue; + } + return result; + } +}; + +function Parser(fileContent) { + this._tokenizer = new Tokenizer(fileContent); +} + +Parser.prototype.parseFile = function () { + var sections = []; + while (true) { + var section = this.parseSection(); + if (section === null) { + if (this._tokenizer.shift() !== null) { + throw new Error('Unexpected unparsed section of file remains!'); + } + return sections; + } + sections.push(section); + } +}; + +Parser.prototype.parseSection = function () { + var section = this._tokenizer.shift(); + if (section === null) { + return null; + } + if (!(section instanceof Section)) { + throw new Error('Expected section heading; got: ' + JSON.stringify(section)); + } + var docstring = this._tokenizer.shift(); + if (docstring instanceof SectionDocstring) { + section.docstring = docstring; + } + else { + this._tokenizer.unshift(docstring); + } + this.parseVars(section); + return section; +}; + +Parser.prototype.parseVars = function (section) { + while (true) { + var variable = this.parseVar(); + if (variable === null) { + return; + } + section.addVar(variable); + } +}; + +Parser.prototype.parseVar = function () { + var docstring = this._tokenizer.shift(); + if (!(docstring instanceof VarDocstring)) { + this._tokenizer.unshift(docstring); + docstring = null; + } + var variable = this._tokenizer.shift(); + if (variable instanceof Variable) { + variable.docstring = docstring; + return variable; + } + this._tokenizer.unshift(variable); + return null; +}; + + +module.exports = Parser; -- cgit v1.2.3