[GH-ISSUE #255] Suggestion to "improve" sass and less files #168

Closed
opened 2026-03-03 14:35:07 +03:00 by kerem · 7 comments
Owner

Originally created by @felixvictor on GitHub (Jun 8, 2016).
Original GitHub issue: https://github.com/lipis/flag-icons/issues/255

Love your project...

What about this: instead of listing all the imports in the sass (less) files, you could use a loop. For example

$countries: ad, ae, af;
$n: length($countries);

@for $i from 1 through $n {
  $country: nth($countries, $i);
  .flag-icon-#{$country} {
  background-image: url(#{$flag-icon-css-path}#{$flag-icon-rect-path}/#{$country}.svg);
  &.flag-icon-squared {
    background-image: url(#{$flag-icon-css-path}#{$flag-icon-square-path}/#{$country}.svg);
  }
 }
}

And for less

@countries: ad, ae, af;
@n: length(@countries);
.generate-icons(@n);

.generate-icons(@n, @i: 1) when (@i =< @n) {
  @country: extract(@countries, @i);
  .flag-icon.@{country} {
    background-image: ~"url((@{flag-icon-css-path}@{flag-icon-rect-path}/@{country}.svg)";
    &.flag-icon-squared {
      background-image: ~"url(@{flag-icon-css-path}@{flag-icon-square-path}/@{country}.svg)";
    }
  }
  .generate-icons(@n, (@i + 1));
}

Originally created by @felixvictor on GitHub (Jun 8, 2016). Original GitHub issue: https://github.com/lipis/flag-icons/issues/255 Love your project... What about this: instead of listing all the imports in the sass (less) files, you could use a loop. For example ``` $countries: ad, ae, af; $n: length($countries); @for $i from 1 through $n { $country: nth($countries, $i); .flag-icon-#{$country} { background-image: url(#{$flag-icon-css-path}#{$flag-icon-rect-path}/#{$country}.svg); &.flag-icon-squared { background-image: url(#{$flag-icon-css-path}#{$flag-icon-square-path}/#{$country}.svg); } } } ``` And for less ``` @countries: ad, ae, af; @n: length(@countries); .generate-icons(@n); .generate-icons(@n, @i: 1) when (@i =< @n) { @country: extract(@countries, @i); .flag-icon.@{country} { background-image: ~"url((@{flag-icon-css-path}@{flag-icon-rect-path}/@{country}.svg)"; &.flag-icon-squared { background-image: ~"url(@{flag-icon-css-path}@{flag-icon-square-path}/@{country}.svg)"; } } .generate-icons(@n, (@i + 1)); } ```
kerem closed this issue 2026-03-03 14:35:07 +03:00
Author
Owner

@lipis commented on GitHub (Jun 8, 2016):

It's easier to maintain, sort, add, remove, check, etc...

<!-- gh-comment-id:224590822 --> @lipis commented on GitHub (Jun 8, 2016): It's easier to maintain, sort, add, remove, check, etc...
Author
Owner

@lipis commented on GitHub (Jun 8, 2016):

Also multi-cursor is your friend..

<!-- gh-comment-id:224591043 --> @lipis commented on GitHub (Jun 8, 2016): Also [multi-cursor](https://www.sublimetext.com/) is your friend..
Author
Owner

@felixvictor commented on GitHub (Jun 8, 2016):

Just an idea ;-)

<!-- gh-comment-id:224601563 --> @felixvictor commented on GitHub (Jun 8, 2016): Just an idea ;-)
Author
Owner

@lipis commented on GitHub (Jun 8, 2016):

So what do you think about this idea after the answer?

<!-- gh-comment-id:224606241 --> @lipis commented on GitHub (Jun 8, 2016): So what do you think about this idea after the answer?
Author
Owner

@tomlutzenberger commented on GitHub (Jun 8, 2016):

I partially agree with @felixvictor, except I would just loop the list and call the mixin.

<!-- gh-comment-id:224609091 --> @tomlutzenberger commented on GitHub (Jun 8, 2016): I partially agree with @felixvictor, except I would just loop the list and call the mixin.
Author
Owner

@felixvictor commented on GitHub (Jun 8, 2016):

Sorry, @lipis, I don't understand your question.

<!-- gh-comment-id:224614945 --> @felixvictor commented on GitHub (Jun 8, 2016): Sorry, @lipis, I don't understand your question.
Author
Owner

@lipis commented on GitHub (Jun 13, 2016):

I'll pass on this one..

<!-- gh-comment-id:225511519 --> @lipis commented on GitHub (Jun 13, 2016): I'll pass on this one..
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/flag-icons#168
No description provided.