Answer the question
In order to leave comments, you need to log in
Problems implementing the BEM approach with Sass 3.1.8?
According to the ideology of BEM , it is worth refusing inheritance in css whenever possible (since it is slow and dangerous, let's say so). That is, instead of
.block{}
.block .header{}
.block .content{}
.block{}
.block_header{}
.block_content{}
.block
&_header
&_content
.block{}
.block_header{}
.block_content{}
Deprecate parent selectors followed immediately by identifiers (eg &foo). This should never have worked, since it violates the rule of & only being usable where an element selector would.
.block _header{}
Answer the question
In order to leave comments, you need to log in
I don't know how relevant this is :)
Do an initializer with this code:
Rails.application.config.after_initialize do |app|
app.assets.register_postprocessor 'text/css', :sass_bem_class_builder do |context, data|
data.gsub(/([a-zA-Z0-9\-]+)[ ]([_]+)/i){ $1 + $2 }
end
end
You can define a special variable in which to store the parent selector, for example $_
:
$_: '.block';
#{$_} { color: #111; }
#{$_}_header { color: #222; }
#{$_}_content { color: #333; }
$_: '.another';
#{$_} { color: #444; }
#{$_}_header { color: #555; }
#{$_}_content { color: #666; }
.block {
width: 100px; }
.block_header {
width: 200px; }
.block_content {
width: 300px; }
.another {
width: 100px; }
.another_header {
width: 200px; }
.another_content {
width: 300px; }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question