Browse files

new script, phpdoc.coffee.

  • Loading branch information...
1 parent 604ebcb commit 37e6c70e11d4582abe9932208c66099fb6ca659b @nebiros nebiros committed Jan 3, 2013
Showing with 41 additions and 0 deletions.
  1. +41 −0 src/scripts/phpdoc.coffee
View
41 src/scripts/phpdoc.coffee
@@ -0,0 +1,41 @@
+# Description:
+# PHP's functions reference.
+#
+# Dependencies:
+# "jsdom": ""
+# "jquery": ""
+#
+# Configuration:
+# None
+#
+# Commands:
+# hubot phpdoc for <function> - Shows PHP function information.
+#
+# Author:
+# nebiros
+
+jsdom = require("jsdom").jsdom
+
+module.exports = (robot) ->
+ robot.respond /phpdoc for (.+)$/i, (msg) ->
+ msg
+ .http("http://www.php.net/manual/en/function." + msg.match[1].replace(/[_-]+/, "-") + ".php")
+ .get() (err, res, body) ->
+ window = (jsdom body, null,
+ features:
+ FetchExternalResources: false
+ ProcessExternalResources: false
+ MutationEvents: false
+ QuerySelector: false
+ ).createWindow()
+
+ $ = require("jquery").create(window)
+ ver = $.trim $(".refnamediv p.verinfo").text()
+ desc = $.trim $(".refnamediv span.dc-title").text()
+ syn = $.trim $(".methodsynopsis").text().replace(/\s+/g, " ").replace(/(\r\n|\n|\r)/gm, " ")
+
+ if ver and desc and syn
+ msg.send "#{ver} - #{desc}"
+ msg.send syn
+ else
+ msg.send "Not found."

0 comments on commit 37e6c70

Please sign in to comment.