SlideShare a Scribd company logo
Component-Driven Web Development in Ruby



           Brian Sam-Bodden




                                           1
Components on the Web
   1   Reusable Components
       ➡More that just reusable output generators, true OO constructs
       ➡Reuse views and logic in a convenient bundle
       ➡Composable: Components made of Components

   2   Events and Event Handlers
       ➡Communication between components is in the form of events
       ➡Components interested in an event provide a handler


   3   Transparent State Management
       ➡Minimize explicit interaction with the HTTP session
       ➡Components are full-blow objects with rich behavior and state


                                                                        2
What is Trellis?
1   Magic Like Rails!
    ➡A DSL for Component-Oriented Ruby Web Development
    ➡Some new concepts and many old ones (done the Ruby way!)


                       2    A Micro-Framework
                            ➡Small like Camping and Sinatra
                            ➡Designed for Small Apps, Many Mounts, Complex Pages


3   Components
    ➡Easy to build, easy to reuse
    ➡Encapsulate complexity in components, keep application simple
    ➡MVC all the way!

                                                                                   3
What is Trellis?
✓declares pages used
✓declares a home page
✓dispatches request to pages




                                 ✓defines a template
                                 ✓handles events
                                 ✓dispatches events to components




     ✓provides reusable logic
     ✓responds to events
     ✓stateless or stateful




                                ✓means of communication
                                ✓point to point
                                ✓publish / subscribe
                                                                    4
What is Trellis?
   A lot of ideas (stolen) from...
                ✓ WebObjects
   ✓ Tapestry                  ✓ Seaside
✓ Sinatra                           ✓ Iowa

   ✓ Camping                    ✓ Rails
                   ✓ Wee
                                             5
What is Trellis?
   Built on Rack!




                    6
Hello World


              7
Hello World



      ✓1 XHTML Template

      ✓1 Ruby File



                          8
9
All Ruby - Single File
              ✓1 Ruby File
              ✓ Inline Template
               using Markaby




                                  10
✓   1 Application class with an
                                          entry point (a “home” page)



                                        ✓   1 Page class with an instance
                                             variable @current_time




✓   Template has access to page instance variables
                                                            ✓ 1 Page template
                                                              embedded in the
                                                                page class

                                                      ✓ Template using 2	
  Trellis
                                                            components:
                                                        Value and PageLink




                          ✓ PageLink creates a hyperlink to an application Page
                                                                                  11
Launching
Application#start() launches the Trellis
application w/ Mongrel on port 3000


    It’s a Ruby program, just run it!



                                        12
Hello World




              13
Application
Navigation


              14
In Trellis page navigation is
controlled by the return value of
   an event handler method




                                    15
HILO

 The Hi-Lo Web Application is the
  simple number guessing game

       Start                 Guess             GameOver
An opening/welcoming page                   Number correctly guessed


                            Pick a number




                                                                       16
HILO
    The Hi-Lo Web Application
structure consists of 1 Ruby file and
        3 XHTML templates




                                       17
HILO
 The HiLoGame Trellis Application
class defines the home page and any
        other available pages




                                     18
HILO




✓ The Start declares the pages it can navigate to (:guess	
  is the symbol for the	
  Guess	
  page)
✓ It provides an event handler called on_select() that sets the target value on the guess page
✓ Injected pages get their own instance variable (:guess	
  -­‐>	
  @guess	
  -­‐>	
  Guess)
✓If the return value of the method is a Page instance then navigate to that page


                                                                                                       19
HILO
Ok, so far so good. But, where does
the on_select event come from?




                                      20
HILO
Trellis’ default routing scheme is:

       ✓ The ActionLink generates URLs in the form




                                                     21
✓ The Guess page can only navigate to the GameOver page , see	
  pages	
  :game_over
✓ It provides an event handler called on_select_from_link(value)
✓ on_select_from_link	
  implements a simple state machine navigation. If the guessed value:
   ➡ ...matches the target value then navigate to the GameOver page
   ➡ ...does not match the target value then navigate to the Guess page

                                                                                               22
✓ The Guess page uses several components to generate the HTML:
➡ Value (<trellis:value>): outputs the value of the Page instance variable @message
➡ Loop (<trellis:loop>) that repeats from 1..10 and makes the local variable guess available inside the loop
➡ActionLink (<trellis:action_link>): “link” which creates a hyperlink passing the guess as a parameter
➡ Value (<trellis:value>) outputs the value of the guess local variable as the contents of the ActionLink

                                                                                                               23
The guess’ page two states




                             24
