less / less/less-docs

Documenting dynamic property iteration (or whatever you want to call it).

Open
#531 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Less
Stars
680
Forks
442
PR merge metrics
No merged PRs in 30d

Description

After testing several ways on how to dynamically iterate over a set of properties, I've finally managed to get something practical for my needs. If such an example were in the documentation, much time and headache could have been reduced. I was trying to create a list of colors that I could iterate over that has access to its local scope, and mixins worked well here. (Detached rulesets and lists do not have access to their local scope, and lazy-loading does not seem to compensate for it. Would have been nice if at least detached rulesets could access their own scopes!)

This:

.colors() {
    blue: #00F;
    dark-blue: darken($blue, 10%);
    red: #F00;
}

each(.colors(), {
    .@{key} {
      color: @value;
    }
});

Will generate:

.blue {
  color: #00F;
}
.dark-blue {
  color: #0000cc;
}
.red {
  color: #F00;
}

Personally, I'm amazed this actually worked. Because I couldn't find anything on the internet similar to this, neither in the documentation, I have no idea of any undesirable consequences doing it this way. Would be nice to have this use-case documented.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No documentation file or entry point is named. Start by locating the Less documentation section covering mixins, property iteration, or each(); add the demonstrated scoped mixin example and explain its generated CSS, then verify the example renders correctly in the documentation.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.