mixins

Dynamically define a variable in LESS CSS

旧巷老猫 提交于 2019-11-26 20:57:25
问题 I am trying to create a mixin that dynamically defines variables in LESS CSS, by actually assigning them a composite name. The simplified use-case (not the real one): .define(@var){ @foo{var}: 0; } Then one would call the mixin as such: .define('Bar'){ @fooBar: 0; } Since this kind of string interpolation is possible while using selectors names, I was wondering if the same would be possible for variable names; so far, I have had no luck with various syntaxes I tried (other than the above, I

CSS property as SASS mixin value [duplicate]

允我心安 提交于 2019-11-26 19:12:27
This question already has an answer here: Using variables for CSS properties in Sass 2 answers I try to build some universal margin/padding mixin... This is my code: [class*="shift"] { $sft-o: 10px; @mixin shift_stp($val) { &[class*="_sml"]{ $val: $sft-o; } &[class*="_mid"]{ $val: $sft-o * 2; } &[class*="_big"]{ $val: $sft-o * 3; } } &[class*="_m"]{ @include shift_stp(margin); } &[class*="_p"]{ @include shift_stp(padding); } } Something is not right, so I wonder if it is possible to set some CSS property as a mixin value? Can anybody help? If you want to use variables as property names you

Difference between @Delegate, @Mixin and Traits in Groovy?

只谈情不闲聊 提交于 2019-11-26 18:53:43
问题 Would someone explain when I would want to use Groovy Traits vs. Mixins (@Mixin) vs. Delegates (@Delegate)? Maybe some trade-offs and design concerns would help. They all seem to allow for reusing multiple "classes" of behavior. Thanks. :-) This SO thread was helpful too: Difference between @Delegate and @Mixin AST transformations in Groovy 回答1: I agree, they all seem to allow reusing multiple "classes" of behaviour. There are differences, though, and understanding these will probably aid

Dynamic mixin in Scala - is it possible?

ε祈祈猫儿з 提交于 2019-11-26 18:49:17
What I'd like to achieve is having a proper implementation for def dynamix[A, B](a: A): A with B I may know what B is, but don't know what A is (but if B has a self type then I could add some constraints on A). The scala compiler is happy with the above signature, but I could not yet figure out how the implementation would look like - if it is possible at all. Some options that came to my mind: Using reflection/dynamic proxy. Simplest case: A is an interface on Java level + I can instantiate B and it has no self type. I guess it would not be too hard (unless I run into some nasty, unexpected

Inheriting class methods from modules / mixins in Ruby

六月ゝ 毕业季﹏ 提交于 2019-11-26 18:47:30
问题 It is known that in Ruby, class methods get inherited: class P def self.mm; puts 'abc' end end class Q < P; end Q.mm # works However, it comes as a surprise to me that it does not work with mixins: module M def self.mm; puts 'mixin' end end class N; include M end M.mm # works N.mm # does not work! I know that #extend method can do this: module X; def mm; puts 'extender' end end Y = Class.new.extend X X.mm # works But I am writing a mixin (or, rather, would like to write) containing both

What are Mixins (as a concept)

放肆的年华 提交于 2019-11-26 18:11:52
I'm trying to get my head around the Mixin concept but I can't seem to understand what it is. The way I see it is that it's a way to expand the capabilities of a class by using inheritance. I've read that people refer to them as "abstract subclasses". Can anyone explain why? I'd appreciate if you'd explain your answer based on the following example (From one of my lecture slideshows): Before going into what a mix-in is, it's useful to describe the problems it's trying to solve. Say you have a bunch of ideas or concepts you are trying to model. They may be related in some way but they are

Mixins vs. Traits

喜你入骨 提交于 2019-11-26 17:54:39
问题 What is the difference between Mixins and Traits? According to Wikipedia, Ruby Modules are sort of like traits. How so? 回答1: Mixins may contain state, (traditional) traits don't. Mixins use "implicit conflict resolution", traits use "explicit conflict resolution" Mixins depends on linearization, traits are flattened. Lecture about traits ad 1. In mixins you can define instance variables. Traits do not allow this. The state must be provided by composing class (=class using the traits) ad 2.

ruby inheritance vs mixins

自古美人都是妖i 提交于 2019-11-26 16:58:19
In Ruby, since you can include multiple mixins but only extend one class, it seems like mixins would be preferred over inheritance. My question: if you're writing code which must be extended/included to be useful, why would you ever make it a class? Or put another way, why wouldn't you always make it a module? I can only think of one reason why you'd want a class, and that is if you need to instantiate the class. In the case of ActiveRecord::Base, however, you never instantiate it directly. So shouldn't it have been a module instead? Andy Gaskell I just read about this topic in The Well

Are Mixin class __init__ functions not automatically called?

偶尔善良 提交于 2019-11-26 15:51:31
问题 I'd like to use a Mixin to always add some init functionality to my child classes which each inherit from different API base classes. Specifically, I'd like to make multiple different child classes that inherit from one of these different API-supplied base classes and the one Mixin, which will always have the Mixin initialization code executed in the same way, without code replication. However, it seems that the __init__ function of the Mixin class never gets called unless I explicitly call

What is C++ Mixin-Style?

时光怂恿深爱的人放手 提交于 2019-11-26 15:35:17
问题 I have just come across this keyword C++ Mixin-Style , do anyone know what this is? In this post, is has been answered as a design pattern. Is it the same design pattern as described in this document? 回答1: Mixins are a concept from Lisp. A good explanation from Dr. Dobbs: A mixin is a fragment of a class in the sense that it is intended to be composed with other classes or mixins. [...] The difference between a regular, stand-alone class (such as Person) and a mixin is that a mixin models