mixins

Executing a mixin method at the end of a class definition

吃可爱长大的小学妹 提交于 2019-12-06 15:58:13
I have a Mix-in that reflects on the receiver class to generate some code. This means that I need to execute the class method at the end of the class definition, like in this trivially dumbed down example: module PrintMethods module ClassMethods def print_methods puts instance_methods end end def self.included(receiver) receiver.extend ClassMethods end end class Tester include PrintMethods def method_that_needs_to_print end print_methods end I'd like to have the mixin do this for me automatically, but I can't come up with a way. My first thought was to add receiver.print_methods to self

Is it possible to use a mixin for browser-specific CSS

喜欢而已 提交于 2019-12-06 10:13:20
问题 I'm looking for a solution to use a mixin for browser-specific CSS hacks. I'm using JavaScript to add the browser tag in the HTML class. Like .ie .ie7 .ie8 .ie9 I would like to use the mixin like: .box-test { margin: 10px; @include browser(ie7) { margin: 20px; } } DESIRED OUTPUT: .box-test { margin: 10px; } .ie7 .box-test { margin: 20px; } the mixin i tried to make: @mixin browser($browserVar) { @if $browserVar == ie7 { .ie7 { @content } } @else if $browserVar == ie8 { .ie8 { @content; } }

How to make a Responsive (Row Fluid) Mixin for Bootstrap

两盒软妹~` 提交于 2019-12-06 07:01:29
问题 I can replace this code with <div class="row"> <div class="span10">...</div> <div class="span2">...</div> </div> With this, to make it more semantic <div class="article"> <div class="main-section">...</div> <div class="aside">...</div> </div> <!-- Less stylesheet --> .article { .makeRow(); .main-section { .makeColumn(10); } .aside { .makeColumn(2); } } How can I do this with the fluid grid though: <div class="row-fluid"> <div class="span10">...</div> <div class="span2">...</div> </div> <!--

Use LoginRequiredMixin and UserPassesTestMixin at the same time

我的梦境 提交于 2019-12-06 03:49:29
问题 I want to have a TemplateView Class that uses LoginRequiredMixin and UserPassesTestMixin at the same time. Something like this: from django.views.generic import TemplateView from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin class FinanceOverview(LoginRequiredMixin, UserPassesTestMixin, TemplateMixin): login_url = '/login' redirect_field_name = 'next' def test_func(self): return self.request.user.groups.filter(name="FinanceGrp").exists() def get(self, request,

How do you remove units of measurement from a Sass mixin equation?

不羁岁月 提交于 2019-12-06 02:05:34
问题 I've written a very simple Sass mixin for converting pixel values into rem values (see Jonathan Snook's article on the benefits of using rems). Here's the code: // Mixin Code $base_font_size: 10; // 10px @mixin rem($key,$px) { #{$key}: #{$px}px; #{$key}: #{$px/$base_font_size}rem; } // Include syntax p { @include rem(font-size,14); } // Rendered CSS p { font-size: 14px; font-size: 1.4rem; } This mixin works quite well, but I'm a bit unsatisfied with the include syntax for it. See, I would

Mixin common fields between serializers in Django Rest Framework

不打扰是莪最后的温柔 提交于 2019-12-05 21:59:51
问题 I have this: class GenericCharacterFieldMixin(): attributes = serializers.SerializerMethodField('character_attribute') skills = serializers.SerializerMethodField('character_skill') def character_attribute(self, obj): character_attribute_fields = {} character_attribute_fields['mental'] = {str(trait_item.get()): trait_item.get().current_value for trait_item in obj.mental_attributes} character_attribute_fields['physical'] = {str(trait_item.get()): trait_item.get().current_value for trait_item in

Error serializing Typed collection with Jackson

穿精又带淫゛_ 提交于 2019-12-05 21:46:51
I'm trying to serialize a collection using mixings, but Jackson won't save the type info. This is a basic test illustrating what happens: public class CollectionSerializationTest { interface Common extends Serializable { } class A implements Common { private static final long serialVersionUID = 1L; } @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = A.class, name = "CODE") }) class AMixIn { } @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({

LESS call a mixin dynamically

为君一笑 提交于 2019-12-05 21:03:30
How do you call a mixin dynamically? A use case might be to generate a style guide: // The mixin which should be called .typography-xs(){ font-family: Arial; font-size: 16px; line-height: 22px; } // The mixin which tries to call typography-xs .typography-demo(@typographyName, @mixinName) { @{typographyName} { &:before{content: '@{typographyName}';} // Calling the mixin dynamically @mixinName(); } } // Example call of .typograhpy-demo .typography-demo(xs, typography-xs); Is such a dynamic call possible at all with less css? You cannot at present dynamically call as you desire. You can, however,

Python Mixin - Unresolved Attribute Reference [PyCharm]

£可爱£侵袭症+ 提交于 2019-12-05 18:57:53
I am using a mixin to separate a range of functionality to a different class. This Mixin is only supposed to be mixable with the only child class: class Mixin: def complex_operation(self): return self.foo.capitalize() class A(Mixin): def __init__(self): self.foo = 'foo' in my method Mixin.complex_operation PyCharm gives warning 'Unresolved Attribute Reference foo'. Am I using the mixin pattern correctly? Is there a better way? (I would like to have type hints and autocompletion in my mixins, and I would like to have multiple mixins.) Declare the necessary fields in the Mixin like: class Mixin:

Python: Use of decorators v/s mixins? [closed]

倖福魔咒の 提交于 2019-12-05 11:45:51
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I have understood the basics of decorators and mixins. Decorators add a new functionality to an object without changing other object instances of the same class, while a mixin is a kind of multiple inheritance used to inherit from multiple parent classes. Does it mean that