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

urls stored in variables - a few issues #26

Closed
muszek opened this issue May 13, 2010 · 10 comments
Closed

urls stored in variables - a few issues #26

muszek opened this issue May 13, 2010 · 10 comments

Comments

@muszek
Copy link

muszek commented May 13, 2010

It's quite possible that I simply don't know how to achieve what I want.

I was trying to hold background url in a variable. Couldn't do so, because:

One. I can't store a string with a colon (:) without enquoting the string.
@url: http://example.com;
div {
something: @url;
}

makes lessc run indefinitely (it just doesn't stop running)

Two. when I enquote the string (with either single or double quotation marks):
@url: "http://example.com";
div {
something: @url;
}
quotation marks are printed when I use this var
muszek@bobek:~/www/fooba/webroot/css$ ./less.sh test
div {
something: "http://example.com";
}

Three. finally, I can't seem to concatenate strings
@url: "http://example.com/a.png";
div {
background-url: url(@url);
}
turns to
div {
background-url: url(@url);
}
I tried different approaches, none of them worked. Is it possible to concatenate strings? It's very handy, for example in cases when you keep a path to images directory in one variable.

@cloudhead
Copy link
Member

Hey, I might have something just for you: try the escape function:

foo: e("hello:world");

Output:

foo: hello:world;

@cloudhead
Copy link
Member

There's also a format function:

@var: "world";
%("hello %s", @var);

Output

"hello world"

And they can be used together.

@muszek
Copy link
Author

muszek commented May 13, 2010

Thanks
How about string concatenation?
Example scenario (pseudo code):
.transparent-background(@opacity-level: 5) {
background-image: url(transparent-{@opacity-level}.png);
}

.transparent-background(2);

would output this:
background-image: url(transparent-2.png);

Is something similar implemented?

@muszek
Copy link
Author

muszek commented May 13, 2010

Thanks. And scratch the last post (started writing before you posted your 2nd)...

@cloudhead
Copy link
Member

great.

@jamesfoster
Copy link
Contributor

I don't understand why the compiler doesn't stop given your input. I get the following error:

Parse Error on line 2:
@url: http://example.com;
----^

we should catch all these when we add tests for error cases

@muszek
Copy link
Author

muszek commented May 13, 2010

While lessc is running, node takes 100% of my CPU.

I case there's a need for some data:
muszek@bobek:/www/fooba/webroot/css$ node --version
v0.1.91-35-g11f673e
muszek@bobek:
/www/fooba/webroot/css$ cat test.less
@url: http://example.com;
div {
something: @url;
}
muszek@bobek:~/www/fooba/webroot/css$ /home/muszek/scripts/less.js/bin/lessc test.less

@muszek
Copy link
Author

muszek commented May 13, 2010

cloudhead: I tried the format function:
.transparent-background(@opacity_level: 5) {
background: %('url(stripes/1x1t%s.png)', @opacity_level) repeat 0% 100%;
}
but the output of the function is enclosed in quotes as well:
.round1 .box_inner {
background: "url(stripes/1x1t5.png)" repeat 0% 100%;
}
is there any way to shake off the quotes?

@jamesfoster
Copy link
Contributor

e(%(...))

@muszek
Copy link
Author

muszek commented May 13, 2010

thanks. too bad there's another issue --> http://github.com/cloudhead/less.js/issues/issue/27

This issue was closed.
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

No branches or pull requests

3 participants