This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass | |
foo: -> | |
alert "foobar" | |
bar: -> | |
alert "barfoo" | |
@foo() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass | |
simple: -> | |
alert "hello!" | |
another: -> | |
alert "hi!" | |
withParams: (a, b) -> | |
alert a + " - " + b | |
withReturnValue: (a) -> | |
return 2 * a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tunkkaus | |
import org.grails.plugin.resource.ResourceMeta | |
import org.grails.plugin.resource.ResourceProcessor | |
import org.grails.plugin.resource.mapper.MapperPhase; | |
import org.grails.plugin.resource.module.ModuleBuilder | |
import org.springframework.util.AntPathMatcher | |
/** | |
* We are using prefix '_' because we want that this resource mapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.tunkkaus._MultiModuleResourceMapper | |
beans = { | |
_MultiModuleResourceMapper.enable() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PART 1: tweak backbone validation a little bit | |
# =============================================== | |
# first, allow errorous inputs to update our model | |
Backbone.Validation.configure | |
forceUpdate: true | |
# then disable default callbacks for backbone validation events | |
_.extend Backbone.Validation.callbacks, | |
valid: (view, attr, selector) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PART 2: bind our backbone view to validation events and also for | |
# input changes so that model changes automatically when input changes | |
# ======================================================================= | |
# This defines which element's attribute will be used for linking | |
inputSelector = 'name' | |
# model update function, which is called when input changes | |
updateModel = (model, attr, value) -> | |
model.set(attr, value || null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery -> | |
# Simple person model with two attributes | |
class Person extends Backbone.Model | |
validation: | |
age: | |
required: true | |
min: 10 | |
name: | |
required: true | |
msg: "All persons have a name..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/x-template" id="person-form-template"> | |
<div class="form-horizontal"> | |
<div class="control-group"> | |
<label class="control-label" for="name">Name</label> | |
<div class="controls"><input class="input" type="text" name="name" id="name" value="{{name}}" /></div> | |
</div> | |
<div class="control-group"> | |
<label class="control-label" for="age">Age</label> | |
<div class="controls"><input class="input" type="number" name="age" id="age" value="{{age}}" /></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object OrderingDSLExample extends App { | |
case class My(num: Int, str: String) | |
val myValues = List(My(3, "foo"), My(3, "bar"), My(5, "bar"), My(5, "foo")) | |
import OrderingDSL._ | |
require(myValues.sortBy(m => (asc(m.num), asc(m.str))) == | |
List(My(3, "bar"), My(3, "foo"), My(5, "bar"), My(5, "foo"))) | |
require(myValues.sortBy(m => (asc(m.num), desc(m.str))) == | |
List(My(3, "foo"), My(3, "bar"), My(5, "foo"), My(5, "bar"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object OrderingDSL { | |
case class AscendingOrder[T](value: T)(implicit ord: Ordering[T]) extends Ordered[AscendingOrder[T]] { | |
def compare(that: AscendingOrder[T]): Int = ord.compare(value, that.value) | |
} | |
case class DescendingOrder[T](value: T)(implicit ord: Ordering[T]) extends Ordered[DescendingOrder[T]] { | |
def compare(that: DescendingOrder[T]): Int = -ord.compare(value, that.value) | |
} | |
def asc[T](value: T)(implicit ord: Ordering[T]) = AscendingOrder(value) |
OlderNewer