Skip to content

Instantly share code, notes, and snippets.

View ncolgan's full-sized avatar

Nick Colgan ncolgan

  • Minneapolis, MN
View GitHub Profile
@machty
machty / router-js-refactor-architecture.md
Last active July 31, 2019 18:39
Overview of the architecture and approach to the router.js refactor

router.js Architecture

Let this serve as a guide for anyone who'd like to dig into router.js's internals, understand what's going on, and hopefully contribute!

Scope of router.js (et al)

router.js is most popularly known as the routing microlib used by the Ember.js Router, though other folk have been known to use it beyond Ember, including some Angular folk who weren't satisfied with

Basic Strategy

Take a match block and add routes to a RouteRecognizer:

match("/posts").to("posts", function(match) {
  match("/").to("postIndex")
  match("/:id").to("showPost");
  match("/edit").to("editPost");
@tomdale
tomdale / gist:3981133
Last active November 26, 2019 21:19
Ember.js Router API v2

WARNING

This gist is outdated! For the most up-to-date information, please see http://emberjs.com/guides/routing/!

It All Starts With Templates

An Ember application starts with its main template. Put your header, footer, and any other decorative content in application.handlebars.

<header>
App.Router.map(function(match) {
match("/posts/:post_id").to("post");
});
App.PostRoute = Ember.Route.extend({
// default implementation
deserialize: function(router, params) {
return App.Post.find(params.post_id);
},
@joshsusser
joshsusser / silence_assets.rb
Created April 17, 2012 22:34
put in config/initializers to silence asset logging in Rails development mode
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@n0nick
n0nick / form.js
Created December 22, 2011 16:55
Javascript extension for client_side_validations to support Formtastic Bootstrap form builder
clientSideValidations.formBuilders["FormtasticBootstrap::FormBuilder"] = {
add: function (element, settings, message) {
if (element.data('valid') !== false) {
element.addClass('error').data('valid', false);
var $parent = element.closest('.input');
$parent.parent().addClass('error');
$('<span/>').addClass('help-inline').text(message).appendTo($parent);
} else {
element.parent().find('span.help-inline').text(message);
@cowboy
cowboy / HEY-YOU.md
Last active September 2, 2024 04:03
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.