This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #677 from nebiros/master
new script, phpdoc.coffee
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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,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." |