61
Hardcore! Extending Rails 3 Rick Martinez Tuesday, June 15, 2010

Hardcore Extending Rails 3 - From RailsConf '10

Embed Size (px)

DESCRIPTION

Rick Martinez's presentation on some useless, but inspiring, ways to extend Rails 3.

Citation preview

Page 1: Hardcore Extending Rails 3 - From RailsConf '10

Hardcore!Extending Rails 3

Rick Martinez

Tuesday, June 15, 2010

Page 2: Hardcore Extending Rails 3 - From RailsConf '10

- Dave Thomas

Tuesday, June 15, 2010

Page 3: Hardcore Extending Rails 3 - From RailsConf '10

core

Tuesday, June 15, 2010

Page 4: Hardcore Extending Rails 3 - From RailsConf '10

"when I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

Duck Typing

Tuesday, June 15, 2010

Page 5: Hardcore Extending Rails 3 - From RailsConf '10

Rails 2

Tuesday, June 15, 2010

Page 6: Hardcore Extending Rails 3 - From RailsConf '10

I started exploringalternatives to Rails

Tuesday, June 15, 2010

Page 7: Hardcore Extending Rails 3 - From RailsConf '10

!

Tuesday, June 15, 2010

Page 8: Hardcore Extending Rails 3 - From RailsConf '10

HISS!!!jason seifer

YouTube search: rails vs. django

Tuesday, June 15, 2010

Page 9: Hardcore Extending Rails 3 - From RailsConf '10

December 23rd, 2008

Tuesday, June 15, 2010

Page 10: Hardcore Extending Rails 3 - From RailsConf '10

Tuesday, June 15, 2010

Page 11: Hardcore Extending Rails 3 - From RailsConf '10

+ =

RAILS 3

Tuesday, June 15, 2010

Page 12: Hardcore Extending Rails 3 - From RailsConf '10

What makes Rails 3 amazing?

(and why did it take so long?)

Tuesday, June 15, 2010

Page 13: Hardcore Extending Rails 3 - From RailsConf '10

“THE GREAT DECOUPLING”

Tuesday, June 15, 2010

Page 14: Hardcore Extending Rails 3 - From RailsConf '10

Tuesday, June 15, 2010

Page 15: Hardcore Extending Rails 3 - From RailsConf '10

Core componentsare easily customizable.

Tuesday, June 15, 2010

Page 16: Hardcore Extending Rails 3 - From RailsConf '10

Core componentsare easily replaceable.

OOTuesday, June 15, 2010

Page 17: Hardcore Extending Rails 3 - From RailsConf '10

LET’S EXPLORESOME RAILS CORE

FOR THE SAKE OF KNOWING!

Tuesday, June 15, 2010

Page 18: Hardcore Extending Rails 3 - From RailsConf '10

THE RAILS STACK

Network

Rack

ActionDispatch

ActionController

ActionView ActiveModel

Railties

Tuesday, June 15, 2010

Page 19: Hardcore Extending Rails 3 - From RailsConf '10

LET’S DOUSELESS THINGS

Tuesday, June 15, 2010

Page 20: Hardcore Extending Rails 3 - From RailsConf '10

Take this code witha grain of salt

Tuesday, June 15, 2010

Page 21: Hardcore Extending Rails 3 - From RailsConf '10

Let’s write a useless DSL for our views.

WRITING A TEMPLATE HANDLER

Tuesday, June 15, 2010

Page 22: Hardcore Extending Rails 3 - From RailsConf '10

WRITING A TEMPLATE HANDLER

Tuesday, June 15, 2010

Page 23: Hardcore Extending Rails 3 - From RailsConf '10

WRITING A TEMPLATE HANDLER

Tuesday, June 15, 2010

Page 24: Hardcore Extending Rails 3 - From RailsConf '10

WHAT ACTION VIEW EXPECTS

Tuesday, June 15, 2010

Page 25: Hardcore Extending Rails 3 - From RailsConf '10

Tuesday, June 15, 2010

Page 26: Hardcore Extending Rails 3 - From RailsConf '10

Tuesday, June 15, 2010

Page 27: Hardcore Extending Rails 3 - From RailsConf '10

Tuesday, June 15, 2010

Page 28: Hardcore Extending Rails 3 - From RailsConf '10

MAKING THE DSL

Tuesday, June 15, 2010

Page 29: Hardcore Extending Rails 3 - From RailsConf '10

my_cool_dsl.rb

Tuesday, June 15, 2010

Page 30: Hardcore Extending Rails 3 - From RailsConf '10

my_cool_handler.rb

Tuesday, June 15, 2010

Page 31: Hardcore Extending Rails 3 - From RailsConf '10

views/hello/index.cool

Tuesday, June 15, 2010

Page 32: Hardcore Extending Rails 3 - From RailsConf '10

http://localhost:3000/hello

