Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding rails adapter

  • Loading branch information...
commit 9c3876ac462261cbf45f6a4e96d1012960d1bc4c 1 parent e6fc063
@tenderlove authored
Showing with 41 additions and 3 deletions.
  1. +10 −1 Manifest.txt
  2. +1 −2  bin/phrack
  3. +30 −0 lib/phuby/rails.rb
View
11 Manifest.txt
@@ -3,7 +3,9 @@ CHANGELOG.rdoc
Manifest.txt
README.rdoc
Rakefile
+bin/phrack
bin/phuby
+bin/phuby_server
ext/phuby/Makefile
ext/phuby/extconf.rb
ext/phuby/mkmf.log
@@ -11,18 +13,25 @@ ext/phuby/phuby.c
ext/phuby/phuby.h
ext/phuby/phuby_array.c
ext/phuby/phuby_array.h
+ext/phuby/phuby_conversions.c
+ext/phuby/phuby_conversions.h
ext/phuby/phuby_runtime.c
ext/phuby/phuby_runtime.h
lib/phuby.rb
lib/phuby/array.rb
lib/phuby/events.rb
-lib/phuby/phuby.bundle
+lib/phuby/php_handler.rb
+lib/phuby/rails.rb
lib/phuby/runtime.rb
php.patch
test/assets/hello_world.php
+test/assets/htdocs/index.php
test/helper.rb
test/test_array.rb
test/test_handlers.rb
test/test_header_sent.rb
+test/test_nil.rb
+test/test_object.rb
+test/test_php_handler.rb
test/test_phuby.rb
test/test_runtime.rb
View
3  bin/phrack
@@ -47,5 +47,4 @@ class Rack::Phrack < Rack::File
end
end
-Rack::Handler::WEBrick.run(Rack::Phrack.new(ARGV[0] || Dir.pwd),
- :Port => 10101) if $0 == __FILE__
+Rack::Handler::WEBrick.run(Rack::Phrack.new(ARGV[0] || Dir.pwd), :Port => 10101)
View
30 lib/phuby/rails.rb
@@ -0,0 +1,30 @@
+require 'phuby'
+
+class PHPHandler < ActionView::TemplateHandler
+ class Events < Struct.new(:code, :headers, :body)
+ def write string; body << string; end
+ def send_headers response_code; end
+
+ def header value, op
+ k, v = value.split(': ', 2)
+ self.code = 302 if k == 'Location' headers[k] = [headers[k], Rack::Utils.unescape(v)].compact.join "\n"
+ end
+ end
+
+ def render template, *args
+ filename = File.join template.load_path, template.template_path
+ events = Events.new(200, {}, '')
+ Dir.chdir(File.dirname(filename)) do
+ Phuby::Runtime.php do |rt|
+ rt.eval "date_default_timezone_set('America/Los_Angeles');"
+ rt.with_events(events) do
+ open(filename) { |f| rt.eval f }
+ end
+ end
+ end
+
+ events.body
+ end
+end
+
+ActionView::Template.register_template_handler('php', PHPHandler)
Please sign in to comment.
Something went wrong with that request. Please try again.