Skip to content

Accessors #6

Closed
Closed

Description

@jamesfoster

From the original less.rb tests, this test doesn't pass.

.magic-box {
    color: red;
}
.class {
    color: .magic-box['color'];
}

it fails on the [

Activity

  1. cloudhead commented on Apr 9, 2010

    @cloudhead
    Member

    I've decided to scrap accessors, at least for the first version. It turns out they aren't all that useful..

  2. alixaxel commented on Jan 11, 2012

    @alixaxel

    @cloudhead: That's a shame, I could really see potential for "OO" organization in them (Issue #564).

    I assume we have to wait at least till version 2 now?

  3. mindfullsilence commented on Mar 7, 2012

    @mindfullsilence

    @cloudhead: I've been google searching for days too see if this was possible with LESS. Is there a chance of it in the future? On a complex site I could be looking at all kinds of variables and it'd be great to be able to organize them inside mixins and be able to access them from other sources.

    vars.less:
    
        .colors() {
            @blue: #234;
            @red: #b3452;
            etc...
        }
        .grid() {
            @col-width: 5em;
            @col-gutter: 1em;
        }
    
    main.less:
    
        @import "vars";
        .alert {
            width: .grid[@col-width] * 12;
            margin: 0 (.grid[@col-gutter]/2) 0 (.grid[@col-gutter]/2)
            color: .colors[@red];
            background: lighten(.colors[@red], 50%);
        }
    

    This would be INSANELY helpful. Is there hope?

  4. alixaxel commented on Mar 7, 2012

    @alixaxel

    @mindfullsilence: @col-gutter or .grid[@col-gutter]? I don't think there's hope for this tho...

  5. mindfullsilence commented on Mar 7, 2012

    @mindfullsilence

    Fixed, thanks for pointing it out. I guess it's not that big of a deal, I can always seperate variables in my stylesheet with comments. But I have a few frameworks I've built and I like to use pieces from each one on occassion. So I prepend each variable with the name of my framework. It'd save a lot of time building these frameworks out if I could do something like this:

    fw-1.less:
        
        .fw-1_colors() {
            @red: #2345ba;
            @blue: #928342;
        }
    
    fw-2.less:
    
        fw-2_colors() {
            @red: #239401;
            @blue: #293872;
        }
    

    Without this option, I end up prefixing every variable I have:

        @fw-1-colors_red: #2345ba;
        @fw-2-colors_red: #239401;
        @fw-1-colors_blue: #928342;
        @fw-2-colors_blue: #293872;
    

    Some of my frameworks do as much as the twitter bootstrap, and end up having a LOT of variables. Be a lot easier to write these frameworks if I could just set them inside of a wrapping mixin.

  6. lukeapage commented on Mar 8, 2012

    @lukeapage
    Member

    have you tried

    #namespace {
       @blue: blue;
    }
    
    .class {
       #namespace;
       color: @blue;
    }
    

    I'd like to hear from @cloudhead whether this is a feature or a bug though (it could cause collisions if your using functions written by someone else)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions