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
Passing arguments from a mixin to a content block #871
Comments
I like this idea. 👍 |
Not crazy about the syntax for |
Comments of general distaste are not very useful without explanations and, ideally, alternative suggestions. |
It's really fine !
|
At first blush, I like it. How about @Bind instead of @receive... maybe that's too nerdy? On Thu, Aug 1, 2013 at 2:32 PM, Gabriel Nau notifications@github.comwrote:
|
Could always pull a JavaScript and make an $arguments variable. Or an arguments($n) function. |
The problem with Re: Naming, I'm not a fan of |
I'm not a fan of |
I guess I'm not a fan of receive due to it being commonly misspelled. Just @take On Friday, August 2, 2013, Nathan Weizenbaum wrote:
|
I think I like @content-arguments best so far. |
Hrrm... as I look at the use case more, this seems like something we think We could steal some Ruby syntax!
On Sun, Aug 4, 2013 at 11:30 AM, Chris Eppstein notifications@github.comwrote:
|
The part I'm not a fan of is how much additional code this adds from a reuse standpoint. Using global variables is worse when it comes to authoring the mixins, but more convenient for using them. Shorter is better. If it must be a keyword, Borrowing a bit from Haskell here: @mixin foo($a, $b) {
@content (darken($a), lighten($b), blend($a, $b));
}
.foo {
@include foo(red, blue) -> ($c, $d, $e) {
@include background: $e;
@include background-image(linear-gradient($c, $d));
}
} Using a Ruby style syntax as @hcatlin suggests would also be acceptable. |
I don't get where the red and blue come from in the above example ? |
The |
I'm more of a fan of @cimmanon's example than any of the others I've seen. Placing the arguments before the I'm not a big fan of |
I actually really like the Leaning towards taking. I also like |
I don't like how much longer |
What about |
How about |
I think I like |
Objections to this for 3.3? Would really clean up some compass code. |
I don't want any new features in 3.3. I want to get it out the door as soon as the existing features for it are done. |
ok. |
From my short-lived #894, since the Optionally a
I just don't see a reason to force all variables to be explicitly named ( as previously discussed ); it's not particularly magical if done implicitly as the mixin consumers will need to refer to argument documentation regardless.
|
I think it's important that all the variables are named at the call site. It makes it possible to determine where each variable is coming from by inspecting the code around it. |
@chriseppstein passing arguments to |
Yes please! I came across this issue recently and would love this to help On Tuesday, September 17, 2013, Elise Chant wrote:
|
For anyone interested, my workaround at the moment requires a repeating loop: _config.scss
_breadcrumb.scss
|
Yea I have something similar but like you say you can't do the loop within I wanted the loop within a mixin as then it's tidier and cleans the code up I'm happy it's being discussed - I thought about it the other day and On Wednesday, September 18, 2013, Elise Chant wrote:
|
This has also landed in LibSass. Should this issue be closed? |
How long would this typically take to trickle into node-sass? |
Woohoo! Been on the lookout for this for 3 years! Big thanks! |
Goes to show, good things come to those who wait. Nice work guys! |
@xzyfer When you close out these issues, can you let me know the first LibSass release number these features are expected to land in? That way I can update the new reference docs' implementation tracker. |
And the subsequent node-sass release if anyone catches it. Then we can put this whole 5+ year ordeal to bed 👯 🍾 |
has this not landed on node-sass? |
@itsleeowen it landed in sass/libsass#2761 |
Yeah and node-sass still isn't using it. |
When to wait for an update for node-sass? |
the @content argument examples work w/ node-sass on my end with these updates: sass/node-sass#2714 node-sass mocha tests don't pass, I'm not sure how to reconcile node-sass tests against libsass changes between Nov 11, 2018 and libsass#2b8a17a. Unless I'm misunderstanding the failing node-sass tests, I'm not confident that node-sass having it's own set of style tests is a good idea, it should probably depend on libsass tests if it's not. 5935 passing (18s) also... @content arguments are AMAZING, thanks you! 😺 |
I don't know what Node Sass's release schedule is—you'd have to follow along on sass/node-sass#2685. |
@itsleeowen How? I'm using the latest version of node-sass and it seams to be using libSass |
I'm using latest version of Node-Sass (4.13.0) and this doesn't seem to be working, but it's still great news that the feature is now in Sass. I'm struggling to find where to follow for updates for Node-Sass though. This thread mentions to follow a PR for updates, but the PR was already merged. |
Node Sass versions are released later (sometimes substantially later) than the corresponding LibSass versions. I'm not sure if there's a central place to look for them. Maybe @xzyfer or @nschonni would know? Alternately, you could use Dart Sass (https://www.npmjs.com/package/sass) which definitely has this feature. |
What's the status on this one? |
As the comment above indicates, this is implemented everywhere but may not yet be released in Node Sass. |
Mixin content is great and has done wonders for code implementing wrapper and context abstractions. However, there is often some setup done in the mixin and that setup needs to be available to the content when it is included. The current strategy is to use global variables, which works, but is obviously not ideal.
I'd like to introduce a way for mixins to include their content block and to pass arguments to the content.
Calling the content with arguments
In order to pass arguments to content blocks an argument list can be passed to the content directive. This accepts positional and keyword arguments for passing to a content block. Variable argument semantics are allowed.
Receiving arguments within a content block
A content block receives arguments using a new directive called
@receive
. The directive allows an argument list declaration that is the same as for functions and mixins. Positional arguments, default values, and variable arguments are all allowed.The text was updated successfully, but these errors were encountered: