Search Results

Search found 51 results on 3 pages for 'mixin'.

Page 1/3 | 1 2 3  | Next Page >

  • Groovy Mixin on Instance (Dynamic Mixin)

    - by david
    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 chance to get this working like proposed in the Groovy Mixins JSR?

    Read the article

  • Using one mixin from LESS within another mixin

    - by user1165984
    I am trying to use a mix that calculates the base line height in another that contains my base font styles. Each time I try to compile, I get an error. Here is an example. .lineHeight(@sizeValue){ @remValue: @sizeValue; @pxValue: (@sizeValue * 10); line-height: ~"@{pxValue}px"; line-height: ~"@{remValue}rem"; } .baseFont(@weight: normal, @size: 14px, @lineHeight: (.lineHeight(2.1)) { font-family: @fontFamily; font-size: @size; font-weight: @weight; line-height: @lineHeight; } The error is: TypeError: Cannot call method 'charAt' of undefined at getLocation (/Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:212:34) at new LessError (/Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:221:19) at Object.toCSS (/Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:385:31) at /Applications/CodeKit.app/Contents/Resources/engines/less/bin/lessc:107:28 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:434:40 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:94:48 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/index.js:116:17 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:434:40 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:94:48 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/index.js:116:17

    Read the article

  • Mixin or Trait implementation in AS3?

    - by Brian Heylin
    I'm looking for ideas on how to implement a Mixin/Trait style system in AS3. I want to be able to compose a number of classes together into a single object. Of course this is not a language level feature of AS3, but I'm hoping that there is maybe some way to do this using prototype based techniques or maybe some bytecode hacking that I believe AsMock uses to implement it's functionality. An existing Java example is Qi4J where the user define interfaces that the Qi4j framework implements based on metadata tags and coding by convention. Has anyone any ideas on how to get the Mixin/Trait concept working within AS3?

    Read the article

  • Help creating a JavaScript mixin in Tapestry5?

    - by shane87
    I am creating a mixin which renders a javascript file when a textfield gains focus. I am new to the idea of mixins in Tapestry, and I am unsure of where to place my original javascript file which i wish to run when the textfield gains focus. The following is an example of my code: The Java mixin class: package asc.mixins; import org.apache.tapestry5.RenderSupport; import org.apache.tapestry5.annotations.AfterRender; import org.apache.tapestry5.annotations.Environmental; import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary; import org.apache.tapestry5.annotations.InjectContainer; import org.apache.tapestry5.corelib.base.AbstractTextField; @IncludeJavaScriptLibrary("js_dasher_mixin.js") public class DasherMixin { @Environmental private RenderSupport renderSupport; @InjectContainer private AbstractTextField field; @AfterRender void addScript() { this.renderSupport.addScript("new JSDasher('%s');", this.field.getClientId()); } } The Javascript mixin file: JSDasher = Class.create({ initialize: function(textField) { this.textField = $(textField); this.textField.observe('focus', this.onFocus.bindAsEventListener(this)); }, onFocus: function(event) { //call my javascript init() function } } part of my javascript file I wish to run when the textfield gains focus: var posX, posY; // Sets up our global variables and dispatches an init request to the server. function init() { posX=0; posY=0; canvas = document.getElementById("canvas"); canvasWidth = canvas.offsetWidth; canvasHeight = canvas.offsetHeight; if (canvas.getContext) { ctx = canvas.getContext("2d"); } canvas.onclick = canvasClicked; canvas.onmousemove = mouseMoved; canvasOffsetX = findPosX(canvas); canvasOffsetY = findPosY(canvas); sessID = -1; sendInitRQ(canvasWidth, canvasHeight); } My javascript file is much larger than above, my question is where should I put my javascript code above? Should it all be contained in the mixin.js file? if so where exactly should it go? Thanks in advance for any help.

    Read the article

  • Sass mixin not compiling?

    - by corroded
    I have previously made a mixin in sass 2.2.22 for my font sizes(it's a font converter), like so: =6.5pts :font :size 9px It has been working ever since i first made it a year ago. We just upgraded to haml/sass 3 and now whenever I try to refresh the page im working on, a sass compile error appears like so: http://grab.by/4yFE I don't get it since Sass 3 documentation says that the = declaration for mixins is NOT deprecated. I tried uninstalling haml 3.0, restarted my server and deleted the generated css file and now it apparently works. Problem is, I need haml 3 for another related project where we just started using Compass. Why is the compiler complaining when the documentation claims the declaration is not deprecated?

    Read the article

  • SASS mixin for swapping images / floats on site language (change)

    - by DBUK
    Currently using SASS on a website build. It is my first project using it, tried a little LESS before and liked it. I made a few basic mixins and variables with LESS, super useful stuff! I am trying to get my head around SASS mixins, and syntax, specifically for swapping images when the page changes to a different language, be that with body ID changing or <html lang="en">. And, swapping floats around if, for example, a website changed to chinese. So a mixin where float left is float left unless language is AR and then it becomes float right. With LESS I think it would be something like: .headerBg() when (@lang = en) {background-image:url(../img/hello.png);} .headerBg() when (@lang = it) {background-image:url(../img/ciao.png);} .header {.headerBg(); width: 200px; height:100px} .floatleft() when (@lang = en) { float: left;} .floatleft() when (@lang = ar) { float: right;} .logo {.floatleft();} Its the syntax I am having problems with combined with a brain melting day.

    Read the article

  • Does Objective-C support Mixin like Ruby?

    - by hacksignal
    In Ruby, there's Modules and you can extend a class by "mixing-in" the module. Module myModule def printone print "one" end end Class myClass extend myModule end theOne = myClass.new theOne.printone >> one In Objective-C, I find that I have a set of common methods that I want a number of Class to "inherit". What other ways can I achieve this without creating a common class and deriving all from that common class?

    Read the article

  • call a class method from inside an instance method from a module mixin (rails)

    - by sean
    Curious how one would go about calling a class method from inside an instance method of a module which is included by an active record class. For example I want both user and client models to share the nuts and bolts of password encryption. # app/models class User < ActiveRecord::Base include Encrypt end class Client < ActiveRecord::Base include Encrypt end # app/models/shared/encrypt.rb module Encrypt def authenticate # I want to call the ClassMethods#encrypt_password method when @user.authenticate is run self.password_crypted == self.encrypt_password(self.password) end def self.included(base) base.extend ClassMethods end module ClassMethods def encrypt_password(password) Digest::SHA1.hexdigest(password) end end end However, this fails. Says that the class method cannot be found when the instance method calls it. I can call User.encrypt_password('password') but User.new.encrypt_password fails Any thoughts?

    Read the article

  • Why is -webkit-keyframes not working in my SASS mixin?

    - by Tintin81
    I have this SASS mixin that should make a button flash: @mixin background_animation($color) { -webkit-animation: backgroundAnimation 800ms infinite; @-webkit-keyframes backgroundAnimation { 0% {background-color: $color;} 50% {background-color: red;} 100% {background-color: $color;} } } I am using it like this: @include background_animation(#000000); However, it's not working. The background color of the button won't flash. Can anybody tell me what I'm missing here? P.S. The code works fine when not including it as a mixin. The generated CSS looks like this: -webkit-animation-delay: 0s; -webkit-animation-direction: normal; -webkit-animation-duration: 0.800000011920929s; -webkit-animation-fill-mode: none; -webkit-animation-iteration-count: infinite; -webkit-animation-name: backgroundAnimation; -webkit-animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1); ... other rules omitted for brevity

    Read the article

  • Groovy MetaClass - Add category methods to appropriate metaClasses

    - by noah
    I have several categories that I use in my Grails plugin. e.g., class Foo { static foo(ClassA a,Object someArg) { ... } static bar(ClassB b,Object... someArgs) { ... } } I'm looking for the best way to add these methods to the meta-classes so that I don't have to use the category classes and can just invoke them as instance methods. e.g., aInstance.foo(someArg) bInstance.bar(someArgs) Is there a Groovy/Grails class or method that will help me do this or am I stuck iterating through the methods and adding them all myself?

    Read the article

  • Accessing a class's containing namespace from within a module

    - by SFEley
    I'm working on a module that, among other things, will add some generic 'finder' type functionality to the class you mix it into. The problem: for reasons of convenience and aesthetics, I want to include some functionality outside the class, in the same scope as the class itself. For example: class User include MyMagicMixin end # Should automagically enable: User.name('Bob') # Returns first user named Bob Users.name('Bob') # Returns ALL users named Bob User(5) # Returns the user with an ID of 5 Users # Returns all users I can do the functionality within these methods, no problem. And case 1 (User.name('Bob')) is easy. Cases 2–4, however, require being able to create new classes and methods outside User. The Module.included method gives me access to the class, but not to its containing scope. There is no simple "parent" type method that I can see on Class nor Module. (For namespace, I mean, not superclass nor nested modules.) The best way I can think to do this is with some string parsing on the class's #name to break out its namespace, and then turn the string back into a constant. But that seems clumsy, and given that this is Ruby, I feel like there should be a more elegant way. Does anyone have ideas? Or am I just being too clever for my own good?

    Read the article

  • Mixins, variadic templates, and CRTP in C++

    - by Eitan
    Here's the scenario: I'd like to have a host class that can have a variable number of mixins (not too hard with variadic templates--see for example http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.103.144). However, I'd also like the mixins to be parameterized by the host class, so that they can refer to its public types (using the CRTP idiom). The problem arises when trying to mix the too--the correct syntax is unclear to me. For example, the following code fails to compile with g++ 4.4.1: template <template<class> class... Mixins> class Host : public Mixins<Host<Mixins>>... { public: template <class... Args> Host(Args&&... args) : Mixins<Host>(std::forward<Args>(args))... {} }; template <class Host> struct Mix1 {}; template <class Host> struct Mix2 {}; typedef Host<Mix1, Mix2> TopHost; TopHost *th = new TopHost(Mix1<TopHost>(), Mix2<TopHost>()); With the error: tst.cpp: In constructor ‘Host<Mixins>::Host(Args&& ...) [with Args = Mix1<Host<Mix1, Mix2> >, Mix2<Host<Mix1, Mix2> >, Mixins = Mix1, Mix2]’: tst.cpp:33: instantiated from here tst.cpp:18: error: type ‘Mix1<Host<Mix1, Mix2> >’ is not a direct base of ‘Host<Mix1, Mix2>’ tst.cpp:18: error: type ‘Mix2<Host<Mix1, Mix2> >’ is not a direct base of ‘Host<Mix1, Mix2>’ Does anyone have successful experience mixing variadic templates with CRTP?

    Read the article

  • Can you define <=> in Ruby and then have ==, >, <, >=, and <= defined automatically?

    - by jeremy Ruten
    Here's part of my Note class: class Note attr_accessor :semitones, :letter, :accidental def initialize(semitones, letter, accidental = :n) @semitones, @letter, @accidental = semitones, letter, accidental end def <=>(other) @semitones <=> other.semitones end def ==(other) @semitones == other.semitones end def >(other) @semitones > other.semitones end def <(other) @semitones < other.semitones end end It seems to me like there should be a module that I could include that could give me my equality and comparison operators based on my <=> method. Is there one? I'm guessing a lot of people run into this kind of problem. How do you usually solve it? (How do you make it DRY?)

    Read the article

  • Qt: Is it possible to use mixins technique?

    - by Eye of Hell
    Hello. Qt library includes advanced meta-programming capabilities using they own preprocessing moc compiler. Does anyone knows, is it possible to create some kind of mix-ins via it? For example, i have a QString and want to add a method to it without sub-classing and changing existing code. Does Qt have such solutions for that?

    Read the article

  • C++ dynamic type construction and detection

    - by KneLL
    There was an interesting problem in C++, but it concerns more likely architecture. There are many (10, 20, 40, etc) classes that describe some characteristics (mix-in classes), for exmaple: struct Base { virtual ~Base() {} }; struct A : virtual public Base { int size; }; struct B : virtual public Base { float x, y; }; struct C : virtual public Base { bool some_bool_state; }; struct D : virtual public Base { string str; } // .... Primary module declares and exports a function (for simplicity just function declarations without classes): // .h file void operate(Base *pBase); // .cpp file void operate(Base *pBase) { // .... } Any other module can has a code like this: #include "mixins.h" #include "primary.h" class obj1_t : public A, public C, public D {}; class obj2_t : public B, public D {}; // ... void Pass() { obj1_t obj1; obj2_t obj2; operate(&obj1); operate(&obj2); } The question is how to know what the real type of given object in operate() without dynamic_cast and any type information in classes (constants, etc)? Function operate() is used with big array of objects in small time periods and dynamic_cast is too slow for it. And I don't want to include constants (enum obj_type { ... }) because this is not OOP-way. // module operate.cpp void some_operate(Base *pBase) { processA(pBase); processB(pBase); } void processA(A *pA) { } void processB(B *pB) { } I cannot directly pass a pBase to these functions. And it's impossible to have all possible combinations of classes, because I can add new classes just by including new .h files. As one of solutions that comed to mind, in editor application I can use a composite container: struct CompositeObject { vector<Base *pBase> parts; }; But editor does not need a time optimization and can use dynamic_cast for parts to determine the exact type. In operate() I cannot use this solution. So, is it possible to not use a dynamic_cast and type information to solve this problem? Or maybe I should use another architecture?

    Read the article

  • How can I fix Problems with interlaced video jerking/flicking when playedback on DVD players? (Mixin

    - by Simon P Stevens
    I'm trying to make a DVD and the final DVD jerks when played on standalone DVD players. It seems to play fine on PCs. I think the problem may be to do with interlacing settings when rendering the final output, but I'll outline the whole editing process I have followed in case I've made a mistake somewhere else. Most of the footage comes from a sony handy cam (one of those mini DVD ones) so isn't great quality. It was set to "high quality" (haha) and 16:9 aspect ratio when it was recorded. I copy the files directly from the mini DVDs onto the hard drive and import them into Cinelerra. In Cinelerra I set the format to 25fps, 720x576, RGBA-8bit, 16:9, interlaced bottom fields first. When I've finished the editing, I add a Fields to frames effect (set to bottom first) to each video track. I render to audio and video separately: Audio: AC3, 128kbps Video: YUV4MPEG steam, video pipe settings: ffmpeg -f yuv4mpegpipe -i - -y -target dvd -flags +ilme+ildct mpeg2video % Cinelerra often crashes during the rendering, so I set it to generate a new video file at each label, and combine them using cat when I've got a sucesful render of each one. Once I've combined them, I use mencoder to re-index them: mencoder -forceidx -oac copy -ovc copy merged.m2v -o mergedReIndexed.m2v I combine the audio and video files using ffmpeg: ffmpeg -i AudioFile.ac3 -i VideoFile.m2v -target dvd -flags +ilme+ildct FinalMovie.mpg Then I build the menus with spumux and I create the DVD file system with dvdauthor, and finally I write it do a dvd-r like this: nice -n -20 growisofs -dvd-compat -speed=2 -Z /dev/dvd -dvd-video -V VIDEO ./ && eject /dev/dvd Originally, when I did it the DVD flickered badly, so as suggested in a guide I added the fields to frames effect in cinelerra. Now it doesn't "flicker", but has become "jerky" when there is lots of motion, particularly when the camera is moving, so the whole background moves. This is what I've tried so far: Removed "mpeg2video" from cinelerra video render pipe. Removed +ilme from render pipe. Removed +ildct from render pipe. Removed +ilme from render audio/video rejoin command. Removed +ildct from render audio/video rejoin command. Added -alt to render pipe. Added -alt to render audio/video rejoin command. Tried with and without the frames to fields effect in Cinelerra. and various combinations of the above. I've also tried this: change the Cinelerra fps to 50, use fields to frames (instead of frames to fields), render to an intermediate QTforlinux jpeg video stream, re-importing that back into Cinelerra, adding a frames to fields effect and then rendering that output as normal (@25fps), and I still have the same problem. Has anyone experienced this "jerking" playback before? Can anyone give any suggestions on how to fix it? (Like I say, it plays back fine on a PC, but not on any of the standalone players I've tried)

    Read the article

  • Override ActiveRecord#save, Method Alias? Trying to mixin functionality into save method...

    - by viatropos
    Here's the situation: I have a User model, and two modules for authentication: Oauth and Openid. Both of them override ActiveRecord#save, and have a fair share of implementation logic. Given that I can tell when the user is trying to login via Oauth vs. Openid, but that both of them have overridden save, how do "finally" override save such that I can conditionally call one of the modules' implementations of it? Here is the base structure of what I'm describing: module UsesOauth def self.included(base) base.class_eval do def save puts "Saving with Oauth!" end def save_with_oauth save end end end end module UsesOpenid def self.included(base) base.class_eval do def save puts "Saving with OpenID!" end def save_with_openid save end end end end module Sequencer def save if using_oauth? save_with_oauth elsif using_openid? save_with_openid else super end end end class User < ActiveRecord::Base include UsesOauth include UsesOpenid include Sequencer end I was thinking about using alias_method like so, but that got too complicated, because I might have 1 or 2 more similar modules. I also tried using those save_with_oauth methods (shown above), which almost works. The only thing that's missing is that I also need to call ActiveRecord::Base#save (the super method), so something like this: def save_with_oauth # do this and that super.save # the rest end But I'm not allowed to do that in ruby. Any ideas for a clever solution to this?

    Read the article

  • Avoiding NPE in trait initialization without using lazy vals

    - by 0__
    This is probably covered by the blog entry by Jesse Eichar—still I can't figure out how to correct the following without residing to lazy vals so that the NPE is fixed: Given trait FooLike { def foo: String } case class Foo( foo: String ) extends FooLike trait Sys { type D <: FooLike def bar: D } trait Confluent extends Sys { type D = Foo } trait Mixin extends Sys { val global = bar.foo } First attempt: class System1 extends Mixin with Confluent { val bar = Foo( "npe" ) } new System1 // boom!! Second attempt, changing mixin order class System2 extends Confluent with Mixin { val bar = Foo( "npe" ) } new System2 // boom!! Now I use both bar and global very heavily, and therefore I don't want to pay a lazy-val tax just because Scala (2.9.2) doesn't get the initialisation right. What to do?

    Read the article

  • How can I reverse ruby's include function.

    - by Glen
    I'll explain what i'm looking for in code as thats probably the most succinct: module Mixin def method puts "Foo" end end class Whatever include Mixin end w = Whatever.new w.method => "Foo" # some magic here w2 = Whatever.new w.method => NoMethodError I had tried just undefining the Mixin module using remove_const, but this doesn't seem to make any difference to Whatever. I had assumed that #include just added a reference to the module into the class's method resolution chain - but this behaviour doesn't agree with that. Can anyone tell me what include actually does behind the scenes, and how to reverse this?

    Read the article

  • How to extent activrerecord,just make id to id.to_i

    - by qichunren
    module ActiveRecord module Mixin alias old_id id def id old_id.to_i end def hello "hellooooooooooooo" end end end ActiveRecord::Base.send :include, ActiveRecord::Mixin I make is because: id column in oracle is number type,not number(10), @user.id return 123.0,not 123,so I would like to do it by extend ar. But my way above does not work for me,it still show number with dot zero,123.0. How to make id auto invove id.to_i???

    Read the article

  • What does ruby include when it encounters the "include module" statement?

    - by Steve Weet
    If I have the following project structure project/ lib/ subproject/ a.rb b.rb lib.rb where lib.rb looks like this :- module subproject def foo do_some_stuff end end and a.rb and b.rb both need to mixin some methods within lib.rb and are both namespaced within a module like so :- require 'subproject/lib' module subproject class A include Subproject def initialize() foo() end end end What does ruby do when it encounters the include statement? How does it know that I want to only include the mixin from lib.rb rather than the whole module which includes both class A and class B, is this based purely on the require of subproject/lib or am I getting it wrong and it is including the whole of the module, including the definitions of Class A and B within themselves?

    Read the article

1 2 3  | Next Page >