English 中文(简体)
possible to define an array in Sass?
原标题:
  • 时间:2009-12-14 21:35:44
  •  标签:
  • haml
  • sass

wondering if it is possible to use an array with Sass as I find my self repeating the following sort of thing:

.donkey
  h2
    background-color= !donkey

.giraffe
  h2
    background-color= !giraffe

.iguana
  h2
    background-color= !iguana
最佳回答

No, this isn t possible. The best way to do it is to define a mixin:

+animal-h2(!name, !color)
  .#{name} h2
    background-color= !color

Then you can have one line per style, rather than three:

+animal-h2("donkey", !donkey)
+animal-h2("giraffe", !giraffe)
+animal-h2("iguana", !iguana)
问题回答

Absolutely.

$animals: "donkey", "giraffe", "iguana"
@foreach $animal in $animals
  .#{$animal}
    h2
      background-color: !#{$animal}

nex3 s answer is correct. To get this working with SASS on Rails 3.1 I needed to have the following in a css.scss file:

$donkey: #CC4499;

@mixin animal-h2($name, $color) {
  .#{$name} h2 {
    background-color: $color;
  }
}

@include animal-h2("donkey", $donkey);
@include animal-h2("horse", #000);

Which output:

.donkey h2 {
    background-color: #CC4499;
}

.horse h2 {
    background-color: black;
}




相关问题
How to debug broken vim completefunc in haml files?

I m using rails.vim and I love how you can use ctrl-x ctrl-u in insert mode to autocomplete long method names like distance_of_time_in_words and accepts_nested_attributes_for. But for some reason it ...

ruby - if string is not contained within an array

I only want to output one anchor here. If the current_page is in the array I get two (.html and -nf.html). If it is not in the array I get as many anchors as there are items in the array. I am using ...

Feasibility of HAML + PHP/CakePHP

Is anyone using a HAML implementation for PHP like phpHaml or pHAML? Both projects have seen no activity for about 2 years, and both are < 1.0. Is it feasible/wise to use HAML for a large PHP ...

How can I use Haml with Catalyst?

Is it possible to use Haml instead of a templating engine with the Catalyst web framework?

Referencing a SASS file from HAML

How do I reference a .sass file from a .haml file? I have the following haml expression that will reference a .css file: %link{ href => /stylesheets/layout.css?cache=1 , rel => stylesheet ...

haml syntax - better way of writing this?

I have a config file full of this.... - if current_page.include? "test_string_one" - @total_index = 3 - @next_location = ../random_string/page0.html - @next_name = title 2 ...

haml syntax - better way of writing this?

There must be a better way of writing this- I m just not sure how (using staticmatic)- - if current_page.include? "0.html" - @current_index = 1 - if current_page.include? "1.html" - @...

热门标签