Created
March 20, 2012 03:10
-
-
Save takimo/2130673 to your computer and use it in GitHub Desktop.
brook on nodejs
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
print "var Namespace = require('../lib/namespace.js');\n"; | |
print <STDIN>; | |
print qq| | |
Namespace() | |
.use('brook *') | |
.use('brook.util *') | |
.apply(function(ns){ | |
module.exports = ns; | |
}); | |
|; |
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
diff --git a/Makefile b/Makefile | |
index 22a63fc..51cf4ac 100644 | |
--- a/Makefile | |
+++ b/Makefile | |
@@ -5,7 +5,8 @@ COMPAT = ./build/brook.js | |
MOBILE = ./build/brook-mobile.js | |
MIN = ./build/brook.min.js | |
HTP = ./build/brook-view-htmltemplate-core.js | |
-all : $(CORE) $(COMPAT) $(MIN) | |
+NODE = ./build/brook-nodejs.js | |
+all : $(CORE) $(COMPAT) $(MIN) $(NODE) | |
clean : | |
rm -rf ./build/* | |
@@ -18,6 +19,11 @@ $(CORE) : \ | |
./src/brook/model.js | |
cat $^ > $@ | |
+$(NODE) : \ | |
+ ./src/brook.js \ | |
+ ./src/brook/util.js | |
+ cat $^ | perl ./bin/exportnode > $@ | |
+ | |
$(HTP) : ./lib/html-template-core.js | |
perl ./bin/wrapns $^ "brook.view.htmltemplate.core" > $@ |
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
var brook = require('./brook/build/brook-nodejs.js'); | |
var promise = brook.promise; | |
var request = require('request'); | |
promise() | |
.bind(function(next, value){ | |
console.log("ATNDから入力されたキーワードに関係するイベントの参加者を出力します"); | |
console.log("キーワードを入力してください"); | |
next(value) | |
}) | |
.bind(function(next, value){ | |
var stdin; | |
stdin = process.openStdin(); | |
stdin.setEncoding('utf8'); | |
stdin.on('data', function(input){ | |
var keyword; | |
keyword = input.trim(); | |
next(keyword) | |
}) | |
}) | |
.bind(brook.debug("通過していく値を見る事が出来ます")) | |
.bind(function(next, value){ | |
var url = "http://api.atnd.org/events/?keyword=" + value + "&format=json&count=1"; | |
request({url: url}, function(error, response, body){ | |
var json = JSON.parse(body); | |
var event; | |
if(json && json.events.length){ | |
event = json.events[0]; | |
next(event); | |
}else{ | |
process.exit(); | |
} | |
}); | |
}) | |
.bind(function(next, value){ | |
var url = "http://api.atnd.org/events/users/?event_id=" + value.event_id + "&format=json"; | |
request({url: url}, function(error, response, body){ | |
console.log(body); | |
var json = JSON.parse(body); | |
var event = json.events[0]; | |
next(event.users); | |
}); | |
}) | |
.bind(brook.cond(function(value){ | |
return (value && value.length > 10) | |
}, promise(function(next, value){ | |
console.log("10人以上参加しています"); | |
next(value); | |
}))) | |
.bind(brook.mapper(function(value){ | |
return value.map(function(user){ | |
return user.nickname; | |
}); | |
})) | |
.subscribe(function(value){ | |
console.log(value) | |
process.exit(); | |
}, "hello"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment