Recorrer arreglos en pre-processors

5/Nov/2014 199

Hace unos 4 proyectos atrás, me enfrenté al dilema de crear y recorrer un array de elementos -en este caso colores en hexacromía- y crear clases CSS dinámicamente a partir de cada uno de los colores contenidos en el arreglo. Algo sencillo de lograr en JavaScript pero que curiosamente tiene diferentes soluciones por cada tipo de pre-processor. Mientras SCSS y Stylus son más sencillos, con LESS es necesario un poco más de código para lograr lo mismo, pero que se espera se solucione en una pronta versión.

A continuación, snippets de cómo recorrer arreglos y usar sus elementos en LESS, SCSS y Stylus:

LESS


// Creamos un arreglo con 4 colores:
@colores: '#767676','#8cc079','#b35d5d','#81babd';
// Guardamos el total de elementos del arreglo:
@cuantos: length(@colores);
// Recorramos cada uno de los elementos del arreglo @colores:
.loop (@index) when (@index > 0){
  // Obtengamos el nombre de cada color
  @color: e(extract(@colores,@index));
  // Ahora podemos utilizarlo:
  elemento-@{index} {
    color: @color;
  }
  .loop (@index - 1);
}
.loop(0){}
// Seguimos recorriendo hasta llegar al total (último):
.loop(@cuantos);
// Fin

SCSS


// Creamos un arreglo con 4 colores:
$colores: (#767676, #8cc079, #b35d5d, #81babd);
// Recorramos cada uno de los elementos del arreglo @colores:
@each $color in $colores {
  // Obtengamos el índice de cada $color en $colores:
  $i: index($colores, $color);
  // Ahora podemos utilizarlo:
  elemento-#{$i} {
    color: $color;
  }
}
// Fin

Stylus


// Creamos un arreglo con 4 colores:
colores = ( #767676 #8cc079 #b35d5d #81babd )
// Guardamos el total de elementos del arreglo:
cuantos = length(colores) - 1
// Recorramos cada uno de los elementos del arreglo @colores hasta llegar al total (último):
for i in (0..cuantos)
// Ahora podemos utilizarlo:
  elemento-{i + 1}
    color colores[i]
// Fin

Comentarios

  1. off white x jordan 1 [#]

    I wanted to type a brief remark in order to appreciate you for all of the awesome solutions you are showing on this site. My incredibly long internet lookup has at the end of the day been rewarded with really good concept to write about with my relatives. I would repeat that we visitors are very lucky to exist in a decent community with very many outstanding people with interesting guidelines. I feel very blessed to have come across your web site and look forward to so many more enjoyable minutes reading here. Thanks a lot once more for all the details.

  2. bape hoodie [#]

    I am glad for writing to make you be aware of of the helpful encounter my cousin’s child gained checking your webblog. She came to understand a good number of things, with the inclusion of what it is like to possess a very effective helping style to let most people with no trouble thoroughly grasp a number of complex things. You truly exceeded readers’ expected results. Thank you for offering the informative, healthy, explanatory and also cool thoughts on this topic to Tanya.

  3. lebron 16 shoes [#]

    I precisely had to appreciate you again. I am not sure what I would have made to happen without the actual hints discussed by you on that question. It seemed to be an absolute scary concern in my circumstances, but noticing the very skilled way you handled the issue forced me to leap over happiness. I am happy for the support and as well , believe you realize what an amazing job you happen to be putting in training some other people using your blog. Most probably you have never come across all of us.

  4. kyrie irving shoes [#]

    I would like to express my appreciation for your kindness in support of individuals that have the need for help on this particular issue. Your real dedication to getting the message all around was astonishingly informative and has continually empowered professionals just like me to realize their objectives. This warm and friendly publication denotes much a person like me and a whole lot more to my office colleagues. Many thanks; from everyone of us.

  5. quest bars your [#]

    Hi! I’m at work browsing your blog from my new iphone!

    Just wanted to say I love reading your blog and look forward to all your posts!
    Keep up the great work! quest bars http://bitly.com/3C2tkMR quest
    bars

  6. bit.ly [#]

    It’s a shame you don’t have a donate button! I’d definitely donate to this brilliant blog!
    I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to brand new updates and will talk about this blog with my Facebook group.
    Chat soon! scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery

  7. app.gumroad.com [#]

    I’ve been browsing online greater than three hours as of late,
    but I by no means discovered any fascinating article like yours.
    It’s lovely price enough for me. In my opinion, if all site owners and bloggers made just right content material as
    you did, the web might be much more helpful than ever before.
    asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

  8. www.iherb.com [#]

    I do not even know how I ended up here, but I thought this post
    was great. I do not know who you are but definitely you are going to a famous blogger if you are not
    already 😉 Cheers! quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

  9. kobe byrant shoes [#]

    Thanks a lot for providing individuals with an exceptionally remarkable possiblity to read from this blog. It’s usually so brilliant and also stuffed with a great time for me personally and my office fellow workers to search your site more than 3 times in a week to read through the new issues you have got. And indeed, I am just at all times motivated with the beautiful techniques you give. Certain 3 points in this post are completely the very best we’ve ever had.

  10. curry 6 shoes [#]

    Thank you so much for giving everyone a very splendid opportunity to discover important secrets from this website. It is often so enjoyable and jam-packed with a good time for me and my office colleagues to search your blog at least 3 times in a week to read the fresh items you have got. And indeed, I am just usually contented with your amazing ideas you give. Selected 2 areas in this article are ultimately the very best we’ve had.

  11. supreme clothing [#]

    I wanted to construct a quick note to be able to express gratitude to you for all of the magnificent strategies you are giving out on this website. My time intensive internet search has at the end of the day been rewarded with really good facts to talk about with my family members. I ‘d believe that most of us visitors actually are really lucky to dwell in a magnificent site with very many wonderful professionals with useful hints. I feel very blessed to have seen the weblog and look forward to many more awesome times reading here. Thanks a lot again for everything.

  12. lebron shoes [#]

    Thanks a lot for providing individuals with such a pleasant possiblity to discover important secrets from this web site. It’s always so cool and as well , stuffed with fun for me and my office mates to visit your blog at the least 3 times in one week to learn the newest items you will have. And lastly, I am also always satisfied concerning the extraordinary creative concepts you serve. Certain 2 ideas in this post are without a doubt the most impressive I’ve had.

  13. cheap jordans [#]

    I as well as my buddies have been digesting the best strategies located on your site and so quickly came up with a horrible feeling I had not expressed respect to the web blog owner for those secrets. Those young boys appeared to be consequently glad to read through them and have in effect in fact been loving those things. Thank you for getting considerably considerate and then for getting variety of quality things millions of individuals are really needing to be aware of. My very own honest regret for not expressing gratitude to you sooner.

  14. kd 10 [#]

    I precisely desired to thank you so much once again. I’m not certain the things that I might have achieved without the ideas shared by you about this question. This has been an absolute frustrating matter in my view, but spending time with your professional technique you handled the issue took me to cry for delight. Now i am happy for the guidance and even wish you realize what a powerful job you were carrying out instructing the rest thru a blog. I’m certain you haven’t encountered all of us.

  15. jordan shoes [#]

    I definitely wanted to jot down a brief comment so as to say thanks to you for some of the magnificent concepts you are showing on this site. My prolonged internet investigation has now been rewarded with reputable information to write about with my neighbours. I would point out that we site visitors actually are extremely blessed to be in a useful network with so many perfect individuals with valuable advice. I feel really happy to have used the webpages and look forward to really more fabulous moments reading here. Thank you again for a lot of things.

  16. supreme clothing [#]

    My husband and i were ecstatic when Raymond managed to finish up his researching while using the precious recommendations he got from your weblog. It’s not at all simplistic to just continually be offering facts that most people could have been selling. We really understand we need the blog owner to give thanks to because of that. The specific explanations you’ve made, the straightforward site menu, the relationships your site make it possible to instill – it is most overwhelming, and it is assisting our son in addition to the family feel that this theme is entertaining, and that’s exceedingly pressing. Many thanks for the whole lot!

  17. stone island clothing [#]

    Thank you a lot for giving everyone a very marvellous chance to discover important secrets from here. It is always so terrific plus stuffed with a good time for me and my office fellow workers to search the blog not less than 3 times weekly to see the newest guidance you have got. Not to mention, I am also actually satisfied with all the cool suggestions you serve. Certain 1 areas in this article are clearly the simplest we have ever had.

  18. http://bit.ly/ [#]

    Hi, the whole thing is going nicely here and ofcourse every one is sharing information, that’s actually good, keep up writing.
    cheap flights http://1704milesapart.tumblr.com/ cheap flights

  19. دانلود فیلم [#]

    Very good blog post. I absolutely love this site. Keep it up!

  20. http://coub.com/stories/962966-scoliosis-surgery [#]

    Howdy! This article could not be written much better! Looking through this post
    reminds me of my previous roommate! He constantly kept talking about this.
    I am going to forward this article to him. Pretty
    sure he’ll have a very good read. Thank you for sharing!

    scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

  21. hermes handbags [#]

    I wish to convey my admiration for your generosity in support of folks who should have guidance on this issue. Your special commitment to getting the message all-around had been especially advantageous and have usually helped most people just like me to arrive at their endeavors. Your personal warm and helpful tutorial indicates a whole lot a person like me and substantially more to my mates. Many thanks; from everyone of us.

  22. jordan 11 [#]

    My wife and i were quite excited when Raymond could deal with his preliminary research from the precious recommendations he came across out of the web page. It is now and again perplexing just to happen to be giving out steps others have been trying to sell. And we grasp we need the website owner to thank for this. The specific explanations you made, the easy web site menu, the relationships you can make it easier to foster – it’s got most astounding, and it’s really making our son and the family know that this topic is exciting, which is unbelievably important. Many thanks for everything!

  23. jordan 4 [#]

    Needed to compose you a very little observation to help say thank you as before on the splendid techniques you have provided here. It was really pretty open-handed of you to deliver extensively precisely what a lot of folks would have supplied for an e book in making some money for themselves, notably given that you might well have done it if you ever decided. The techniques likewise served to become great way to comprehend other people have the same desire like my very own to grasp very much more on the topic of this problem. Certainly there are numerous more pleasant moments up front for folks who start reading your website.

  24. yeezy shoes [#]

    I want to voice my affection for your kind-heartedness in support of men and women who absolutely need help on the idea. Your very own commitment to getting the message up and down appears to be surprisingly functional and has usually empowered regular people just like me to get to their aims. The helpful guideline denotes so much a person like me and extremely more to my colleagues. With thanks; from all of us.

  25. golden goose outlet [#]

    Thanks for all your valuable effort on this website. Kim loves managing internet research and it is easy to understand why. A number of us notice all regarding the dynamic method you provide advantageous items on the website and in addition boost contribution from other ones about this matter and our girl is starting to learn so much. Enjoy the remaining portion of the new year. You are conducting a wonderful job.

  26. yeezy supply [#]

    I wish to voice my affection for your kindness giving support to all those that absolutely need help on this matter. Your personal dedication to passing the message all through came to be exceedingly functional and have usually enabled those much like me to arrive at their pursuits. Your personal helpful tutorial entails a whole lot to me and much more to my mates. Thanks a lot; from each one of us.

  27. yeezy boost 350 [#]

    I enjoy you because of all of the hard work on this website. Kate delights in working on investigations and it’s simple to grasp why. A lot of people know all about the compelling manner you present good secrets by means of your web site and as well cause response from other people on the article plus our own child is actually studying a lot of things. Take pleasure in the rest of the year. You are always performing a glorious job.

  28. moncler jackets [#]

    I needed to put you one bit of observation to help give many thanks yet again just for the pretty techniques you have shared here. It’s certainly wonderfully generous with people like you to give easily what a number of people could have supplied as an ebook in order to make some dough on their own, mostly considering that you might well have tried it if you ever desired. The concepts likewise worked to be the great way to understand that other people online have a similar desire the same as my personal own to learn way more with regard to this matter. I believe there are millions of more pleasurable instances in the future for individuals that examine your site.

  29. jordan retro [#]

    I needed to draft you a tiny observation to be able to say thank you yet again with the amazing views you have shown at this time. This is really unbelievably open-handed with people like you to supply unreservedly exactly what a few individuals could possibly have advertised for an ebook to get some bucks for their own end, primarily given that you could have done it in case you considered necessary. These inspiring ideas also served as the fantastic way to know that other people have similar desire much like my personal own to find out much more with reference to this matter. I think there are many more enjoyable periods up front for people who find out your site.

  30. golden goose [#]

    I would like to convey my admiration for your kindness in support of persons who have the need for assistance with this subject. Your very own dedication to getting the solution all-around had become surprisingly good and have regularly made some individuals much like me to realize their pursuits. Your own warm and friendly hints and tips entails a great deal to me and further more to my office colleagues. Many thanks; from all of us.

  31. golden goose [#]

    My spouse and i have been absolutely satisfied when Emmanuel could finish off his inquiry with the precious recommendations he discovered from your blog. It is now and again perplexing to simply always be giving out concepts which usually a number of people may have been trying to sell. And now we remember we now have you to give thanks to for that. The illustrations you’ve made, the easy site menu, the relationships you will aid to foster – it is most fantastic, and it is making our son and us reason why the article is cool, which is certainly exceptionally fundamental. Many thanks for the whole thing!

  32. SLOT PG [#]

    Thank you very much for sharing this great article. ดาวน์โหลด pgslot

  33. buy zyrtec online [#]

    fexofenadine side effects – http://allergyd.com

  34. cost of cetirizine 10mg [#]

    zyrtec – https://allergyd.com

  35. paul george shoes [#]

    I wish to get across my respect for your kindness supporting people who require assistance with this area. Your real dedication to passing the solution across turned out to be quite insightful and has consistently made some individuals just like me to attain their dreams. Your personal warm and helpful guide entails a lot a person like me and much more to my fellow workers. Warm regards; from everyone of us.

  36. moncler outlet [#]

    My spouse and i got very peaceful Albert could conclude his preliminary research with the ideas he came across out of the weblog. It’s not at all simplistic to simply be offering points that others may have been selling. So we figure out we now have the writer to thank because of that. These explanations you made, the easy web site navigation, the friendships you can aid to create – it’s got many powerful, and it’s really aiding our son and us understand that subject matter is brilliant, and that is seriously serious. Many thanks for the whole thing!

  37. bape hoodie [#]

    I want to express some thanks to you just for bailing me out of this particular condition. Right after looking out throughout the the net and finding recommendations which were not beneficial, I believed my entire life was over. Being alive without the solutions to the issues you’ve sorted out by means of your entire website is a critical case, and those that could have badly affected my entire career if I had not noticed your blog post. Your own know-how and kindness in dealing with a lot of things was invaluable. I am not sure what I would’ve done if I hadn’t encountered such a subject like this. I am able to at this moment look ahead to my future. Thank you so much for this impressive and result oriented help. I will not hesitate to refer your web sites to any individual who will need care about this subject.

  38. off white nike [#]

    I intended to create you one very little observation so as to say thank you as before on your exceptional opinions you’ve documented here. This is certainly generous of you to present publicly exactly what a lot of folks might have made available for an e-book to help make some dough for their own end, principally considering the fact that you could have tried it in case you decided. These basics in addition worked to be the great way to fully grasp that some people have the same passion like my personal own to understand more around this issue. I am certain there are many more fun occasions ahead for folks who scan through your site.

  39. golden goose [#]

    I would like to convey my appreciation for your kind-heartedness in support of women who actually need help on this issue. Your special dedication to passing the solution all around became certainly significant and have in most cases permitted some individuals much like me to attain their desired goals. Your entire valuable tutorial means a lot a person like me and still more to my peers. Thanks a ton; from everyone of us.

  40. ivermectin where to find [#]

    stromectol https://stromectolforte.com/# ivermectin ivermectin coronavirus

  41. ivermectina 1 crema generica [#]

    stromectol generic https://stromectolforte.com/ stromectol otc sztromektol uk

  42. hermes [#]

    I actually wanted to post a small comment in order to appreciate you for some of the magnificent recommendations you are giving here. My time-consuming internet search has at the end been paid with wonderful ideas to write about with my guests. I ‘d tell you that many of us site visitors actually are rather endowed to be in a magnificent network with many wonderful people with helpful principles. I feel pretty grateful to have seen your entire webpage and look forward to tons of more fabulous minutes reading here. Thank you once again for everything.

  43. yeezy [#]

    My spouse and i have been quite more than happy Raymond could carry out his web research through your ideas he got out of your site. It’s not at all simplistic to simply continually be handing out guidelines many people could have been trying to sell. We really remember we’ve got the writer to give thanks to for that. The main explanations you made, the straightforward web site menu, the relationships you will assist to promote – it’s many incredible, and it’s facilitating our son in addition to us believe that the situation is exciting, which is certainly highly fundamental. Thanks for everything!

  44. supreme clothing [#]

    I precisely desired to appreciate you once again. I’m not certain what I could possibly have used without the actual basics shared by you about such industry. It seemed to be an absolute depressing crisis for me personally, but looking at this specialized way you solved the issue forced me to leap for contentment. I’m happier for the support and then hope that you recognize what a powerful job you’re providing teaching most people through your website. I am sure you haven’t come across any of us.

  45. jordan shoes [#]

    I precisely needed to say thanks once more. I do not know the things that I could possibly have achieved in the absence of the entire tips and hints contributed by you directly on such a situation. It was actually a very intimidating matter in my circumstances, but considering a new skilled fashion you processed that made me to jump for contentment. Now i am grateful for the guidance and thus sincerely hope you recognize what a powerful job you happen to be getting into teaching men and women using your web page. I am certain you’ve never encountered any of us.

  46. stromectol for humans [#]

    stromectol manufacturer http://stromectolforte.com/# cost of stromectol medication stromectol australia

  47. modafinildrugtest [#]

    modafinil smart drug modafinil withdrawal

  48. how does accutane work [#]

    isotretinoin buy isotretinoine

  49. prednisonewarnings [#]

    prednisone side effects in dogs https://prednisoloneprednisolone.com/

CSSLab