Slide 1

Slide 1 text

A Sprinkling of Ember Brandon Hays @tehviking The Frontside

Slide 2

Slide 2 text

To paraphrase Doc Brown: I apologize for the crudity of this slide deck

Slide 3

Slide 3 text

You want a little interactivity You don’t want to rewrite your app

Slide 4

Slide 4 text

THE GOOGLES DO NOTHING

Slide 5

Slide 5 text

BUT ACTUALLY

Slide 6

Slide 6 text

It’s so easy I can show you in 5 minutes

Slide 7

Slide 7 text

1: Drop in a Component

Slide 8

Slide 8 text

What DHH means by “a sprinkling”

Slide 9

Slide 9 text

$(document).ready(function(){ $(".url-input-component-container").each(function(){ App.FsGifUrlInputComponent.create().replaceIn(this); }); });

Slide 10

Slide 10 text

App.FsGifUrlInputComponent = Ember.Component.extend({ layoutName: "components/fs-gif-url-input", gifUrl: null, urlIsValid: function(){ if(!!this.get("gifUrl")) { return this.get("gifUrl").match(/^(ht|f)tps?:\/\/[a- z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/); } }.property("gifUrl") });

Slide 11

Slide 11 text

Wait, that’s it?

Slide 12

Slide 12 text

Benefits over jQuery/ AJAX • Testability • Models, Computed Properties & bindings • Ember Data (No more writing $.ajax() ) • Reactivity between components • Super fun

Slide 13

Slide 13 text

2: Launch from a sub-URL

Slide 14

Slide 14 text

You want routes but you have an app

Slide 15

Slide 15 text

Get you an EmberController

Slide 16

Slide 16 text

class EmberController < ApplicationController def index end end class GifLinksController < ApplicationController ... # GET /gif_links/1/details # Send back to Ember to handle this route def details respond_to do |format| format.html { render "ember/index" } end end ... end

Slide 17

Slide 17 text

Tell your router(s) what’s up

Slide 18

Slide 18 text

# routes.rb Sprinkler::Application.routes.draw do resources :gif_links do get :details, on: :member end resources :ember, controller: "ember", only: [ :index ] root 'gif_links#index' end // router.js App.Router.map(function(){ this.route("gifDetails", {path: "gif_links/:id/details"}) }); App.Router.reopen({ location: 'history' });

Slide 19

Slide 19 text

Demo

Slide 20

Slide 20 text

Now the hand wavey part

Slide 21

Slide 21 text

J/K Here is some code https://github.com/ tehviking/sprinkler