2012-03-06 37 views
9

Cách bút giao dịch với phạm vi biến?Phạm vi biến đổi trong Stylus

-

1- Có phải tất cả các biến toàn cầu?

$foo = red // is $foo global? 

2- Tương tự như các commonJS module, là có bất kỳ exports/require tương đương?

$foo = @import 'foo' 

body { color: $foo } 

3- gì về các biến khai báo trong một khối CSS, có lẽ với mixins:

$foo = green 

bar() 
    $foo = yellow // is it the same $foo ? 
    $baz = blue. // local or implied global? 

ul { 

    background: $foo // green or yellow? red? 

    $foo = red 

    li { 

    $foo = pink 

    } 

    color: $foo // pink? 

    bar() // what about $foo now? 

} 

-

Sẽ đánh giá cao bất kỳ làm rõ hoặc tài liệu về vấn đề này ...

Cảm ơn bạn

+0

Một vấn đề liên quan đến 2/https://github.com/LearnBoost/stylus/issues/526 – abernier

Trả lời

10

Nếu y ou hơi xây dựng lại và phần # 3 câu hỏi của bạn:

$foo = green                 
p('global: $foo is ' $foo)             

bar()                  
    $foo = yellow                
    p('In bar(): $foo is ' $foo)            
    $baz = blue                

p('$baz outside of bar() is ' $baz)           

ul {                   

    background: $foo               
    p('In ul: $foo is ' $foo)             

    $foo = red                 
    p('In ul: now $foo is ' $foo)            

    li {                  

    $foo = pink                
    p('In ul li: $foo is ' $foo)            

    }                   

    color: $foo // pink?              
    p('Back in ul: now $foo is ' $foo)           

    bar()                  
    p('what about $foo now? ' $foo)           
} 

Sau đó bút sẽ trả lời nó:

$ stylus test.styl 
inspect: 'global: $foo is ' (#008000) 
inspect: '$baz outside of bar() is ' $baz 
inspect: 'In ul: $foo is ' (#008000) 
inspect: 'In ul: now $foo is ' (#f00) 
inspect: 'In ul li: $foo is ' (#ffc0cb) 
inspect: 'Back in ul: now $foo is ' (#f00) 
inspect: 'In bar(): $foo is ' (#ff0) 
inspect: 'what about $foo now? ' (#f00) 
    compiled test.css