Giter Site home page Giter Site logo

Comments (7)

akhleung avatar akhleung commented on August 20, 2024

Good catch! The problem is specifically that conditionals aren't allowed inside namespaced properties. I'll fix this soon. Thanks!

from libsass.

akhleung avatar akhleung commented on August 20, 2024

Oh, I should also point out that replacing the background { ... } block with the following should work (assuming that the is-url function is implemented in SassScript, of course):

background-image: if(is-url($img), $img, image-url($img));
background: {
  repeat: no-repeat;
  position: $x $y;
}

from libsass.

mingodad avatar mingodad commented on August 20, 2024

After playing a bit with the code I tried this modification but it now gives another error:

It seems that this parser is generated by hand. How it works ?
If some explanation about of the logic of this parser is provided it can allow other people to help improve it, I plan to integrate a lua interpreter on it and knowing a bit how it is supposed to work will make things easier.

Node Document::parse_propset()
{
lex< identifier >();
Node property_segment(context.new_Node(Node::identifier, path, line, lexed));
lex< exactly<':'> >();
lex< exactly<'{'> >();
Node block(context.new_Node(Node::block, path, line, 1));
while (!lex< exactly<'}'> >()) {
if (peek< sequence< identifier, optional_spaces, exactly<':'>, optional_spaces, exactly<'{'> > >(position)) {
block << parse_propset();
}
///////new code start
else if(peek< exactly<'@'> >()) {
block << parse_block(block);
}
//////new code end
else {
block << parse_rule();
lex< exactly<';'> >();
}
}
if (block.empty()) throw_syntax_error("namespaced property cannot be empty");
Node propset(context.new_Node(Node::propset, path, line, 2));
propset << property_segment;
propset << block;
return propset;
}

from libsass.

akhleung avatar akhleung commented on August 20, 2024

Yeah, the parser is hand-written and somewhat complex, and the formal syntax of Sass itself is fairly complicated too. Documenting the whole thing isn't really feasible for me at the moment, but if you can tell me how you want to integrate Lua and what you want to do with it, I may be able to explain some of the relevant LibSass components.

(Incidentally, Lua is one of my favorite langauges, so I appreciate your interest in integrating it with LibSass!)

from libsass.

mingodad avatar mingodad commented on August 20, 2024

My idea is to be able to also create functions with lua to be used inside scss probably something like:

@-lua {
--any lua code here
--maybe having a global object sass where we can create new functions on it
--that will be searched when an identifier is not found elsewhere
function sass:resize_image(img_name, new_size)
os.execute("imagemagick ...")
...
end
}

.menu {
background-image : @include resize_image('some_image', 30px);
}

from libsass.

akhleung avatar akhleung commented on August 20, 2024

Hmm, rather than introduce special syntax, a better way might be to introduce a new built-in Sass function that takes a Lua source string as an argument. Check out functions.cpp for the set of built-in Sass functions. They're also declared in functions.hpp and registered in context.cpp.

You could define the function to be used as follows:

$x: something();
$y: something-else();
div {
  foo: lua("some_lua_function(#{$x}, #{$y})");
}

Unfortunately, defining functions in Lua and making them accessible in Sass will require a foreign function interface, which is still in development. But once this is done, you'd be able to add Lua support without needing to fork LibSass.

from libsass.

akhleung avatar akhleung commented on August 20, 2024

All right, directives and whatnot are allowed in namespaced properties now.

from libsass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.