Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
07309edc
Commit
07309edc
authored
11 years ago
by
Chris Rebert
Browse files
Options
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
docs/assets/js/customizer.js
+42
-34
docs/assets/js/customizer.js
with
42 additions
and
34 deletions
+42
-34
docs/assets/js/customizer.js
+
42
-
34
View file @
07309edc
...
@@ -173,20 +173,55 @@ window.onload = function () { // wait for load in a dumb way because B-0
...
@@ -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.
// in which they appear in the file.
function
bootstrap
LessFilenames
()
{
function
included
LessFilenames
(
lessFilename
)
{
var
IMPORT_REGEX
=
/^@import
\"(
.*
?)\"
;$/
var
IMPORT_REGEX
=
/^@import
\"(
.*
?)\"
;$/
var
bootstrapL
essLines
=
__less
[
'
bootstrap.less
'
].
split
(
'
\n
'
)
var
l
essLines
=
__less
[
lessFilename
].
split
(
'
\n
'
)
for
(
var
i
=
0
,
imports
=
[];
i
<
bootstrapL
essLines
.
length
;
i
++
)
{
for
(
var
i
=
0
,
imports
=
[];
i
<
l
essLines
.
length
;
i
++
)
{
var
match
=
IMPORT_REGEX
.
exec
(
bootstrapL
essLines
[
i
])
var
match
=
IMPORT_REGEX
.
exec
(
l
essLines
[
i
])
if
(
match
)
imports
.
push
(
match
[
1
])
if
(
match
)
imports
.
push
(
match
[
1
])
}
}
return
imports
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
()
{
function
generateCSS
()
{
var
oneChecked
=
false
var
oneChecked
=
false
var
lessFileIncludes
=
{}
var
lessFileIncludes
=
{}
...
@@ -202,43 +237,16 @@ window.onload = function () { // wait for load in a dumb way because B-0
...
@@ -202,43 +237,16 @@ window.onload = function () { // wait for load in a dumb way because B-0
var
result
=
{}
var
result
=
{}
var
vars
=
{}
var
vars
=
{}
var
css
=
''
$
(
'
#less-variables-section input
'
)
$
(
'
#less-variables-section input
'
)
.
each
(
function
()
{
.
each
(
function
()
{
$
(
this
).
val
()
&&
(
vars
[
$
(
this
).
prev
().
text
()]
=
$
(
this
).
val
())
$
(
this
).
val
()
&&
(
vars
[
$
(
this
).
prev
().
text
()]
=
$
(
this
).
val
())
})
})
$
.
each
(
bootstrapLessFilenames
(),
function
(
index
,
filename
)
{
var
bsLessSource
=
generateLESS
(
'
bootstrap.less
'
,
lessFileIncludes
,
vars
)
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
try
{
try
{
var
parser
=
new
less
.
Parser
({
compileLESS
(
bsLessSource
,
'
bootstrap
'
,
result
)
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
})
}
})
}
catch
(
err
)
{
}
catch
(
err
)
{
return
showError
(
'
<strong>Ruh roh!</strong> Could not parse less files.
'
,
err
)
return
showError
(
'
<strong>Ruh roh!</strong> Could not parse less files.
'
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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