forked from YahooArchive/mojito
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding middleware and mocked models.
- Loading branch information
Joe Catera
committed
Nov 5, 2013
1 parent
026a2f9
commit 4b15e05
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
examples/developer-guide/binding_events/middleware/mojito-contextualizer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = function(config) { | ||
var url = require('url'), | ||
query; | ||
return function(req, res, next) { | ||
|
||
if (!req.context) { | ||
req.context = {}; | ||
} | ||
query = url.parse(req.url, true).query || {}; | ||
req.context.environment = query.environment || ''; | ||
next(); | ||
}; | ||
}; |
51 changes: 51 additions & 0 deletions
51
examples/developer-guide/binding_events/mojits/PagerMojit/models/model.server.mocked.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2011-2013, Yahoo! Inc. All rights reserved. | ||
* Copyrights licensed under the New BSD License. | ||
* See the accompanying LICENSE file for terms. | ||
*/ | ||
|
||
/*jslint anon:true, sloppy:true, nomen:true*/ | ||
|
||
YUI.add('iphonePagerMojitModel', function (Y, NAME) { | ||
var photos = []; | ||
Y.namespace('mojito.models')[NAME] = { | ||
init: function(config) { | ||
this.config = config; | ||
}, | ||
getData: function (search, start, count, callback) { | ||
var id, title, | ||
url = [ | ||
'/static/PagerMojit/assets/pic.com/1234/1001_banffpark.jpg', | ||
'/static/PagerMojit/assets/pic.com/1234/1002_calgary.jpg', | ||
'/static/PagerMojit/assets/pic.com/1234/1003_jasperpark.jpg', | ||
'/static/PagerMojit/assets/pic.com/1234/1004_rockmountain.jpg' | ||
]; | ||
photos.length = 0; | ||
for (i = 0; i < url.length; i += 1) { | ||
id = url[i].match(/com\/(\d+)\/(\d+)_([0-9a-z]+)\.jpg$/); | ||
title = url[i].split("/"); | ||
photos.push({ | ||
id: id[2], | ||
title: title[6], | ||
location: url[i] | ||
}); | ||
} | ||
callback(photos); | ||
}, | ||
getContent: function (imageId, callback) { | ||
for (i = 0; i < photos.length; i += 1) { | ||
id = photos[i].id; | ||
if(imageId === id) { | ||
var raw = { | ||
query: { | ||
results: { | ||
photo: photos[i] | ||
} | ||
} | ||
} | ||
callback(raw); | ||
} | ||
} | ||
} | ||
}; | ||
}, '0.0.1', { requires: ['mojito', 'yql']}); |
13 changes: 13 additions & 0 deletions
13
examples/developer-guide/model_yql/middleware/mojito-contextualizer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = function(config) { | ||
var url = require('url'), | ||
query; | ||
return function(req, res, next) { | ||
|
||
if (!req.context) { | ||
req.context = {}; | ||
} | ||
query = url.parse(req.url, true).query || {}; | ||
req.context.environment = query.environment || ''; | ||
next(); | ||
}; | ||
}; |
13 changes: 13 additions & 0 deletions
13
examples/developer-guide/unittest_model_controller/middleware/mojito-contextualizer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = function(config) { | ||
var url = require('url'), | ||
query; | ||
return function(req, res, next) { | ||
|
||
if (!req.context) { | ||
req.context = {}; | ||
} | ||
query = url.parse(req.url, true).query || {}; | ||
req.context.environment = query.environment || ''; | ||
next(); | ||
}; | ||
}; |