Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
capotej authored and capotej committed Jul 20, 2009
0 parents commit 9e30415
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
47 changes: 47 additions & 0 deletions config.ru
@@ -0,0 +1,47 @@
require 'rubygems'
require 'erb'
require 'rack'

class Joke

#print_r and vardump for completeness
def vardump(o)
o.inspect
end

def print_r(o)
o.inspect
end

#support for array('s',1,4);
def array(*arr)
arr
end

#support for <? ?>
def _preprocess(str)
str = str.gsub('<?', '<%')
str = str.gsub('?>', '%>')
end

#the rack interface
def call(env)
req = Rack::Request.new(env)
path = env['REQUEST_PATH'].sub('/','')
if path == ''
path = 'index.rb'
end
if File.exists?(path)
# $_GET, $_POST and $_REQUEST support
eval('$_REQUEST,$_' << env['REQUEST_METHOD'] << '= req.params,req.params')
response = ERB.new(_preprocess(File.read(path))).result(binding)
# ensure data doesn't stick around between requests
$_GET, $_POST, $_REQUEST = nil
[200, {"Content-Type" => "text/html", "Content-Length" => response.length.to_s}, response]
else
[404, {"Content-Type" => "text/plain", "Content-Length" => '3'}, '404']
end
end
end

run Joke.new
12 changes: 12 additions & 0 deletions form.rb
@@ -0,0 +1,12 @@
<h1>Parameter Testing:</h1>
$_GET:<br/>
<?= print_r($_GET) ?><br/>
$_POST:<br/>
<?= print_r($_POST) ?><br/>
$_REQUEST:<br/>
<%= print_r($_REQUEST)?><br/>
<br/>

<h1>Form result:</h1>
Your name is <%= $_POST["first_name"]%> <%= $_POST["last_name"] %>

18 changes: 18 additions & 0 deletions index.rb
@@ -0,0 +1,18 @@
<h1>Parameter Testing:</h1>
$_GET:<br/>
<?= print_r($_GET) ?><br/>
$_POST:<br/>
<?= print_r($_POST) ?><br/>
$_REQUEST:<br/>
<%= print_r($_REQUEST)?><br/>
<br>

array(1,2,3) = <%= print_r(array(1,2,3)) %>

<h1>Forms:</h1>
<form action="form.rb" method="post">
First Name: <input type="text" name="first_name">
Last Name: <input type="text" name="last_name">
<input type="submit" value="submit">
</form>

0 comments on commit 9e30415

Please sign in to comment.