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
Introduction to Cuba
Search
Francesco Rodríguez
September 04, 2014
Programming
84
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Cuba
Introduction to Cuba "The Ruby Microframework"
Francesco Rodríguez
September 04, 2014
Transcript
34 slides
None
Francesco
[email protected]
Cuba (‛ƅ㱼ƅ)‛ Ruby microframework for web development.
ʕ•ᴥ•ʔ ! • Small. • Focused. • Simple. • Stable.
• Rack. • Fast.
require "cuba"! ! Cuba.define do! on "home" do! res.write("Hello Cuba")!
end! end
Rules
Cuba.define do! on "home" do # PATH == "/home"! !
res.write("Hello Cuba")! end! end
Cuba.define do! on "home" do # PATH == "/home"! !
res.write("Hello Cuba")! end! ! on "about" do # PATH == "/about"! ! res.write("About us”)! end! end
Captures
Cuba.define do! on "hello/:name" do |name|! ! res.write("Hello #{ name
}")! end! end! ! # /hello/frodsan => Hello frodsan
Matchers
Cuba.define do! on /hello\/(^[a-zA-Z]+$)/ do |name|! ! res.write("Hello #{ name
}")! end! end! ! # /hello/frodsan => Hello frodsan! # /hello/123 =>
Cuba.define do! on :name do |name|! ! res.write("Hello #{ name
}")! end! end! ! # /frodsan => Hello frodsan! # /123 => Hello 123
Cuba.define do! # Any expression that! # evaluates to `true`.!
on (*) do! ! res.write("Hello Cuba")! end! end
Cuba.define do! # Any expression that! # evaluates to `true`.!
on true do! ! res.write("Hello Cuba")! end! end
Cuba.define do! on false do! ! res.write("⊙﹏⊙")! end! ! on
true do! ! res.write("the winner")! end! end
Cuba.define do! on authenticated? do! # . . .! end!
! on true do! ! res.status = 401! ! res.write("Not authorized")! end! end
Nested Blocks
Cuba.define do! on "posts" do! # /posts/new! on "new" do!
# . . .! end! ! ! ! # /posts/mypost! on :slug do |slug|! ! # . . .! end! end! end
404 (Else)
Cuba.define do! on "posts" do! on "new" do! ! #
. . .! ! # on true do! on default do! res.status = 404! res.write("Not Found")! end! end! end
Helpers
Cuba.define do! on "posts" do! on get do! # METHOD
== GET! end! ! on post do! on param("post") do |post|! end! end! end! end
Composition
class Users < Cuba define do! on "posts" do! on
"new" do! ! # . . .! end! ! on :slug do |slug|! ! # . . .! end! end! end! end
Cuba.define do! on authenticated? do! run(Users)! end! ! on default
do! ! res.status = 401! ! res.write("Not authorized")! end! end
Stack
ʕ•ᴥ•ʔ ! • hache • mote • mote-render • malone
• ohm • ost • rack-protection • requests • scrivener • shield
! on "signup" do! on post, param("user") do |params|! signup
= Signup.new(params)! ! on signup.valid? do! user = User.create(params)! authenticate(user)! ! res.redirect("/dashboard")! end! ! on default do! end! end! end!
! on "posts" do! on post, param("post") do |params|! end!
! on :id do |id|! post = Post[id]! ! on default do! render("post", post: post)! end! end! ! on default do! render("posts")! end! end!
theguidetocuba.io A Getting Started guide (WIP)
github.com/punchgirls/job_board/ An Open Source application.
cuba.is Cuba’s website.
thx <3
More Decks by Francesco Rodríguez
See All by Francesco Rodríguez
A Minimalistic Ruby Stack
frodsan
1
81
Web Development with Cuba - Ruby Fun Day 2014
frodsan
0
150
Web Security 101 - Ruby Fun Day 2014
frodsan
0
130
Aprende a Programar
frodsan
0
190
Metaprogramming: From Zero to Hero. (URU meetup)
frodsan
1
150
Introducción a Cuba
frodsan
0
87
Other Decks in Programming
See All in Programming
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
930
SODA - FACT BOOK(JP)
sodainc
1
40k
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
200
将来の標準フォーマッター?ktfmtを深堀る
t45k
0
220
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
310
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.4k
Crash Auto Pipelines
veronikapj
1
430
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
310
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
590
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
180
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
450
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
460
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.9k
Everyday Curiosity
cassininazir
0
400
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.4k
Chasing Engaging Ingredients in Design
codingconduct
0
400
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
300
The Invisible Side of Design
smashingmag
301
52k
Mind Mapping
helmedeiros
1
440
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.7k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7.1k