67
Ruby on Rails Brian McCallister Ning, Inc. Philadelphia Emerging Technology Conference ‘06

Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski Smalltalk + Lisp + Perl

  • Upload
    vanbao

  • View
    232

  • Download
    4

Embed Size (px)

Citation preview

Page 1: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Ruby on RailsBrian McCallister

Ning, Inc.

Philadelphia Emerging Technology Conference ‘06

Page 2: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Robert Tinneywww.tinney.net

O’Reillywww.perl.com

Conrad Barskiwww.lisperati.com

Smalltalk Lisp Perl+ +

Page 3: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

$~='`';$_=$:=$~|'%';$;=$^='/'|$~;$;++;$\=$~|"'";$;++;$:.=++$;;$/=++$;;+$\++;$_.='#'|$~;$,=++$/;$_.="$\$^$\"";++$,;$_.='@'|'*'&~'!';$_.="$,$;$/$\"";$_.+='!.'|$~.$~;$_.="$^$/$\$:$\"";$_.='@'|':'&~'*';$_.=$:;$_.=$^&'|';$_.=$".$\;$_.=+"$~$~$~"|'!#+';++$.;$.++;`$_$:,>&$.`;

Weird GUI

Parens

-

-

-

Without the...

Page 4: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

[“hello”, “world”].each {|word| print word }

printer_generator = lambda {|x| lambda { print x }}hello = printer_generator.call “hello world”hello.call

“world hello” =~ /(\w+)\s(\w+)/print “#{$2} #{$1}”

we love each!

functions to generate functions to...

Yeah, yeah, told you

Page 5: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

+ +

John Longwww.wiseheartdesign.com

Sunjava.sun.com

PHPwww.php.net

Page 6: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Model-2 Web Framework

Object/Relational Mapping Library

SOAP Stack

SMTP/Email Library

Database Migration Tool

Deployment and Management Tool

Code Generator

Ecosystem

Even more!

Page 7: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Less Code

Convention over Configuration

Opinionated

Page 8: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Gifts(Welcome to your running example)

Page 9: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

First we need a project

Page 10: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 11: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Project Hierarchy

Default Database Configs

with samples for major databases

Rakefile (Makefile)

Functional Test Harness

Unit Test Harness

Apache HTTPD Configs (.htaccess)

Additional Code Generation Scripts...

This Just Generated:

Page 12: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Active RecordYou get the data from the database

and shake it all about...

Page 13: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Not Required!

One Row == One Instance

Dynamic Properties by Default

Embraces SQL

Including joins

Oracle (OCI), DB2, Firebird, SQLite, SQLServer, PostgreSQL, MySQL

Page 14: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

id: integername: varchar(100)description: textfriend_id: integer FK references friends(id)

Gifts

id: integername: varchar(100)

Friends* 1

You want stuff.

Your friends check off what they will give you.

Your friends can see what they are giving you.

Page 15: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 16: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class Gift < ActiveRecord::Base end

class Friend < ActiveRecord::Baseend

Page 17: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class Gift < ActiveRecord::Base belongs_to :friend

validates_presence_of :nameend

class Friend < ActiveRecord::Base has_many :gifts

validates_presence_of :name validates_uniqueness_of :nameend

Page 18: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class Gift < ActiveRecord::Base belongs_to :friend

validates_presence_of :nameend

class Friend < ActiveRecord::Base has_many :gifts

validates_presence_of :name validates_uniqueness_of :nameend

Page 19: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

This part

id: integername: varchar(100)description: textfriend_id: integer FK references friends(id)

Gifts

id: integername: varchar(100)

Friends* 1

Page 20: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class Gift < ActiveRecord::Base belongs_to :friend

validates_presence_of :nameend

class Friend < ActiveRecord::Base has_many :gifts

validates_presence_of :name validates_uniqueness_of :nameend

Page 21: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class Gift < ActiveRecord::Base belongs_to :friend

validates_presence_of :nameend

class Friend < ActiveRecord::Base has_many :gifts

validates_presence_of :name validates_uniqueness_of :nameend

Page 22: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 23: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Gift.find :all, :order =>'name DESC', :limit => count, :include => [:friend]

Gift.find :first, :conditions => ['description like ?', '%me%'], :order => 'name DESC', :include => [:friend]

Gift.find_by_sql ["select g.* from gifts g where g.friend_id < ?", 15]

Page 24: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Gift.find :all, :order =>'name DESC', :limit => count, :include => [:friend]

Gift.find :first, :conditions => ['description like ?', '%me%'], :order => 'name DESC', :include => [:friend]

Gift.find_by_sql ["select g.* from gifts g where g.friend_id < ?", 15]

Page 25: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Gift.find :all, :order =>'name DESC', :limit => count, :include => [:friend]

Gift.find :first, :conditions => ['description like ?', '%me%'], :order => 'name DESC', :include => [:friend]

Gift.find_by_sql ["select g.* from gifts g where g.friend_id < ?", 15]

Page 26: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Gift.find :first, :conditions => ['description like ?', '%me%'], :order => 'name DESC', :include => [:friend]

class Friend < ActiveRecord::Base has_many :gifts

validates_presence_of :name validates_uniqueness_of :nameend

Page 27: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Action PackThat Web Stuff

Page 28: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 29: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 30: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class PeopleController < ApplicationController def identify endend

ActionController

Page 31: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class PeopleController < ApplicationController model :friend def identify if params[:friend] # if we have friend data in the request

@friend = Friend.create_or_find params[:friend][:name]

if @friend.errors.empty? # if there were no validation errors cookies[:name] = @friend.name redirect_to :controller => 'wishes', :action => 'index' end end

@friend ||= Friend.new endend

Success

Check Params

Page 32: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class PeopleController < ApplicationController model :friend def identify if params[:friend] # if we have friend data in the request

@friend = Friend.create_or_find params[:friend][:name]

if @friend.errors.empty? # if there were no validation errors cookies[:name] = @friend.name redirect_to :controller => 'wishes', :action => 'index' end end

@friend ||= Friend.new endend

Let Model Think

Page 33: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class Friend < ActiveRecord::Base has_many :gifts

validates_presence_of :name validates_uniqueness_of :name def Friend.create_or_find name friend = find_by_name name logger.debug "Friend.create_or_find(#{name}) \ found [#{name}]" unless friend logger.debug "Friend.create_or_find(#{name}) \ creating new" friend = Friend.create :name => name end return friend end end

Page 34: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class Friend < ActiveRecord::Base has_many :gifts

validates_presence_of :name validates_uniqueness_of :name def Friend.create_or_find name friend = find_by_name name logger.debug "Friend.create_or_find(#{name}) \ found [#{name}]" unless friend logger.debug "Friend.create_or_find(#{name}) \ creating new" friend = Friend.create :name => name end return friend end end

Page 35: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

<%= error_messages_for 'friend' %><%= start_form_tag :action => 'identify' %> <table class="form"> <tr> <td class="label"> <label for="friend[name]">Your Name</label> </td> <td class="value"> <%= text_field 'friend', 'name' %> </td> </tr> <tr> <td class="label">&nbsp;</td> <td class="value"> <input type="submit" value="Enter!"/> </td> </tr> </table><%= end_form_tag %>

Page 36: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

<%= error_messages_for 'friend' %><%= start_form_tag :action => 'identify' %> <table class="form"> <tr> <td class="label"> <label for="friend[name]">Your Name</label> </td> <td class="value"> <%= text_field 'friend', 'name' %> </td> </tr> <tr> <td class="label">&nbsp;</td> <td class="value"> <input type="submit" value="Enter!"/> </td> </tr> </table><%= end_form_tag %>

Page 37: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

ActionController::Routing::Routes.draw do |map| # Ask people to identify themselves at the /hello map.connect 'hello', :controller => 'people', :action => 'identify' # Pretty url for the most common thing map.connect 'wish', :controller => 'wishes', :action => 'index' # The Default map.connect ':controller/:action/:id'end

Page 38: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

ActionController::Routing::Routes.draw do |map| # Ask people to identify themselves at the /hello map.connect 'hello', :controller => 'people', :action => 'identify' # Pretty url for the most common thing map.connect 'wish', :controller => 'wishes', :action => 'index' # The Default map.connect ':controller/:action/:id'end

http://localhost/hello

http://localhost/people/identify

Page 39: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 40: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Not Bad for Slowest Server Option

Page 41: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Some Fancy Stuffor something like it

Page 42: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

<%= javascript_include_tag 'prototype' %><%= javascript_include_tag 'prototype', 'effects' %><h1>Stuff I Want!</h1><script lang="text/javascript"> function highlight_last() { new Effect.Highlight($('wish_list').lastChild); }</script><%= form_remote_tag :url => { :action => 'gimme' }, :update => 'wish_list', :position => :bottom, :complete => 'highlight_last();' %> <label for="gift_idea">Gift Idea</label> <%= text_field_tag :gift_idea %> <%= submit_tag 'Gimme!' %><%= end_form_tag %> <ul id="wish_list"> <% for gift in current_gift_list %> <%= render_partial 'gift', gift %> <% end %></ul>

Page 43: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

<%= javascript_include_tag 'prototype' %><%= javascript_include_tag 'prototype', 'effects' %><h1>Stuff I Want!</h1><script lang="text/javascript"> function highlight_last() { new Effect.Highlight($('wish_list').lastChild); }</script><%= form_remote_tag :url => { :action => 'gimme' }, :update => 'wish_list', :position => :bottom, :complete => 'highlight_last();' %> <label for="gift_idea">Gift Idea</label> <%= text_field_tag :gift_idea %> <%= submit_tag 'Gimme!' %><%= end_form_tag %> <ul id="wish_list"> <% for gift in current_gift_list %> <%= render_partial 'gift', gift %> <% end %></ul>

Page 44: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

<li><%= h @gift.name %></li>

Page 45: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class WishesController < ApplicationController model :gift def index end def gimme gift_idea = params[:gift_idea] if gift_idea f = Friend.find_by_name cookies[:name] gift = Gift.create :friend => f, :name => gift_idea render :partial => 'gift', :object => gift else render :text => '' end endend

Page 46: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class WishesController < ApplicationController model :gift def index end def gimme gift_idea = params[:gift_idea] if gift_idea f = Friend.find_by_name cookies[:name] gift = Gift.create :friend => f, :name => gift_idea render :partial => 'gift', :object => gift else render :text => '' end endend

Page 47: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

class WishesController < ApplicationController model :gift def index end def gimme gift_idea = params[:gift_idea] if gift_idea f = Friend.find_by_name cookies[:name] gift = Gift.create :friend => f, :name => gift_idea render :partial => 'gift', :object => gift else render :text => '' end endend

Page 48: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 49: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

page.insert_html :bottom, 'list', content_tag("li", "Fox")

page.visual_effect :highlight, 'list', :duration => 3

page.replace_html 'header', 'My New Header!!!1'

from Cody Fauser’s RJS tutorialhttp://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates

Remote JavaScript Templates (RJS)

Page 50: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

The first difference is that “enterprise software” costs more...

The second difference is that “enterprise software” doesn’t necessarily work...

--Kragen Sitaker

http://www.relevancellc.com/blogs/?p=36#comment-545

Page 51: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Rails generators create more code for testing than anything else.

Page 52: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

$ find test/ -name *.rb -exec cat {} \; | wc -l 84$ find app/ -name *.rb -exec cat {} \; | wc -l 52$

Page 53: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

$ find test/ -name *.rb -exec cat {} \; | wc -l 84$ find app/ -name *.rb -exec cat {} \; | wc -l 52$

Page 54: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

ActiveRecord::Schema.define() do

create_table "friends", :force => true do |t| t.column "name", :string, :limit => 100, :null => false end

add_index "friends", ["name"], :name =>"friends_name_key", :unique => true

create_table "gifts", :force => true do |t| t.column "name", :string, :limit => 100, :null => false t.column "description", :text t.column "friend_id", :integer end

end

Page 55: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 56: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl
Page 57: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Switchtower

Page 58: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Apache HTTPD

Rails

PostgreSQL

Rails Rails

Apache HTTPD

PostgreSQL

Cache

Cache

Page 59: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Apache HTTPD 1.3 mod_fcgi

Apache HTTPD 2.0 (maybe 2.2)mod_fcgid mod_scgimod_proxy to Lighttpd

Lighttpd mod_fcgi

Page 60: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

• Multi-processing model (like prefork)

• DB Connection per FCGI Process

• Remote FCGI instances

• Static and Dynamic Caching

• Easy to interface with C

• (Almost as easy to interface with OCaml)

Page 61: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Philly on Rails http://phillyonrails.org/

Ruby http://www.ruby-lang.org/

Try Ruby Online! http://tryruby.hobix.com/

Why’s Poignant Guide to Ruby http://poignantguide.net/

Ruby on Rails http://www.rubyonrails.org/

Ruby Documentation http://www.ruby-doc.org/

Page 62: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

That’s (almost) all folks!Brian [email protected]://www.ning.com/

Slides Available: http://morphy.skife.org/petc-ror-06.pdf

Page 63: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

Interfacing to CNot rails, but is important to know about!

Page 64: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

require 'dl/import'

module XSLT extend DL::Importer dlload "libxslt.so" extern "void *xsltParseStylesheetFile(char*)" extern "void *xsltApplyStylesheet(void*, void*, void[])" extern "void xsltSaveResultToFd(int, void*, void*)" extern "void xsltSaveResultToFile(void*, void*, void*)" extern "void xsltFreeStylesheet(void*)"end

module XML extend DL::Importer dlload "libxml2.so" extern "void *xmlParseFile(char*)" extern "void xmlFreeDoc(void*)"end

cur = XSLT.xsltParseStylesheetFile("sample.xsl")doc = XML.xmlParseFile("sample.xml")res = XSLT.xsltApplyStylesheet(cur, doc, nil)

cur.free = XSLT["xsltFreeStylesheet"]doc.free = XML["xmlFreeDoc"]res.free = XML["xmlFreeDoc"]

XSLT.xsltSaveResultToFile(DL::CPtr[$stdout], res, cur)

Page 65: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

require 'dl/import'

module XSLT extend DL::Importer dlload "libxslt.so" extern "void *xsltParseStylesheetFile(char*)" extern "void *xsltApplyStylesheet(void*, void*, void[])" extern "void xsltSaveResultToFd(int, void*, void*)" extern "void xsltSaveResultToFile(void*, void*, void*)" extern "void xsltFreeStylesheet(void*)"end

module XML extend DL::Importer dlload "libxml2.so" extern "void *xmlParseFile(char*)" extern "void xmlFreeDoc(void*)"end

cur = XSLT.xsltParseStylesheetFile("sample.xsl")doc = XML.xmlParseFile("sample.xml")res = XSLT.xsltApplyStylesheet(cur, doc, nil)

cur.free = XSLT["xsltFreeStylesheet"]doc.free = XML["xmlFreeDoc"]res.free = XML["xmlFreeDoc"]

XSLT.xsltSaveResultToFile(DL::CPtr[$stdout], res, cur)

Page 66: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

require 'dl/import'

module XSLT extend DL::Importer dlload "libxslt.so" extern "void *xsltParseStylesheetFile(char*)" extern "void *xsltApplyStylesheet(void*, void*, void[])" extern "void xsltSaveResultToFd(int, void*, void*)" extern "void xsltSaveResultToFile(void*, void*, void*)" extern "void xsltFreeStylesheet(void*)"end

module XML extend DL::Importer dlload "libxml2.so" extern "void *xmlParseFile(char*)" extern "void xmlFreeDoc(void*)"end

cur = XSLT.xsltParseStylesheetFile("sample.xsl")doc = XML.xmlParseFile("sample.xml")res = XSLT.xsltApplyStylesheet(cur, doc, nil)

cur.free = XSLT["xsltFreeStylesheet"]doc.free = XML["xmlFreeDoc"]res.free = XML["xmlFreeDoc"]

XSLT.xsltSaveResultToFile(DL::CPtr[$stdout], res, cur)

Page 67: Ruby on Rails - Chariot Solutionschariotsolutions.com/wp-content/uploads/presentations/archive/321/... · Conrad Barski  Smalltalk + Lisp + Perl

That’s (really) all folks!Brian [email protected]://www.ning.com/

Slides Available: http://morphy.skife.org/petc-ror-06.pdf