Skip to content

Instantly share code, notes, and snippets.

@rmosolgo
rmosolgo / pre-commit
Last active August 29, 2015 14:01
check for focus and console.log before committing
#!/usr/bin/env ruby
if `git diff --cached spec` =~ /,\s?(:focus|focus:\s?true|:focus\s?=>\s?true)/
puts "\e[31mRemove your :focus tags before committing!\e[0m"
exit 1
end
if `git diff --cached spec` =~ /console\.log/
puts "\e[31mRemove your console.log before committing!\e[0m"
exit 1
@rmosolgo
rmosolgo / Gulpfile.js
Created May 1, 2014 03:19
Example app with batman.js and leaflet
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var jade = require('gulp-jade');
var batmanTemplates = require("gulp-batman-templates")
gulp.task('default', function(){
gulp.watch('./**/*', ["build", "html", "javascripts", "stylesheets", "finalize"])
});
@rmosolgo
rmosolgo / calculated_properties.coffee
Created April 29, 2014 21:14
Batman.js calcuated properties over collections
class App.Sale extends Batman.Model
@hasMany 'sale_items'
@accessor 'total_price', ->
memo = 0
# adds 'sale_items' and each item as a source
@get('sale_items').forEach (item) ->
memo += item.get('subtotal')
memo
@rmosolgo
rmosolgo / Gulpfile.js
Created April 18, 2014 16:12
Rendering into a Bootstrap JavaScript modal with Batman.js
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var jade = require('gulp-jade');
var batmanTemplates = require("gulp-batman-templates")
gulp.task('default', function(){
gulp.watch('./**/*', ["build", "html", "finalize"])
});
@rmosolgo
rmosolgo / json_storage.coffee
Last active August 29, 2015 13:59
Append `.json` to URLs for storage operations
# Taken from Batman.RailsStorage https://github.com/batmanjs/batman/blob/master/src/extras/batman.rails.coffee#L62
#
# Usage:
# #= require ./json_storage
# class MyApp.Model extends Batman.Model
# @persist Batman.JSONStorage
#
class Batman.JSONStorage extends Batman.RestStorage
# override the default URL functions to add .json:
urlForRecord: -> @_addJsonExtension(super)
@rmosolgo
rmosolgo / select_2_view.coffee
Created April 15, 2014 17:36
Batman.js Select2 Custom View
# Props to @theberg for making this
#
# usage:
#
# select data-view='Select2View' data-view-bind='item.option_id'
# option value='' None
# option data-foreach-opt='Option.all' data-bind='opt.name' data-bind-value='opt.id'
#
class App.Select2View extends Batman.View
@option 'bind', 'placeholder'
Loader =
show: ->
hide: ->
window.activeXhrCount = 0
window.globalLoaderEnabled = true
$(document).ajaxSend ->
window.activeXhrCount++
Loader.show()
.ajaxComplete ->
@rmosolgo
rmosolgo / Gulpfile.js
Created April 13, 2014 23:35
Render batman.js views into a modal
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var jade = require('gulp-jade');
var batmanTemplates = require("gulp-batman-templates")
gulp.task('default', function(){
gulp.watch('./**/*', ["build", "html", "finalize"])
});
@rmosolgo
rmosolgo / model observer.coffee
Created April 10, 2014 22:32
Observe attributes of a batmanjs Batman.Model
class MyApp.Thing extends Batman.Model
constructor: ->
super
# Whenever someProperty changes, capitalized property will be updated
@observe 'someProperty', (newValue, oldValue) ->
@set('capitalizedProperty', newValue?.toUpperCase())
@rmosolgo
rmosolgo / toJSON.coffee
Created March 25, 2014 20:08
override Model::toJSON to support accepts_nested_attributes_for
class App.Model extends Batman.Model
toJSON: ->
builtJSON = super
builtJSON.nested_items_attributes = builtJSON.nested_items
delete builtJSON.nested_items
builtJSON