Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rack is Spectacular
Search
Bryce "BonzoESC" Kerley
February 21, 2010
Programming
74
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rack is Spectacular
Barcamp Miami 2010
Bryce "BonzoESC" Kerley
February 21, 2010
More Decks by Bryce "BonzoESC" Kerley
See All by Bryce "BonzoESC" Kerley
Ruby in 2020
bryce
1
130
Rails and the Internet of Things
bryce
1
96
It's Not Ruby, But…
bryce
0
95
Ruby 2.5: What's New and What's Cool
bryce
0
100
docker for rubyists
bryce
0
130
Would You Like To Make A Game?
bryce
0
69
WebSockets and ActionCable
bryce
0
98
How I Learned to Stop Worrying and Like RSpec
bryce
0
98
How Do Computers Even Work?
bryce
1
230
Other Decks in Programming
See All in Programming
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
AmebaブログはKMPから卒業します
kmars0605
0
200
Event is what happens
moro
2
810
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
We Have a Design System, Now What?
morganepeng
55
8.4k
Design in an AI World
tapps
1
350
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
270
Code Reviewing Like a Champion
maltzj
529
40k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
sira's awesome portfolio website redesign presentation
elsirapls
0
460
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Transcript
Rack is Spectacular Learning Rack by making a cheap Rails
knockoff
WARNING CODE HEAVY HTTP Ruby Rails
WARNING CODE HEAVY So get the code http://bit.ly/spectac c9c340bb
WARNING CODE HEAVY NOT READY FOR PRODUCTION c9c340bb
Rack • Standard Ruby-HTTP interface • Write (framework) once •
Run anywhere (that is Rack-compatible) • Rails, Sinatra, Camping • Mongrel, Passenger, Unicorn
A Rack Application use Rack::ContentLength run(proc do [ 200, {
'Content-type' => 'text/plain'}, 'hello world'] end) Response Code Response Headers Response Body c9c340bb config.ru
None
What is Rails • ActionPack • Router - maps URLs
to code • Controller - environment for code • View - generating response body • ActiveRecord - database access
The Essential Rails • ActionPack • Router - maps URLs
to code • Controller - environment for code • View - generating response body • ActiveRecord - database access
module Spectacular class App def call(environment) [ 200, { 'Content-type'
=> 'text/plain'}, 'hello world'] end end end require 'lib/spectacular.rb' use Rack::ContentLength run(Spectacular::App.new) config.ru lib/spectacular/app.rb 0fad6a02
None
module Spectacular class App … def call(environment) method = environment['REQUEST_METHOD']
path = environment['PATH_INFO'] @dispatcher.dispatch method, path, environment rescue => exception error_backtrace exception, environment end private def error_backtrace(exception, environment) exception_info = “some html” [500, { 'Content-type' => 'text/html'}, exception_info] end … end end lib/spectacular/app.rb 2a0d1445 breaks; no dispatcher yet
None
Dispatch & Routing are the most complicated parts of Rails
[citation needed]
But That’s Okay • We’re not building Rails • It’s
okay if we Fail to Scale • Just use an array to map paths to controllers and actions
def get_route(path) @routes.detect{ |r| path === r[0] } end …
class RoutePen def route(path, controller, method) @routes << [path, controller, method] end end 9cfb9609 lib/spectacular/dispatcher.rb
None
def response_for(method) @method = method send @method [response_code, headers, body]
end … def template_file File.join(APP_DIR, 'views', controller_name, "#{@method}.html.haml") end … def body return @body if defined? @body template = File.read template_file engine = Haml::Engine.new template @body = engine.render end ce2f00a3 lib/spectacular/controller.rb
class HelloController < Spectacular::Controller def index end end hello world
app/controllers/hello_controller.rb app/views/hello/index.html.haml ce2f00a3
None
Wildcards def get_route(path) @routes.detect{ |r| r[0] === path } end
lib/spectacular/dispatcher.rb 48b08205
=== 0 :> /abc/ === 'abc' # => true 0
:> String === 'abc' # => true 0 :> /too+t/ === 'toooooooooot' # => true
route /too+t/, TootController, :toot app/routes.rb A Wildcard Route 48b08205
Using the Path class TootController < Spectacular::Controller def toot @toot
= @path.gsub('/','') end end app/controllers/toot_controller.rb %h1=@toot app/views/toot/toot.html.haml 48b08205
None
None
404 • When we can’t figure out how to process
a request, that should be a “404” • We can simply make a wildcard route
route //, ErrorController, :not_found app/routes.rb class ErrorController < Spectacular::Controller def
not_found @response_code = 404 end end app/controllers/error_controller.rb 2a2653b2
None
What’s Left • Only renders HAML • No layouts •
Can’t easily render a different view • No query parameters • No POST
thanks • Bryce Kerley; mercenary developer •
[email protected]
• http://twitter.com/bonzoesc
• Code on Github: http://bit.ly/spectac