Skip to content

Instantly share code, notes, and snippets.

View StevenLangbroek's full-sized avatar

Steven Langbroek StevenLangbroek

View GitHub Profile
@StevenLangbroek
StevenLangbroek / renderer.coffee
Created January 29, 2014 23:21
Marionette Renderer override to use `grunt-contrib-handlebars`
_.extend Marionette.Renderer,
render: (template, data) ->
throw "Template #{template} not found!" unless JST[template]
JST[template](data)
@StevenLangbroek
StevenLangbroek / app.js
Last active August 29, 2015 13:56
Live filtering with Marionette in 39 lines of JS.
var M = Backbone.Marionette;
var App = new M.Application();
var ListItem = M.ItemView.extend({
tagName: 'li',
template: _.template('<h4 class="question"><%= question %></h4><p style="display: none;"><%= answer %></p>')
});
var List = M.CollectionView.extend({
@StevenLangbroek
StevenLangbroek / template.html
Last active August 29, 2015 13:56
TemplateHelpers
<script type="text/handlebars" id="my_list_template">
<div class="{{whichuser}}">
<img src="{{ image }}">
<div class="message_body">
{{{message_body}}}
</div>
</div>
</script>
// Generated on 2014-03-05 using generator-webapp 0.4.7
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/**/*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
@StevenLangbroek
StevenLangbroek / views.coffee
Created March 27, 2014 13:02
Given this code, how can I still add templateHelpers to individual views?
@AnalyticsApp.module "Views", (Views, App, Backbone, Marionette, $, _) ->
_.extend Marionette.View::,
templateHelpers: ->
form:
App.request "get:form"
i18n:
App.request "get:i18n"
describe "Saving", ->
before ->
@syncSpy = sinon.spy()
@syncStub = sinon.stub(Backbone, 'sync', @syncSpy)
@changeSpy = sinon.spy()
afterEach ->
@syncSpy.reset()
it 'sets errors on the model when trying to save', ->
@StevenLangbroek
StevenLangbroek / flightplan.js
Last active August 29, 2015 14:11
Sample Flightplan for Deployments + Rollbacks
var plan = require('flightplan');
var moment = require('moment');
var currentTime = new Date().getTime();
var formattedCurrentTime = moment(currentTime).format('YYYY-MM-DD_HH-mm');
var backupsFilename = 'backups.json';
plan.target('staging', {
host: 'staging.some-host.com',
username: 'root-level-user',
@StevenLangbroek
StevenLangbroek / README.md
Created March 23, 2015 17:22
"Get Posts" Tag independent of "the loop".

Get Posts independent of URL.

As a stand-in to a full-fledged, publicly accessible JSON API, it would be incredibly liberating to have a Handlebars helper which allows us to loop through posts by parameters (maybe query params could even be mixed into the Handlebars context) instead of some internal state dictated by the URL. This would allow for easy creation of "related content", or a "search" function.

@StevenLangbroek
StevenLangbroek / UserView.js
Last active August 29, 2015 14:17
Backbone pattern not possible with ES6 Classes
import BaseView from './BaseView';
import listenToMany from '../utils/listenToMany';
import template from '../templates/user';
// Backbone's extend + ES6
export default BaseView.extend({
template,
listenToMany
});
@StevenLangbroek
StevenLangbroek / 01_readme.md
Created March 30, 2015 13:46
Marty.js weirdness

When I render OfferList through React Router, The result is a rejected promise, saying:

`An error occured when handling the DONE state of a fetch`

{
  message: "Not found",
  name: "Not found",
  status: 404

}