✓The GameOver outputs a message with how many tries it took to guess the number
✓ The GameOver page uses the value of @count in the message
✓The GameOver page uses 1 component:
  ➡ PageLink (<trellis:page_link>): which creates a hyperlink to navigate back to the Start page



                                                                                                   25
HILO




       26
Hangman


          27
Hangman
Hangman is similar to Hi-Lo but it
uses a few more features of Trellis




                                      28
Hangman
Static resources can be mounted
using the map_static method




                                  29
Hangman




          30
Hangman




          31
Templates


            32
HTML Templates
Designer friendly HTML Templates




The Remove (<trellis:remove>) component
        allows for preview elements
                                          33
HAML
Inline or external (.haml) templates:




                                        34
The Skinny on
 Components


                35
A Stateless Component
   The Loop component is a typical
stateless component, a.k.a a simple tag




   The Loop component is a Trellis
         core component                   36
A Stateless Component
    FlickrInterestingness




                            37
A Stateful Component

  Components become full
 blown OO citizens when they
 combine state and logic in a
     reusable package



                                38
A Stateful Component
         The Counter components keeps a count
                            page
view                            on_add source=counter_1
                                                          on_add
<trellis:counter tid="one" />


<trellis:action_link tid="reset">
                                                                          @counter_1
                                                          on_subtract



                                                                               reset



                                                                        @counter_2
                                                                           reset
              reset


                                                                        @counter_3
                                                                           reset



                                                                                       39
A Stateful Component



 A Stateful
 Counter
Component


                       40
A Stateful Component
Reuse: The defining characteristic
        of a Component

               {
     {


                                    41
A Stateful Component
Yes, I stole this demo from Seaside!




                                       42
Encapsulate
 Complexity


              43
Encapsulate Complexity
   A Model Grid Component




                            44
Routing


          45
Clean Routes
Trellis supports routing at the page level




                                         46
Route Sorting
Routes are sorted according to their
           “matchability”




                                       47
Filters


          48
Filters
Trellis supports “before”, “around”
          and “after” filters

       ✓ Filters are defined at the Application level




             ✓ and applied at the Page level

                                                       49
Testing


          50
Testing
Trellis can use Rack::Test w/ RSpec




                                      51
Open Questions &
  What’s Next


               52
Open Questions
  ✓ Testing: Rack provides Rack::MockRequest

    ✓ Sessions: Anything that Rack can support

✓ CRUD: Either dynamically generated Pages (like old
  Rails scaffold) or a code generator. But always using
                       components!

✓ AJAX: Planning a JQuery-based set of components

                                                          53
Open Questions
 ✓ Persistence: You pick. I’m developing data-aware
          components with a pluggable ORM

           ✓ Deployment: Hey is Rack!
✓ Is it ready?: Trellis is an infant (on version 0.1.1)




                                                          54
Resources
Rack: http://rack.rubyforge.org
Radius: http://radius.rubyforge.org
Nokogiri: http://nokogiri.org
REXML: http://www.germane-software.com/software/rexml
Builder: http://builder.rubyforge.org
Paginator: http://paginator.rubyforge.org
Trellis
  Trellis @ GitHub: http://github.com/bsbodden/trellis
  Trellis @ RubyForge: http://rubyforge.org/projects/trellis
  Trellis Website: http://www.trellisframework.org


                                                               55
Blog
http://www.trellisframework.org




                                  56
Come to the South West




Proof of Residence Not Required :-)
                                      57
www.integrallis.com




                      58

More Related Content

PDF
Alticast mhp solution
PDF
Embedded Linux On A R M
PDF
Code for Startup MVP (Ruby on Rails) Session 1
PDF
Organizing Your PHP Projects (2010 ConFoo)
PDF
PDF
Organinzing Your PHP Projects (2010 Memphis PHP)
PDF
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
PDF
Django in the Real World
Alticast mhp solution
Embedded Linux On A R M
Code for Startup MVP (Ruby on Rails) Session 1
Organizing Your PHP Projects (2010 ConFoo)
Organinzing Your PHP Projects (2010 Memphis PHP)
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Django in the Real World

Similar to Trellis Framework At RubyWebConf (20)

PDF
Crash Course HTML/Rails Slides
PDF
Ruby on rails RAD
PPTX
Women Who Code, Ground Floor
PDF
REST in Practice
PDF
Agile sites311training
PDF
Aspose pdf
PDF
Miha Lesjak Mobilizing The Web with Web Runtime
DOC
Ruby On Rails
PDF
Ruby and rails around the web fun, informative sites for new and experienced...
PPTX
Building SPA’s (Single Page App) with Backbone.js
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
KEY
How to do Scalable UI-Heavy Development at a Breakneck Pace
PDF
Plone at the University of Washington
PDF
IJTC%202009%20JRuby
PDF
IJTC%202009%20JRuby
PDF
Pronounced S-pro-ut-Co-re (Introduction to SproutCore)
PDF
Ruby on rails探索
PDF
OSGi, Scripting and REST, Building Webapps With Apache Sling
PDF
Ember.js for SFHTML5
PPTX
WebBee rapid web app development teck stack
Crash Course HTML/Rails Slides
Ruby on rails RAD
Women Who Code, Ground Floor
REST in Practice
Agile sites311training
Aspose pdf
Miha Lesjak Mobilizing The Web with Web Runtime
Ruby On Rails
Ruby and rails around the web fun, informative sites for new and experienced...
Building SPA’s (Single Page App) with Backbone.js
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
How to do Scalable UI-Heavy Development at a Breakneck Pace
Plone at the University of Washington
IJTC%202009%20JRuby
IJTC%202009%20JRuby
Pronounced S-pro-ut-Co-re (Introduction to SproutCore)
Ruby on rails探索
OSGi, Scripting and REST, Building Webapps With Apache Sling
Ember.js for SFHTML5
WebBee rapid web app development teck stack
Ad

More from Brian Sam-Bodden (10)

PDF
Baruco 2014 - Rubymotion Workshop
PDF
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
PDF
Ruby Metaprogramming - OSCON 2008
PDF
RailsConf 2013: RubyMotion
PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
PDF
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and Mustache
PDF
Integrallis groovy-cloud
PDF
PDF
Bitter Java, Sweeten with JRuby
PDF
Ruby Metaprogramming 08
Baruco 2014 - Rubymotion Workshop
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Ruby Metaprogramming - OSCON 2008
RailsConf 2013: RubyMotion
Rspec and Capybara Intro Tutorial at RailsConf 2013
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and Mustache
Integrallis groovy-cloud
Bitter Java, Sweeten with JRuby
Ruby Metaprogramming 08
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25-Week II
Agricultural_Statistics_at_a_Glance_2022_0.pdf
A Presentation on Artificial Intelligence
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks

Trellis Framework At RubyWebConf

  • 1. Component-Driven Web Development in Ruby Brian Sam-Bodden 1
  • 2. Components on the Web 1 Reusable Components ➡More that just reusable output generators, true OO constructs ➡Reuse views and logic in a convenient bundle ➡Composable: Components made of Components 2 Events and Event Handlers ➡Communication between components is in the form of events ➡Components interested in an event provide a handler 3 Transparent State Management ➡Minimize explicit interaction with the HTTP session ➡Components are full-blow objects with rich behavior and state 2
  • 3. What is Trellis? 1 Magic Like Rails! ➡A DSL for Component-Oriented Ruby Web Development ➡Some new concepts and many old ones (done the Ruby way!) 2 A Micro-Framework ➡Small like Camping and Sinatra ➡Designed for Small Apps, Many Mounts, Complex Pages 3 Components ➡Easy to build, easy to reuse ➡Encapsulate complexity in components, keep application simple ➡MVC all the way! 3
  • 4. What is Trellis? ✓declares pages used ✓declares a home page ✓dispatches request to pages ✓defines a template ✓handles events ✓dispatches events to components ✓provides reusable logic ✓responds to events ✓stateless or stateful ✓means of communication ✓point to point ✓publish / subscribe 4
  • 5. What is Trellis? A lot of ideas (stolen) from... ✓ WebObjects ✓ Tapestry ✓ Seaside ✓ Sinatra ✓ Iowa ✓ Camping ✓ Rails ✓ Wee 5
  • 6. What is Trellis? Built on Rack! 6
  • 8. Hello World ✓1 XHTML Template ✓1 Ruby File 8
  • 9. 9
  • 10. All Ruby - Single File ✓1 Ruby File ✓ Inline Template using Markaby 10
  • 11. 1 Application class with an entry point (a “home” page) ✓ 1 Page class with an instance variable @current_time ✓ Template has access to page instance variables ✓ 1 Page template embedded in the page class ✓ Template using 2  Trellis components: Value and PageLink ✓ PageLink creates a hyperlink to an application Page 11
  • 12. Launching Application#start() launches the Trellis application w/ Mongrel on port 3000 It’s a Ruby program, just run it! 12
  • 15. In Trellis page navigation is controlled by the return value of an event handler method 15
  • 16. HILO The Hi-Lo Web Application is the simple number guessing game Start Guess GameOver An opening/welcoming page Number correctly guessed Pick a number 16
  • 17. HILO The Hi-Lo Web Application structure consists of 1 Ruby file and 3 XHTML templates 17
  • 18. HILO The HiLoGame Trellis Application class defines the home page and any other available pages 18
  • 19. HILO ✓ The Start declares the pages it can navigate to (:guess  is the symbol for the  Guess  page) ✓ It provides an event handler called on_select() that sets the target value on the guess page ✓ Injected pages get their own instance variable (:guess  -­‐>  @guess  -­‐>  Guess) ✓If the return value of the method is a Page instance then navigate to that page 19
  • 20. HILO Ok, so far so good. But, where does the on_select event come from? 20
  • 21. HILO Trellis’ default routing scheme is: ✓ The ActionLink generates URLs in the form 21
  • 22. ✓ The Guess page can only navigate to the GameOver page , see  pages  :game_over ✓ It provides an event handler called on_select_from_link(value) ✓ on_select_from_link  implements a simple state machine navigation. If the guessed value: ➡ ...matches the target value then navigate to the GameOver page ➡ ...does not match the target value then navigate to the Guess page 22
  • 23. ✓ The Guess page uses several components to generate the HTML: ➡ Value (<trellis:value>): outputs the value of the Page instance variable @message ➡ Loop (<trellis:loop>) that repeats from 1..10 and makes the local variable guess available inside the loop ➡ActionLink (<trellis:action_link>): “link” which creates a hyperlink passing the guess as a parameter ➡ Value (<trellis:value>) outputs the value of the guess local variable as the contents of the ActionLink 23
  • 24. The guess’ page two states 24
  • 25. ✓The GameOver outputs a message with how many tries it took to guess the number ✓ The GameOver page uses the value of @count in the message ✓The GameOver page uses 1 component: ➡ PageLink (<trellis:page_link>): which creates a hyperlink to navigate back to the Start page 25
  • 26. HILO 26
  • 27. Hangman 27
  • 28. Hangman Hangman is similar to Hi-Lo but it uses a few more features of Trellis 28
  • 29. Hangman Static resources can be mounted using the map_static method 29
  • 30. Hangman 30
  • 31. Hangman 31
  • 32. Templates 32
  • 33. HTML Templates Designer friendly HTML Templates The Remove (<trellis:remove>) component allows for preview elements 33
  • 34. HAML Inline or external (.haml) templates: 34
  • 35. The Skinny on Components 35
  • 36. A Stateless Component The Loop component is a typical stateless component, a.k.a a simple tag The Loop component is a Trellis core component 36
  • 37. A Stateless Component FlickrInterestingness 37
  • 38. A Stateful Component Components become full blown OO citizens when they combine state and logic in a reusable package 38
  • 39. A Stateful Component The Counter components keeps a count page view on_add source=counter_1 on_add <trellis:counter tid="one" /> <trellis:action_link tid="reset"> @counter_1 on_subtract reset @counter_2 reset reset @counter_3 reset 39
  • 40. A Stateful Component A Stateful Counter Component 40
  • 41. A Stateful Component Reuse: The defining characteristic of a Component { { 41
  • 42. A Stateful Component Yes, I stole this demo from Seaside! 42
  • 44. Encapsulate Complexity A Model Grid Component 44
  • 45. Routing 45
  • 46. Clean Routes Trellis supports routing at the page level 46
  • 47. Route Sorting Routes are sorted according to their “matchability” 47
  • 48. Filters 48
  • 49. Filters Trellis supports “before”, “around” and “after” filters ✓ Filters are defined at the Application level ✓ and applied at the Page level 49
  • 50. Testing 50
  • 51. Testing Trellis can use Rack::Test w/ RSpec 51
  • 52. Open Questions & What’s Next 52
  • 53. Open Questions ✓ Testing: Rack provides Rack::MockRequest ✓ Sessions: Anything that Rack can support ✓ CRUD: Either dynamically generated Pages (like old Rails scaffold) or a code generator. But always using components! ✓ AJAX: Planning a JQuery-based set of components 53
  • 54. Open Questions ✓ Persistence: You pick. I’m developing data-aware components with a pluggable ORM ✓ Deployment: Hey is Rack! ✓ Is it ready?: Trellis is an infant (on version 0.1.1) 54
  • 55. Resources Rack: http://rack.rubyforge.org Radius: http://radius.rubyforge.org Nokogiri: http://nokogiri.org REXML: http://www.germane-software.com/software/rexml Builder: http://builder.rubyforge.org Paginator: http://paginator.rubyforge.org Trellis Trellis @ GitHub: http://github.com/bsbodden/trellis Trellis @ RubyForge: http://rubyforge.org/projects/trellis Trellis Website: http://www.trellisframework.org 55
  • 57. Come to the South West Proof of Residence Not Required :-) 57