Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
07309edc
Commit
07309edc
authored
Jan 07, 2014
by
Chris Rebert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make customizer compilation code more generic
parent
bf5017c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
34 deletions
+42
-34
docs/assets/js/customizer.js
docs/assets/js/customizer.js
+42
-34
No files found.
docs/assets/js/customizer.js
View file @
07309edc
...
...
@@ -173,20 +173,55 @@ window.onload = function () { // wait for load in a dumb way because B-0
}
}
// Returns an Array of @import'd filenames
from 'bootstrap.less'
in the order
// Returns an Array of @import'd filenames in the order
// in which they appear in the file.
function
bootstrapLessFilenames
(
)
{
function
includedLessFilenames
(
lessFilename
)
{
var
IMPORT_REGEX
=
/^@import
\"(
.*
?)\"
;$/
var
bootstrapLessLines
=
__less
[
'
bootstrap.less
'
].
split
(
'
\n
'
)
var
lessLines
=
__less
[
lessFilename
].
split
(
'
\n
'
)
for
(
var
i
=
0
,
imports
=
[];
i
<
bootstrapL
essLines
.
length
;
i
++
)
{
var
match
=
IMPORT_REGEX
.
exec
(
bootstrapL
essLines
[
i
])
for
(
var
i
=
0
,
imports
=
[];
i
<
l
essLines
.
length
;
i
++
)
{
var
match
=
IMPORT_REGEX
.
exec
(
l
essLines
[
i
])
if
(
match
)
imports
.
push
(
match
[
1
])
}
return
imports
}
function
generateLESS
(
lessFilename
,
lessFileIncludes
,
vars
)
{
var
lessSource
=
__less
[
lessFilename
]
$
.
each
(
includedLessFilenames
(
lessFilename
),
function
(
index
,
filename
)
{
var
fileInclude
=
lessFileIncludes
[
filename
]
// Files not explicitly unchecked are compiled into the final stylesheet.
// Core stylesheets like 'normalize.less' are not included in the form
// since disabling them would wreck everything, and so their 'fileInclude'
// will be 'undefined'.
if
(
fileInclude
||
(
fileInclude
==
null
))
lessSource
+=
__less
[
filename
]
// Custom variables are added after Bootstrap variables so the custom
// ones take precedence.
if
((
'
variables.less
'
===
filename
)
&&
vars
)
lessSource
+=
generateCustomCSS
(
vars
)
})
lessSource
=
lessSource
.
replace
(
/@import
[^\n]
*/gi
,
''
)
//strip any imports
return
lessSource
}
function
compileLESS
(
lessSource
,
baseFilename
,
intoResult
)
{
var
parser
=
new
less
.
Parser
({
paths
:
[
'
variables.less
'
,
'
mixins.less
'
],
optimization
:
0
,
filename
:
baseFilename
+
'
.css
'
}).
parse
(
lessSource
,
function
(
err
,
tree
)
{
if
(
err
)
{
return
showError
(
'
<strong>Ruh roh!</strong> Could not parse less files.
'
,
err
)
}
intoResult
[
baseFilename
+
'
.css
'
]
=
cw
+
tree
.
toCSS
()
intoResult
[
baseFilename
+
'
.min.css
'
]
=
cw
+
tree
.
toCSS
({
compress
:
true
})
})
}
function
generateCSS
()
{
var
oneChecked
=
false
var
lessFileIncludes
=
{}
...
...
@@ -202,43 +237,16 @@ window.onload = function () { // wait for load in a dumb way because B-0
var
result
=
{}
var
vars
=
{}
var
css
=
''
$
(
'
#less-variables-section input
'
)
.
each
(
function
()
{
$
(
this
).
val
()
&&
(
vars
[
$
(
this
).
prev
().
text
()]
=
$
(
this
).
val
())
})
$
.
each
(
bootstrapLessFilenames
(),
function
(
index
,
filename
)
{
var
fileInclude
=
lessFileIncludes
[
filename
]
// Files not explicitly unchecked are compiled into the final stylesheet.
// Core stylesheets like 'normalize.less' are not included in the form
// since disabling them would wreck everything, and so their 'fileInclude'
// will be 'undefined'.
if
(
fileInclude
||
(
fileInclude
==
null
))
css
+=
__less
[
filename
]
// Custom variables are added after Bootstrap variables so the custom
// ones take precedence.
if
((
'
variables.less
'
===
filename
)
&&
vars
)
css
+=
generateCustomCSS
(
vars
)
})
css
=
css
.
replace
(
/@import
[^\n]
*/gi
,
''
)
//strip any imports
var
bsLessSource
=
generateLESS
(
'
bootstrap.less
'
,
lessFileIncludes
,
vars
)
try
{
var
parser
=
new
less
.
Parser
({
paths
:
[
'
variables.less
'
,
'
mixins.less
'
],
optimization
:
0
,
filename
:
'
bootstrap.css
'
}).
parse
(
css
,
function
(
err
,
tree
)
{
if
(
err
)
{
return
showError
(
'
<strong>Ruh roh!</strong> Could not parse less files.
'
,
err
)
}
result
=
{
'
bootstrap.css
'
:
cw
+
tree
.
toCSS
(),
'
bootstrap.min.css
'
:
cw
+
tree
.
toCSS
({
compress
:
true
})
}
})
compileLESS
(
bsLessSource
,
'
bootstrap
'
,
result
)
}
catch
(
err
)
{
return
showError
(
'
<strong>Ruh roh!</strong> Could not parse less files.
'
,
err
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment