Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying custom variables when calling lessc and less.js. #1655

Merged
merged 1 commit into from
Nov 15, 2013

Conversation

chipx86
Copy link
Contributor

@chipx86 chipx86 commented Nov 14, 2013

Both lessc and less.js can now be provided with global variables that
all .less files will have immediate access to. This can be used to
provide, for example, a base path for an @import, signed URLs offering
temporary access to an image on S3, or anything else.

lessc has two new parameters, --global-var and --modify-var. Both take
a value of the form "varname=value". --global-var declares variables
immediately before the content of the .less files, and --modify-var
declares them after.

--global-var is used when rules, imports, or other variables will depend
on the provided variable.

--modify-var is used to override a variable declared within the .less
file.

less.js's equivalent for global variables is less.globalVars. This can
be set before loading less.js. There is no new equivalent to
--modify-var, as less.modifyVars can be used for that purpose.

Implements issue #731.

Both lessc and less.js can now be provided with global variables that
all .less files will have immediate access to. This can be used to
provide, for example, a base path for an @import, signed URLs offering
temporary access to an image on S3, or anything else.

lessc has two new parameters, --global-var and --modify-var. Both take
a value of the form "varname=value". --global-var declares variables
immediately before the content of the .less files, and --modify-var
declares them after.

--global-var is used when rules, imports, or other variables will depend
on the provided variable.

--modify-var is used to override a variable declared within the .less
file.

less.js's equivalent for global variables is less.globalVars. This can
be set before loading less.js. There is no new requivalent to
--modify-var, as less.modifyVars can be used for that purpose.
@CHH
Copy link

CHH commented Nov 14, 2013

👍

@@ -64,7 +71,7 @@ args = args.filter(function (arg) {
return false;
}

if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=([^\s]*))?$/i)) { arg = match[1] }
if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=(.*))?$/i)) { arg = match[1] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the meaning of this change? so it goes from all non whitespace to characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's to allow for whitespace characters. Otherwise, it's not possible to do expressions or any other sort of content containing whitespace. The whitespace will only end up in the value if explicitly quoted on the shell.

I looked through the other command line arguments and didn't see any that seemed they would be impacted by this change, and sys.argv already handles whitespace between arguments. I may have missed something important though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, makes sense.

@jonschlinkert
Copy link
Contributor

👍 !!!

lukeapage added a commit that referenced this pull request Nov 15, 2013
Support specifying custom variables when calling lessc and less.js.
@lukeapage lukeapage merged commit 8f4ef41 into less:master Nov 15, 2013
@seven-phases-max
Copy link
Member

Doh! Again wrong number... Sorry!

@jonschlinkert
Copy link
Contributor

@lukeapage ping, I'd love to see this moved into less.js core. Can you give pointers for a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants