mixins

LESS CSS: Reuse generated .@{name} class as a mixin

混江龙づ霸主 提交于 2019-11-30 07:25:11
I'm using LESS CSS 1.3.3. Sorry if this question has already been asked, I didn't find anything relevant on the web. I have several class generators that look like this (example extremely simplified, just enough to trigger the error): #genMarginTop (@name, @size) { .@{name} { margin-top: @size; } } Then I use them to generate some actual classes: #genMarginTop(mtStandard, 40px); #genMarginTop(mtHalf, 20px); So far, so good, LESS correctly generates those classes and I can use them in the HTML. However when I want to reuse such a generated class as a mixin somewhere else, I get an error:

Syntax for if/else condition in SCSS mixin

天大地大妈咪最大 提交于 2019-11-30 06:13:26
问题 Hi I'm trying to learn SASS/SCSS and am trying to refactor my own mixin for clearfix what I'd like is for the mixin to be based on whether I pass the mixin a width. thoughts so far (pseudo code only as I will be including other mixins) @mixin clearfix($width) { @if !$width { // if width is not passed, or empty do this } @else { display: inline-block; width: $width; } } here's how I thought I might call it, but it's not working. @include clearfix(); or @include clearfix(100%) or @include

Groovy Mixin on Instance (Dynamic Mixin)

若如初见. 提交于 2019-11-30 05:20:01
问题 I'm trying to achieve following: class A { def foo() { "foo" } } class B { def bar() { "bar" } } A.mixin B def a = new A() a.foo() + a.bar() with one significant difference - I would like to do the mixin on the instance: a.mixin B but this results in groovy.lang.MissingMethodException: No signature of method: A.mixin() is applicable for argument types: (java.lang.Class) values: [class B] Is there a way to get this working like proposed in the Groovy Mixins JSR? 回答1: You can do this since

Using a mixin with a Django form class

蓝咒 提交于 2019-11-30 04:55:28
I'm thinking about creating a mixin form class so that I can add a common set of fields to a variety of otherwise very different forms. Just using it as a base class won't work because I want to be able to use other forms as base classes like so: class NoteFormMixin(object): note = forms.CharField() class MainForm(forms.Form): name = forms.CharField() age = forms.IntegerField() class SpecialForm(MainForm, NoteFormMixin): favorite_color = forms.CharField() My only question is: how does this work? So far it looks like if I use a mixin, then it doesn't recognize the fields set from that mixin: >>

LESS CSS - Change variable value for theme colors depending on body class

こ雲淡風輕ζ 提交于 2019-11-30 04:03:40
Getting to grips with LESS here but one thing is still a little unclear. Lets say I have multiple color themes for my website, controlled by a class on the body tag. From this I can redefine the various colors for each element within each theme. Easy enough but fairly time consuming if I have a lot of elements to change... and a lot of themes. Every time I add a new theme I need to write out all the selectors again, with different color values. I am basing my working so far on another post I found: LESS.css variable depending on class ... However it still seems overly complicated for what I

Sass / SCSS Mixin for Clearfix - best approach?

◇◆丶佛笑我妖孽 提交于 2019-11-30 03:55:53
I want to remove the clearfix class from my HTML and include a clearfix mixin in my SCSS (Rails 3.1 application). What is the best approach to this? I am thinking of just taking the HTML 5 Boilerplate clearfix and turning it into a mixin, then @including it within the CSS for elements that need clearfixing. Copied from HTML5 Boilerplate: /* The Magnificent Clearfix: Updated to prevent margin-collapsing on child elements. http://j.mp/bestclearfix */ .clearfix:before, .clearfix:after { content: "\0020"; display: block; height: 0; overflow: hidden; } .clearfix:after { clear: both; } /* Fix

Does Objective-C support traits/mixins?

半腔热情 提交于 2019-11-30 03:49:38
Are there any techniques for emulating traits or mixins in Objective-C? In Scala, for example, I can do something like this: trait ControllerWithData { def loadData = ... def reloadData = ... def elementAtIndex = ... } trait ControllerWithStandardToolbar { def buildToolbar = ... def showToolbar = ... def hideToolbar = ... } class MyTableController extends ControllerWithData with ControllerWithStandardToolbar { def loadView = { super.loadView loadData buildBar } } It's basically a way to combine (or mix in) multiple pieces of functionality into a single class. So right now I have kind of an all

Where to put common code found in multiple models?

廉价感情. 提交于 2019-11-30 01:40:11
I have two models that contain the same method: def foo # do something end Where should I put this? I know common code goes in the lib directory in a Rails app. But if I put it in a new class in lib called ' Foo ', and I need to add its functionality to both of my ActiveRecord models , do I do that like this: class A < ActiveRecord::Base includes Foo class B < ActiveRecord::Base includes Foo and then both A and B will contain the foo method just as if I had defined it in each? Create a module, which you can put in the lib directory: module Foo def foo # do something end end You can then

When to use mixins and when to use interfaces in Dart?

坚强是说给别人听的谎言 提交于 2019-11-30 01:27:41
I'm very familiar with the concepts of interfaces and abstract classes, but not super familiar with the concepts of mixins . Right now, in Dart, every class A defines an implicit interface, which can be implemented by another class B by using the implements keyword. There's no explicit way of declaring interfaces as, for example, in Java, where an interface contains only unimplemented methods (and eventually static variables). In Dart, since interfaces are defined by classes, the methods of the interface A may actually already be implemented, but the class that implements B still needs to

Semantic Grid with Bootstrap + LESS Mixins ¿ HOW?

左心房为你撑大大i 提交于 2019-11-30 00:49:43
Twitter bootstrap documentation talks about three mixins to generate grid systems: .container-fixed(); #grid > .core(); #grid > .fluid(); I know how to setup the page to use bootstrap and less... But I don't know how to use the grid system semantically. The documentation says what mixins to use but not how... ¿ Could anyone ilustrate how to use them in order to create semantic grids ? Just to figure out or to see how it works :S Thank you !! In navbar.less of bootstrap you will find the following. grid and .core are used to namespace the .span() .navbar-fixed-top .container, .navbar-fixed