web development with ruby - from simple to complex
DESCRIPTION
Beyond the massive hype of Ruby on Rails, there's an amazing world of frameworks, DSLs, and libraries that make the Ruby language a compelling choice when working on the web. In this talk, you'll get a chance to see how to use Ruby to quickly build a static web site, create complex stylesheets with ease, build a simple web service, crete a simple Websocket server, and test your existing applications. Finally, you'll see a few of the ways Rails really can make developing complex applications easier, from advanced database querying to rendering views in multiple formats.TRANSCRIPT
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Web Development With RubyFrom simple to complex
1Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Ruby developers have greatly influenced web
development.
2Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
ASP.Net MVC and NuPack
3Sunday, October 10, 2010
Pretty hot stuff. Inspired by Rails and RubyGems, two things we Rubyists have used to build quality stuff for years.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
With Ruby we can•Make HTML and CSS better•Quickly prototype or build simple web sites•Automate complicated builds or deployments•Build simple micro-apps•Implement Web Sockets servers•Improve communication between customers and developers•while also testing our web sites•Build complex apps that interface with legacy systems
4Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
All made possible by the highly dynamic
features of the
5Sunday, October 10, 2010
So, what is Ruby?• Highly dynamic
• Very high level
• 100% object oriented
• 100% open-source
• Really easy to learn
6Sunday, October 10, 2010
Highly dynamic, high level, 100% object oriented, 100% open source, and really easy to learn.
twitter: bphoganemail: brianhogan at napcs.com
History
Smalltalk(1983)
C++ (1989)
Ruby(1993)
Java(1995)
VB 6(1996)
C#(2000)
7Sunday, October 10, 2010
Ruby was created by Yukihiro Matsumoto (Matz) in 1993. It’s built on C, and has many implementations, including JRuby, which runs on the JVM, and IronRuby, which runs on the .Net platform.
twitter: bphoganemail: brianhogan at napcs.com
8Sunday, October 10, 2010
“How you feel is more important than what you do. “The entire language is designed for programmer productivity and fun.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Basic Ruby
9Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
5 + 510 * 10"Hello" + "World"25 / 5
10Sunday, October 10, 2010
We have numbers, strings, multiplication, addition, subtraction, and division, just like everyone else.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
age = 42first_name = "Homer"start_date = Date.new 1980, 06, 05annual_salary = 100000.00
11Sunday, October 10, 2010
It also helps that the syntax is simple. There are no unnecessary semicolons or curly braces. The interpreter knows when lines end.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Ruby follows the Principle of Least
Surprise.
12Sunday, October 10, 2010
Principle of Least Surprise - This means The language should behave in a way that is not confusing to experienced developers. It doesn’t mean that it works like your current favorite language! But as you get used to Ruby, you’ll find that you ramp up quickly.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
"Brian".length["red", "green", "blue"].length[:first_name => "Brian", :last_name => "Hogan"].lengthUser.find_all_by_last_name("Hogan").length
13Sunday, October 10, 2010
Ruby achieves this through a consistant API. You won’t find yourself guessing too much what methods are available to you.
Arrays
colors = ["Red", "Green", "Blue"]
14Sunday, October 10, 2010
The square brackets denote an array.
Hashes (Dictionaries)
attributes = {:age => 25, :first_name => "Homer", :last_name => "Simpson"}
15Sunday, October 10, 2010
=>
16Sunday, October 10, 2010
This is the hash symbol, or the hash rocket. Whenever you see this, you’re dealing with a hash.
twitter: bphoganemail: brianhogan at napcs.com
:foo
17Sunday, October 10, 2010
When you see these, you’re looking at Symbols. They represent names and some strings. They conserve memory, as repeating a symbol in your code uses the same memory reference, whereas repeating a string creates a new object on each use.
Simple control logic
if on_probation(start_date) puts "Yes"else puts "no"end
18Sunday, October 10, 2010
Methods (functions) are simple too.
# if start date + 6 months is > todaydef on_probation?(start_date) (start_date >> 6) > Date.todayend
19Sunday, October 10, 2010
The two arrows (>>) is actually a method on the Date object that adds months. So here, we’re adding six months to the start date and comparing it to today
Notice here that the input parameter is assumed to be a date. There’s no type checking here.
Let Ruby write code for you!
class Person @started_on = Date.today @name = "" def started_on=(date) @started_on = date end def started_on @started_on end
def name=(name) @name = name end def name @name endend
class Person attr_accessor :name attr_accessor :started_onend
20Sunday, October 10, 2010
Making getters and setters is so common that Ruby can do it for you.
def test_user_hired_today_should_be_on_probation person = Person.new person.hired_on = Date.today assert person.on_probation?end
test_user_hired_last_year_should_not_be_on_probation person = Person.new person.hired_on = 1.year.ago assert !person.on_probation?end
21Sunday, October 10, 2010
Here we have two tests, one using a person hired today, and another using a person last year.
Implement the method
class Person attr_accessor :name, :start_date def on_probation? (start_date >> 6) > Date.today endend
22Sunday, October 10, 2010
Watch as the tests pass.
twitter: bphoganemail: brianhogan at napcs.com
haml and sass
23Sunday, October 10, 2010
HAML
!!!#wrapper.container_12 #header.grid_12 %h1 The awesome site %ul#navbar.grid_12 %li %a{:href => "index.html"} Home %li %a{:href => "products"} Products %li %a{:href => "services"} Services #middle.grid_12 %h2 Welcome #footer.grid_12 %p Copyright 2010 AwesomeCo
24Sunday, October 10, 2010
HTML <div class='container_12' id='wrapper'> <div class='grid_12' id='header'> <h1>The awesome site</h1> </div> <ul class='grid_12' id='navbar'> <li> <a href='index.html'>Home</a> </li> <li> <a href='products'>Products</a> </li> <li> <a href='services'>Services</a> </li> </ul> <div class='grid_12' id='middle'> <h2>Welcome</h2> </div> <div class='grid_12' id='footer'> <p>Copyright 2010 AwesomeCo</p> </div> </div>
25Sunday, October 10, 2010
SASS
$the_border: 1px$base_color: #111
#header color: $base_color * 3 border-left: $the_border border-right: $the_border * 2 color: red a font-weight: bold text-decoration: none
26Sunday, October 10, 2010
CSS
#header { color: #333333; border-left: 1px; border-right: 2px; color: red; }
#header a { font-weight: bold; text-decoration: none; }
27Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
$the_border: 1px$base_color: #111
#header color: $base_color * 3 border-left: $the_border border-right: $the_border * 2 color: red a font-weight: bold text-decoration: none
#header { color: #333333; border-left: 1px; border-right: 2px; color: red; } #header a { font-weight: bold; text-decoration: none; }
28Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Demos
29Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
StaticMatichttp://staticmatic.rubyforge.org/
30Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
src layouts application.haml pages index.html stylesheets application.sass
site index.html images javascripts stylesheets application.css
31Sunday, October 10, 2010
StaticMatic is a tiny framework for building static websites quickly using HAML and SASS.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Rake
32Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Automation LanguageDeploy with a single command!
33Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Rakefiles have tasks
desc "Copies the site to our remote server"task :deploy do puts "*** Deploying the site via SSH to #{ssh_user}" system("rsync -avz --delete #{upload_files}/ #{ssh_user}:#{remote_root}") FileUtils.rm_rf upload_files rescue nilend
rake deploy
34Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
StaticMatic and Rake demo
35Sunday, October 10, 2010
Let’s put a site online
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Sinatrahttp://www.sinatrarb.com/intro
36Sunday, October 10, 2010
Sinatra is a great way to build simple web apps with Ruby.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Great for micro apps
37Sunday, October 10, 2010
Hello Sinatra!
require 'rubygems'require 'sinatra'
get "/" do "Hello Sinatra!"end
38Sunday, October 10, 2010
Sinatra is a simple web framework that basically maps incoming requests to backend code that produces responses.
39Sunday, October 10, 2010
That little bit of code gets us a working web application that handles requests.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Sinatra demos
40Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Composable apps?Sure!
41Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
config.ru
require 'rubygems'require 'sinatra' # include our Application coderequire File.join(File.dirname(__FILE__), 'main')require File.join(File.dirname(__FILE__), 'blog') # disable sinatra's auto-application startingdisable :run map "/" do run Mainend
map "/blog" do run Blogend
Sinatra Apps
Mountingto URLs
42Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Testing Web Apps
43Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
cucumberWeb application testing
for people first and computers second
44Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Plain Text Scenarios!Feature: an advanced google search with CucumberAs an interested developer who wants to automate tasks with CucumberI want to search GoogleSo that I can find more information on how it works.
Scenario: Advanced searchGiven I go to "http://www.google.com"And I click "Advanced search"And I fill in "as_q" with "cucumber"And I fill in the "any of these unwanted words" field with "pickles"And I select "50 results" from the "Number of results" dropdownAnd I click the Date, usage rights, numeric range, and more sectionAnd I turn on Safe SearchWhen I press "Advanced Search"Then I should see "Cucumber - Making BDD fun"When I click "Cucumber - Making BDD fun" And I click "Wiki" And I click "Gherkin" And I click "Feature Introduction"Then I should see "Feature Introduction"
45Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Express requirementsplainly...
46Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
then run real browsers!
47Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Demo?
48Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
RadiantContent Management System
49Sunday, October 10, 2010
Based on Rails, completely modular, easy to install
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Web Sockets
50Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
NodeJS? NoWai!
51Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
EventMachine
52Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Demo?
53Sunday, October 10, 2010
Fi
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Finally, Rails
54Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Opinionated, but flexible.
55Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Demo
56Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
“Use The Right Tool”
57Sunday, October 10, 2010
We hear this a lot.
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Most people who advocate that mean
“The right tool is the one I use”
58Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
I am a “Web” developer first and a Ruby
developer second.
59Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Ruby is the fastest, best, most productive, and most stable, and lucrative way to build
web stuff...
60Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
...for me, for now.
61Sunday, October 10, 2010
But I still use WordPress for my blogs, I still use PHP for simple web stuff, and I still use Visual Basic to maintain a commercial app I sold years ago. I use ASP
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
Code examples
http://github.com/napcs/cucumber_watir
http://dl.dropbox.com/u/50783/tccc9_ruby_webdev.zip
62Sunday, October 10, 2010
twitter: @bphoganemail: brianhogan at napcs.comLike this talk? Rate it at http://spkr8.com/t/4773
You have new tools.Go use them.
63Sunday, October 10, 2010