Test to see if @content was passed #407

Closed
alanhogan opened this Issue Jun 1, 2012 · 10 comments

Comments

Projects
None yet
6 participants
Contributor

alanhogan commented Jun 1, 2012

I want to be able to define a mixin that can be passed @content but that does not require it.

Something like this would be good:

@if @content
  @content
Owner

chriseppstein commented Jun 3, 2012

I had intended that @content would be a no-op if it was not passed. @nex3, you and I should sort this out.

Contributor

alanhogan commented Jun 3, 2012

My current work-around is this (where my-mixin expects content but I don’t want to pass any, and in fact is perhaps not even defined by myself):

@include my-mixin {
  -no-op: 1
}

That way when this is resolved I can just remove those -no-op: 1 lines.

IMO, @content as a no-op when not passed would be better than a test for seeing if it would be passed, since it would mean less code (no pointless conditionals).

But better than that is both options. I know some Compass functions do some tricky conditional stuff based on what arguments are actually passed. I can’t imagine there wouldn’t be any cases where testing for @content would not be useful, as well.

Best: Both test & no-op
Good: No-op
Fine: test

On Jun 3, 2012, at 10:49 AM, Chris Eppstein wrote:

I had intended that @content would be a no-op if it was not passed. @nex3, you and I should sort this out.


Reply to this email directly or view it on GitHub:
nex3#407 (comment)

Contributor

alanhogan commented Jun 10, 2012

Ran into this again — wrote a mixin where I’d love to be able to make @content optional. It would have made the rest of the stylesheet a bit more maintainable.

Contributor

alanhogan commented Jun 16, 2012

Would love to see sass 3.2 with a no-op-if-none-passed @content.

Owner

chriseppstein commented Jun 17, 2012

I think this is simply a bug/oversight. @nex3 this needs to be in 3.2.

Hunt & pecked on my iPhone... Sorry if it's brief!

On Jun 16, 2012, at 12:52 AM, Alan Hoganreply@reply.github.com wrote:

Would love to see sass 3.2 with a no-op-if-none-passed @content.


Reply to this email directly or view it on GitHub:
nex3#407 (comment)

sidonath commented Jul 2, 2012

+1to @alanhogan's suggestion

I have @include in a partial that's used by two different stylesheets. I would like to make the mixin noop in one stylesheet, and to generate the appropriate code in the other one.

Right now I'm getting this error Mixin "foo-bar" does not accept a content block.

My current workaround is to define foo-bar mixin with a never-executing conditional:

@mixin foo-bar {
  @if false {
    @content
  }
}
Owner

chriseppstein commented Aug 8, 2012

@nex3 can we please address this before 3.2 ships?

nex3 closed this in 709e15c Aug 11, 2012

Contributor

alanhogan commented Aug 13, 2012

thumbs-up

Great :)

Also, going to cc @ericam to make sure he sees this :)

Thanks!

@alanhogan want to check if @content is passed. How are using this? Would love to see a sample of your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment