Skip to content

Commit

Permalink
FINALLY got ASP collection enumerating working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
remi committed Nov 22, 2009
1 parent a8aa295 commit 96bca44
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app.js
Expand Up @@ -24,4 +24,9 @@ post('/foo', function(){
return 'POSTed to foo';
});

post('/params', function(){
return JSON.stringify(this.params);
return map(this.params, function(key, value){ return '' + key + ': ' + value; }).join();
});

run(sinatra_app);
2 changes: 2 additions & 0 deletions rack/rack.js
@@ -1,3 +1,5 @@
req(uire('util/functions'));

// something kindof like Rack for classic ASP
var Rack = {

Expand Down
3 changes: 2 additions & 1 deletion sinatra/sinatra.js
Expand Up @@ -41,7 +41,8 @@ function sinatra_app(env){
if (block != null){

var environment = {
env: env,
env: env,
params: coll2hash(Request.Form()),
render_haml: function(text, scope){
return Haml.to_html(Haml.parse.call(scope, text));
},
Expand Down
5 changes: 5 additions & 0 deletions spec/sinatra/app.js
Expand Up @@ -24,4 +24,9 @@ post('/foo', function(){
return 'POSTed to foo';
});

post('/params', function(){
return JSON.stringify(this.params);
return map(this.params, function(key, value){ return '' + key + ': ' + value; }).join();
});

run(sinatra_app);
5 changes: 4 additions & 1 deletion spec/sinatra/sinatra_spec.rb
Expand Up @@ -31,7 +31,10 @@
post('/does-not-exist.asp').body.should include('POST /does-not-exist')
end

it 'should be able to get POSTed params'
it 'should be able to get POSTed params' do
post('/params.asp', :body => { :foo => 'bar' }).body.should == '{"foo":"bar"}'
end

it 'should be able to get query string params'

it 'should be able to use Regexp for paths'
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -19,8 +19,8 @@ def get uri
HTTParty.get File.join(asp_server, uri)
end

def post uri
HTTParty.post File.join(asp_server, uri)
def post uri, params = {}
HTTParty.post File.join(asp_server, uri), params
end

def put uri
Expand Down
16 changes: 15 additions & 1 deletion util/functions.js
Expand Up @@ -11,7 +11,7 @@ function each( collection, block, include_functions ){
function map( collection, block ){
var to_return = [];
each(collection, function(key, value){
to_return[to_return.length] = block(value);
to_return[to_return.length] = block(key, value);
});
return to_return;
}
Expand All @@ -36,3 +36,17 @@ function nano(text, variables){
}

function n(text, variables){ return nano(text, variables); }

function coll2hash(asp_collection){
var hash = {};

// from http://andrewu.co.uk/tools/servervariables/
// and http://aspjavascript.com/lesson09.asp
for (var objItem = new Enumerator(asp_collection); !objItem.atEnd(); objItem.moveNext()) {
var strKeyName = objItem.item();
var strKeyValue = asp_collection(strKeyName).Count() ? asp_collection(strKeyName).Item(1) : "";
hash[strKeyName] = strKeyValue;
}

return hash;
}

0 comments on commit 96bca44

Please sign in to comment.