Permalink
Browse files

Working on haml examples

  • Loading branch information...
1 parent 4d20d5d commit 22e2efd95ae069446009249bef2bd460df5dc372 @jc00ke committed Mar 2, 2010
@@ -0,0 +1,22 @@
+require 'rubygems'
+require 'sinatra'
+require 'haml'
+
+set :haml, { :format => :html5 }
+
+get '/' do
+ haml :index
+end
+
+__END__
+
+@@ layout
+!!!
+%html
+ %head
+ %title PDXRB RULES!
+ %body= yield
+
+@@ index
+#index
+ Um, hi there.
View
@@ -0,0 +1,15 @@
+require 'rubygems'
+require 'sinatra'
+require 'haml'
+require 'sass'
+
+set :haml, { :format => :html5 }
+
+get '/' do
+ haml :index
+end
+
+get '/styles.css' do
+ content_type 'text/css', :charset => 'utf-8'
+ sass :styles
+end
Binary file not shown.
@@ -0,0 +1,7 @@
+#index
+ Um, hi there.
+
+.explanation
+ views/ contains haml & sass files
+.explanation
+ public/ has all the static files (just like Rails)
@@ -0,0 +1,6 @@
+!!!
+%html
+ %head
+ %title PDXRB RULES!
+ %link{ :rel => :stylesheet, :href => '/styles.css' }
+ %body= yield
@@ -0,0 +1,7 @@
+#index
+ :background-color #ccc
+ :border 1px solid #666
+
+.explanation
+ :border 2px dashed #f00
+ :margin 10px 0
View
@@ -0,0 +1,95 @@
+!SLIDE smaller
+# What about Haml? #
+
+ @@@ ruby
+
+ require 'rubygems'
+ require 'sinatra'
+ require 'haml'
+
+ set :haml, { :format => :html5 }
+
+ get '/' do
+ haml :index
+ end
+
+!SLIDE
+:index can either be in (by default) views/ or in-file.
+
+!SLIDE smaller
+
+ @@@ ruby
+ ...
+
+ get '/' do
+ haml :index
+ end
+
+ __END__
+
+ @@ layout
+ !!!
+ %html
+ %head
+ %title PDXRB RULES!
+ %body= yield
+
+ @@ index
+ #index
+ Um, hi there.
+
+!SLIDE smaller
+# Normal layout/template method #
+## examples/normal_haml/app.rb ##
+ @@@ ruby
+
+ require 'rubygems'
+ require 'sinatra'
+ require 'haml'
+ require 'sass'
+
+ set :haml, { :format => :html5 }
+
+ get '/' do
+ haml :index
+ end
+
+ get '/styles.css' do
+ content_type 'text/css', :charset => 'utf-8'
+ sass :styles
+ end
+
+!SLIDE smaller
+# The Views #
+## examples/normal_haml/views/* ##
+
+!SLIDE smaller
+# examples/normal_haml/views/layout.haml #
+ !!!
+ %html
+ %head
+ %title PDXRB RULES!
+ %link{ :rel => :stylesheet, :href => '/styles.css' }
+ %body= yield
+
+!SLIDE smaller
+# examples/normal_haml/views/index.haml #
+
+ #index
+ Um, hi there.
+
+ .explanation
+ views/ contains haml & sass files
+ .explanation
+ public/ has all the static files (just like Rails)
+
+!SLIDE smaller
+# examples/normal_haml/views/styles.sass #
+
+ #index
+ :background-color #ccc
+ :border 1px solid #666
+
+ .explanation
+ :border 2px dashed #f00
+ :margin 10px 0
View
@@ -1,5 +1,6 @@
[
{ "section" : "title" },
{ "section" : "about_me" },
- { "section" : "sinatra" }
+ { "section" : "sinatra" },
+ { "section" : "haml" }
]
View
@@ -7,8 +7,6 @@
# Set up an app #
$ cd /tmp
- $ mkdir sinazzy && cd sinazzy
- $ touch app.rb
$ vim app.rb
!SLIDE smaller
@@ -21,6 +19,9 @@
'oh you did NOT just make a little website??!!!?!!'
end
+!SLIDE commandline
+
+ $ ruby app.rb
!SLIDE smaller code
@@ -51,7 +52,7 @@
end
!SLIDE smaller commandline incremental
-# ruby example/sinazzy.rb #
+# ruby examples/sinazzy.rb #
$ curl localhost:4567/
Hello World!
$ curl -X DELETE localhost:4567/
@@ -101,13 +102,14 @@
$ curl localhost:4567/i/dislike/puppies
I dislike puppies too!
-!SLIDE
+!SLIDE smaller
# You like regular expressions, right? #
@@@ ruby
get %r{/I/am/([\d]+)/years/old} do |age|
- puts age # write to the logger. sometimes helpful.
+ puts age
+ # write to the logger. sometimes helpful.
end

0 comments on commit 22e2efd

Please sign in to comment.