Tuesday, June 15, 2010

Page 33: Hardcore Extending Rails 3 - From RailsConf '10

Let’s accept uselessconnections.

WRITING A “TELNET SERVER”

Tuesday, June 15, 2010

Page 34: Hardcore Extending Rails 3 - From RailsConf '10

A simple way.ACT LIKE A RACK SERVER

Tuesday, June 15, 2010

Page 35: Hardcore Extending Rails 3 - From RailsConf '10

TALK LIKE A RACK SERVER

telnet_server.rb

Tuesday, June 15, 2010

Page 36: Hardcore Extending Rails 3 - From RailsConf '10

my_cool_handler.rb

Tuesday, June 15, 2010

Page 37: Hardcore Extending Rails 3 - From RailsConf '10

my_cool_dsl.rb

z

Tuesday, June 15, 2010

Page 38: Hardcore Extending Rails 3 - From RailsConf '10

Tuesday, June 15, 2010

Page 39: Hardcore Extending Rails 3 - From RailsConf '10

CONSISTENCY!

Tuesday, June 15, 2010

Page 40: Hardcore Extending Rails 3 - From RailsConf '10

hello_controller.rb views/hello/index.cool

via telnet via browser

Tuesday, June 15, 2010

Page 41: Hardcore Extending Rails 3 - From RailsConf '10

DRY!

Tuesday, June 15, 2010

Page 42: Hardcore Extending Rails 3 - From RailsConf '10

Let’s make this uselessness

configurable.WORKING WITH RAILTIES

Tuesday, June 15, 2010

Page 43: Hardcore Extending Rails 3 - From RailsConf '10

WHAT IS A RAILTIE?The interface between the

Rails framework and its components

Tuesday, June 15, 2010

Page 44: Hardcore Extending Rails 3 - From RailsConf '10

WHAT CAN YOUR RAILTIE DO?

• Allow you to accept configuration from application.rb

• Set up initializers in your extension’s context

• Tell Rails about generators and rake tasks

• Build engines, plugins, and applications

Engines, plugins, and applicationsare all subclasses of Railtie inRails 3

Tuesday, June 15, 2010

Page 45: Hardcore Extending Rails 3 - From RailsConf '10

Organized!

Tuesday, June 15, 2010

Page 46: Hardcore Extending Rails 3 - From RailsConf '10

railtie.rb

Tuesday, June 15, 2010

Page 47: Hardcore Extending Rails 3 - From RailsConf '10

lib/super_cool/view_dsl.rb

Tuesday, June 15, 2010

Page 48: Hardcore Extending Rails 3 - From RailsConf '10

config/application.rb

Tuesday, June 15, 2010

Page 49: Hardcore Extending Rails 3 - From RailsConf '10

Results!

Tuesday, June 15, 2010

Page 50: Hardcore Extending Rails 3 - From RailsConf '10

Let’s let others be justas useless.

MAKING THIS ADISTRIBUTABLE FRAMEWORK

Tuesday, June 15, 2010

Page 51: Hardcore Extending Rails 3 - From RailsConf '10

ANATOMY OF OUR GEM

Tuesday, June 15, 2010

Page 52: Hardcore Extending Rails 3 - From RailsConf '10

ANATOMY OF OUR GEM

Tuesday, June 15, 2010

Page 53: Hardcore Extending Rails 3 - From RailsConf '10

package it with the usual tools...

Tuesday, June 15, 2010

Page 54: Hardcore Extending Rails 3 - From RailsConf '10

Tuesday, June 15, 2010

Page 55: Hardcore Extending Rails 3 - From RailsConf '10

FOOD FOR THOUGHT

IRC bot framework

Modular view systemMUD game framework

Modular enterprise app

A pluggable admin panel

Tuesday, June 15, 2010

Page 56: Hardcore Extending Rails 3 - From RailsConf '10

RESOURCES

http://github.com/rails/railsbundle open railsbundle open actionpackbundle open ... etc ...http://railsapi.com/

Tuesday, June 15, 2010

Page 57: Hardcore Extending Rails 3 - From RailsConf '10

RAILS CODE IS GOOD CODE

Tuesday, June 15, 2010

Page 58: Hardcore Extending Rails 3 - From RailsConf '10

RAILS CODE IS REUSABLE CODE

Tuesday, June 15, 2010

Page 59: Hardcore Extending Rails 3 - From RailsConf '10

And the more use cases you findfor customizing Rails 3 internals,

the better they will be writtenin the future

Tuesday, June 15, 2010

Page 60: Hardcore Extending Rails 3 - From RailsConf '10

Be inspired to look whereyou might’ve not looked before

and learn!

Tuesday, June 15, 2010

Page 61: Hardcore Extending Rails 3 - From RailsConf '10

Thanks!

twitter @digx+

[email protected]

Tuesday, June 15, 2010