Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 16e984d

Browse files
committed
phpdoc: use cheerio instead of jquery, to support non-GUI environments
1 parent 1b2d3ca commit 16e984d

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/scripts/phpdoc.coffee

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,31 @@
22
# PHP's functions reference.
33
#
44
# Dependencies:
5-
# "jsdom": ""
6-
# "jquery": ""
5+
# "cheerio": ""
76
#
87
# Configuration:
98
# None
109
#
1110
# Commands:
1211
# hubot phpdoc for <function> - Shows PHP function information.
1312
#
14-
# Author:
13+
# Authors:
1514
# nebiros
16-
17-
jsdom = require("jsdom").jsdom
15+
# Carter McKendry
1816

1917
module.exports = (robot) ->
2018
robot.respond /phpdoc for (.+)$/i, (msg) ->
2119
msg
2220
.http("http://www.php.net/manual/en/function." + msg.match[1].replace(/[_-]+/, "-") + ".php")
2321
.get() (err, res, body) ->
24-
window = (jsdom body, null,
25-
features:
26-
FetchExternalResources: false
27-
ProcessExternalResources: false
28-
MutationEvents: false
29-
QuerySelector: false
30-
).createWindow()
3122

32-
$ = require("jquery").create(window)
33-
ver = $.trim $(".refnamediv p.verinfo").text()
34-
desc = $.trim $(".refnamediv span.dc-title").text()
35-
syn = $.trim $(".methodsynopsis").text().replace(/\s+/g, " ").replace(/(\r\n|\n|\r)/gm, " ")
23+
$ = require("cheerio").load(body)
24+
ver = $(".refnamediv p.verinfo").text()
25+
desc = $(".refnamediv span.dc-title").text()
26+
syn = $(".methodsynopsis").text().replace(/\s+/g, " ").replace(/(\r\n|\n|\r)/gm, " ")
3627

3728
if ver and desc and syn
3829
msg.send "#{ver} - #{desc}"
3930
msg.send syn
4031
else
41-
msg.send "Not found."
32+
msg.send "Not found."

0 commit comments

Comments
 (0)