This file contains hidden or 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
| /** | |
| * Assign a value to the delimited key in the given object. The inverse of `_.lookup` | |
| * | |
| * @example | |
| * | |
| * var myObj = {}; | |
| * | |
| * _.assign(myObj, 'foo.bar', 'baz'); // myObj = { foo: { bar: 'baz' }} | |
| * | |
| * @param {Object} obj the object to assign to |
This file contains hidden or 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
| # Very simple Mediator in Coffeescript | |
| # Based on the Pub/Sub implementation by rpflorence (https://github.com/rpflorence) | |
| class Mediator | |
| constructor: -> | |
| @channels = {} | |
| subscribe: (name, callback) -> | |
| @channels[name] = [] unless @channels[name]? |
This file contains hidden or 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
| # Monkey-patch Backbone.History to filter/rewrite/inject routes | |
| # see: http://blog.rjzaworski.com/2012/08/filtering-backbone-routes/ | |
| do (History = Backbone.History) -> | |
| _navigate = History::navigate | |
| methods = | |
| filter: (fragment) -> | |
| if fragment == 'NOOP' | |
| return null | |
| fragment |
This file contains hidden or 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
| # A class-based template for jQuery plugins in Coffeescript | |
| # | |
| # $('.target').myPlugin({ paramA: 'not-foo' }); | |
| # $('.target').myPlugin('myMethod', 'Hello, world'); | |
| # | |
| # Check out Alan Hogan's original jQuery plugin template: | |
| # https://github.com/alanhogan/Coffeescript-jQuery-Plugin-Template | |
| # | |
| (($, window) -> |
This file contains hidden or 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
| My::Application.routes.draw do | |
| # Include route definitions here | |
| # ... | |
| # Delegate +/jasmine+ routes to Jasminerice in development only | |
| # see: https://github.com/bradphelan/jasminerice/blob/master/config/routes.rb | |
| if Rails.env.development? | |
| mount Jasminerice::Engine => '/jasmine' |
This file contains hidden or 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
| # Demonstrate helper for rendering twitter intents | |
| # | |
| # Usage: | |
| # | |
| # Twitter::Intents.tweet( | |
| # :text => 'Hello, world!', | |
| # :via => 'rjzaworski', | |
| # :url => 'https://gist.github.com/gists/4012584' | |
| # ) | |
| # |
This file contains hidden or 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
| # Expressive filters for Backbone Collections. | |
| # | |
| # (1) Define a filter: | |
| # | |
| # class MyCollectionFilter extends CollectionFilter | |
| # matches: (model) -> | |
| # model.get('title') == @query | |
| # | |
| # (2) Find matching models by applying it: | |
| # |
This file contains hidden or 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
| # config/initializers/formtastic.rb | |
| module FormtasticBootstrap | |
| class FormBuilder < Formtastic::FormBuilder | |
| # Allow "split-field" inputs such as name (first+last) or location (city+state). | |
| # Block contents are wrapped in a ".controls" field set next to the specified | |
| # +label+ | |
| # | |
| # Usage: | |
| # |
This file contains hidden or 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
| # Methods for cycling through the models in a Backbone Collection | |
| # Usage: | |
| # | |
| # c = new MyCollection([...]) | |
| # nextModel = c.modelAfter(myModel) | |
| # myModel == c.modelBefore(nextModel) | |
| # # true | |
| # | |
| class MyCollection extends Backbone.Collection |
This file contains hidden or 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
| # Match index page ('/') when using pushState in Backbone | |
| class IndexRouter extends Backbone.Router | |
| initialize: (options) -> | |
| # Supply a matcher for both blank and '/' routes: | |
| @route /^\/?$/, 'index', @.index | |
| index: -> | |
| # Serve up an index view |