mixins

Can you test if a mixin exists?

我是研究僧i 提交于 2019-12-05 00:16:35
Sass quick question (hopefully) here. Can you test for the existence of a mixin? e.g. @if thumbnail-mixin {} @else { //define mixin }. Ideally I'd use @unless , but that only exists on a fork. I'm aware you can overwrite a mixin but I'm thinking more if you can have a default mixin, rather than having to specify N variables in every case. Sass does not currently have native functionality to determine if a mixin exists or not. https://github.com/nex3/sass/issues/561#issuecomment-14430978 You could create a Sass function written in Ruby: def mixin_exists(mixin_name) if(environment.mixin(mixin

How to get the `self` to refer to a my class inside a Mixin module (even if it is stated outside the context of a method)?

Deadly 提交于 2019-12-04 21:19:19
I am using Ruby on Rails 3.2.2. I have implemented a Mixin module for a Article model class and I would like to get the self to refer to Article (even, for example, if it stated outside the context of a method). That is, I am trying to make the following: module MyModule extend ActiveSupport::Concern # Note: The following is just a sample code (it doesn't work for what I am # trying to accomplish) since 'self' isn't referring to Article but to the # MyModule itself. include MyModule::AnotherMyModule if self.my_article_method? ... end The above code generates the following error: undefined

Mixins in Tapestry5

一个人想着一个人 提交于 2019-12-04 20:47:08
I'm new to Tapestry5, but because of an internship I need to work with it. Currently I am trying to build a mixin to integrate a CSRF token ( explanation here ) to any form. Is it even possible to achieve this in a mixin? If yes, could I access functions that the mixin offers from the page? I am really not sure about how mixins really work and I'm having big difficulties on finding information about how to create one. Can somebody explain how to create a mixin and if what I'm trying to do is even possible? Thanks a lot! You might find that the HMAC message authentication introduced in tapestry

Dynamic class names in LESS

廉价感情. 提交于 2019-12-04 18:33:22
问题 I have the following bit of LESS code working @iterations: 940; @iterations: 940; @col:2.0833333333333333333333333333333%; // helper class, will never show up in resulting css // will be called as long the index is above 0 .loopingClass (@index) when (@index > -20) { // create the actual css selector, example will result in // .myclass_30, .myclass_28, .... , .myclass_1 (~".gs@{index}") { // your resulting css width: (@index/20+1)*@col; } // next iteration .loopingClass(@index - 60); } // end

Using LESS mixin to set variable multiple times but getting wrong results

倖福魔咒の 提交于 2019-12-04 17:32:09
At the front, I started with less today... So any advice how to do that better is welcome! I have following .less file: .test(@target;@context) { @em: (@target / @context) * 1em; } .custom-field { position: relative; .test(30;16); padding-bottom: @em; .test(30;16); margin-bottom: @em; .test(320;16); max-width: @em; } I expect that padding-bottom and margin-bottom getting the value 1.875 and max-width: 20. But thats the output: .custom-field { position: relative; padding-bottom: 1.875em; margin-bottom: 1.875em; max-width: 1.875em; } I had the second parameter as an optional parameter at the

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

别说谁变了你拦得住时间么 提交于 2019-12-04 16:59:02
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; } } @else if $browserVar == ie9 { .ie9 { @content; } } } the problem is the output is: .box-test { margin:

Difference between @Delegate and @Mixin AST transformations in Groovy

馋奶兔 提交于 2019-12-04 16:45:22
问题 What's the difference between @Delegate and @Mixin AST transformations in Groovy. Maybe my question has to do with OO and when apply different patterns, but I use both and I can achieve the same behavior. class Person { String name = "Clark" def walk() { "Walk" } } @Mixin(Person) class Superhero { def fly() { "Fly" } } def superman = new Superhero() assert superman.name == "Clark" assert superman.walk() == "Walk" assert superman.fly() == "Fly" class Person { String name = "Clark" def walk() {

Doing math on variable argument Sass mixins

这一生的挚爱 提交于 2019-12-04 16:39:46
问题 I like to use rem units with pixel fallbacks for my CSS sizing and am trying to make mixins to help with that. For font-size, this is easy: @mixin font-size($size) { font-size: $size + px; font-size: ($size / 10) + rem; } But for padding, margin, etc. the mixin needs to accept variable arguments, which is possible per the Sass documentation http://sass-lang.com/documentation/file.SASS_REFERENCE.html#variable_arguments However, with the following mixin, instead of dividing by 10, the mixin is

Intersection of mapped types

[亡魂溺海] 提交于 2019-12-04 14:35:23
Consider the following: type Properties = { foo: { n: number }; bar: { s: string }; baz: { b: boolean }; }; declare function retrieveValues<K extends keyof Properties>(add?: K[]): Pick<Properties, K>[K]; // what happens const x: { n: number } | { s: string } = retrieveValues(['foo', 'bar']); // what I'm really trying to express (type error) const y: { n: number } & { s: string } = retrieveValues(['foo', 'bar']); Is there a way to get an intersection of the properties of Pick<Properties, K> ? Or just a different way to get the intersection of a set of types based on the presence of relevant

Understanding ruby metaprogramming using method_added to overwrite instance methods dynamically

跟風遠走 提交于 2019-12-04 12:36:58
问题 I have the following code from Programming Ruby 1.9 (slightly adapted) I just want to ensure my thought process is accurate module Trace def self.included(culprit) #Inject existing methods with tracing code: culprit.instance_methods(false).each do |func| inject(culprit, func) end #Override the singletons method_added to ensure all future methods are injected. def culprit.method_added(meth) unless @trace_calls_internal @trace_calls_internal = true Trace.inject(self, meth) #This will call