Skip to content

Commit

Permalink
add underscore document support
Browse files Browse the repository at this point in the history
  • Loading branch information
villadora committed May 2, 2013
1 parent f319970 commit 8cffebb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
43 changes: 43 additions & 0 deletions parsers/autosuggest/classes/underscore/UnderscoreParser.php
@@ -0,0 +1,43 @@
<?php

Class UnderscoreParser extends AutoSuggestParser {

public $display_name = "underscore";

public $short_name = "_ud";

public $icon = "icon.png";

protected function addResults($html) {
$doc = new DOMDocument();
$doc->loadHTML($html);

$xpath = new DOMXPath($doc);

// $elems = $xpath->query("/html/body/div[@id='sidebar']/ul[@class='toc_section']/li/a");
$elems = $xpath->query("/html/body/div[@class='container']/div[@id='documentation']/p[@id]");

if (!is_null($elems)) {
foreach ($elems as $el) {

$title = $el->getAttribute("id");

$code = $el->getElementsByTagName("code")->item(0)->nodeValue;

$url = "http://underscores.org/#" . $title;
$this->addResult($url, $title, $code);
}
}
// $description = strip_tags(implode($val->sectionHTMLs, ""));
// $description = str_replace("Summary\n", "", $description);

}

public function update() {

$data = file_get_contents("https://github.com/documentcloud/underscore/raw/master/index.html");
$this->addResults($data);

$this->save();
}
}
Binary file added parsers/autosuggest/classes/underscore/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions parsers/autosuggest/data/data._ud.json
@@ -0,0 +1 @@
[{"url":"http:\/\/underscores.org\/#each","title":"each","description":"_.each(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#map","title":"map","description":"_.map(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#reduce","title":"reduce","description":"_.reduce(list, iterator, memo, [context])"},{"url":"http:\/\/underscores.org\/#reduceRight","title":"reduceRight","description":"_.reduceRight(list, iterator, memo, [context])"},{"url":"http:\/\/underscores.org\/#find","title":"find","description":"_.find(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#filter","title":"filter","description":"_.filter(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#where","title":"where","description":"_.where(list, properties)"},{"url":"http:\/\/underscores.org\/#findWhere","title":"findWhere","description":"_.findWhere(list, properties)"},{"url":"http:\/\/underscores.org\/#reject","title":"reject","description":"_.reject(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#every","title":"every","description":"_.every(list, [iterator], [context])"},{"url":"http:\/\/underscores.org\/#some","title":"some","description":"_.some(list, [iterator], [context])"},{"url":"http:\/\/underscores.org\/#contains","title":"contains","description":"_.contains(list, value)"},{"url":"http:\/\/underscores.org\/#invoke","title":"invoke","description":"_.invoke(list, methodName, [*arguments])"},{"url":"http:\/\/underscores.org\/#pluck","title":"pluck","description":"_.pluck(list, propertyName)"},{"url":"http:\/\/underscores.org\/#max","title":"max","description":"_.max(list, [iterator], [context])"},{"url":"http:\/\/underscores.org\/#min","title":"min","description":"_.min(list, [iterator], [context])"},{"url":"http:\/\/underscores.org\/#sortBy","title":"sortBy","description":"_.sortBy(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#groupBy","title":"groupBy","description":"_.groupBy(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#countBy","title":"countBy","description":"_.countBy(list, iterator, [context])"},{"url":"http:\/\/underscores.org\/#shuffle","title":"shuffle","description":"_.shuffle(list)"},{"url":"http:\/\/underscores.org\/#toArray","title":"toArray","description":"_.toArray(list)"},{"url":"http:\/\/underscores.org\/#size","title":"size","description":"_.size(list)"},{"url":"http:\/\/underscores.org\/#first","title":"first","description":"_.first(array, [n])"},{"url":"http:\/\/underscores.org\/#initial","title":"initial","description":"_.initial(array, [n])"},{"url":"http:\/\/underscores.org\/#last","title":"last","description":"_.last(array, [n])"},{"url":"http:\/\/underscores.org\/#rest","title":"rest","description":"_.rest(array, [index])"},{"url":"http:\/\/underscores.org\/#compact","title":"compact","description":"_.compact(array)"},{"url":"http:\/\/underscores.org\/#flatten","title":"flatten","description":"_.flatten(array, [shallow])"},{"url":"http:\/\/underscores.org\/#without","title":"without","description":"_.without(array, [*values])"},{"url":"http:\/\/underscores.org\/#union","title":"union","description":"_.union(*arrays)"},{"url":"http:\/\/underscores.org\/#intersection","title":"intersection","description":"_.intersection(*arrays)"},{"url":"http:\/\/underscores.org\/#difference","title":"difference","description":"_.difference(array, *others)"},{"url":"http:\/\/underscores.org\/#uniq","title":"uniq","description":"_.uniq(array, [isSorted], [iterator])"},{"url":"http:\/\/underscores.org\/#zip","title":"zip","description":"_.zip(*arrays)"},{"url":"http:\/\/underscores.org\/#object","title":"object","description":"_.object(list, [values])"},{"url":"http:\/\/underscores.org\/#indexOf","title":"indexOf","description":"_.indexOf(array, value, [isSorted])"},{"url":"http:\/\/underscores.org\/#lastIndexOf","title":"lastIndexOf","description":"_.lastIndexOf(array, value, [fromIndex])"},{"url":"http:\/\/underscores.org\/#sortedIndex","title":"sortedIndex","description":"_.sortedIndex(list, value, [iterator], [context])"},{"url":"http:\/\/underscores.org\/#range","title":"range","description":"_.range([start], stop, [step])"},{"url":"http:\/\/underscores.org\/#bind","title":"bind","description":"_.bind(function, object, [*arguments])"},{"url":"http:\/\/underscores.org\/#bindAll","title":"bindAll","description":"_.bindAll(object, [*methodNames])"},{"url":"http:\/\/underscores.org\/#partial","title":"partial","description":"_.partial(function, [*arguments])"},{"url":"http:\/\/underscores.org\/#memoize","title":"memoize","description":"_.memoize(function, [hashFunction])"},{"url":"http:\/\/underscores.org\/#delay","title":"delay","description":"_.delay(function, wait, [*arguments])"},{"url":"http:\/\/underscores.org\/#defer","title":"defer","description":"_.defer(function, [*arguments])"},{"url":"http:\/\/underscores.org\/#throttle","title":"throttle","description":"_.throttle(function, wait)"},{"url":"http:\/\/underscores.org\/#debounce","title":"debounce","description":"_.debounce(function, wait, [immediate])"},{"url":"http:\/\/underscores.org\/#once","title":"once","description":"_.once(function)"},{"url":"http:\/\/underscores.org\/#after","title":"after","description":"_.after(count, function)"},{"url":"http:\/\/underscores.org\/#wrap","title":"wrap","description":"_.wrap(function, wrapper)"},{"url":"http:\/\/underscores.org\/#compose","title":"compose","description":"_.compose(*functions)"},{"url":"http:\/\/underscores.org\/#keys","title":"keys","description":"_.keys(object)"},{"url":"http:\/\/underscores.org\/#values","title":"values","description":"_.values(object)"},{"url":"http:\/\/underscores.org\/#pairs","title":"pairs","description":"_.pairs(object)"},{"url":"http:\/\/underscores.org\/#invert","title":"invert","description":"_.invert(object)"},{"url":"http:\/\/underscores.org\/#object-functions","title":"object-functions","description":"_.functions(object)"},{"url":"http:\/\/underscores.org\/#extend","title":"extend","description":"_.extend(destination, *sources)"},{"url":"http:\/\/underscores.org\/#pick","title":"pick","description":"_.pick(object, *keys)"},{"url":"http:\/\/underscores.org\/#omit","title":"omit","description":"_.omit(object, *keys)"},{"url":"http:\/\/underscores.org\/#defaults","title":"defaults","description":"_.defaults(object, *defaults)"},{"url":"http:\/\/underscores.org\/#clone","title":"clone","description":"_.clone(object)"},{"url":"http:\/\/underscores.org\/#tap","title":"tap","description":"_.tap(object, interceptor)"},{"url":"http:\/\/underscores.org\/#has","title":"has","description":"_.has(object, key)"},{"url":"http:\/\/underscores.org\/#isEqual","title":"isEqual","description":"_.isEqual(object, other)"},{"url":"http:\/\/underscores.org\/#isEmpty","title":"isEmpty","description":"_.isEmpty(object)"},{"url":"http:\/\/underscores.org\/#isElement","title":"isElement","description":"_.isElement(object)"},{"url":"http:\/\/underscores.org\/#isArray","title":"isArray","description":"_.isArray(object)"},{"url":"http:\/\/underscores.org\/#isObject","title":"isObject","description":"_.isObject(value)"},{"url":"http:\/\/underscores.org\/#isArguments","title":"isArguments","description":"_.isArguments(object)"},{"url":"http:\/\/underscores.org\/#isFunction","title":"isFunction","description":"_.isFunction(object)"},{"url":"http:\/\/underscores.org\/#isString","title":"isString","description":"_.isString(object)"},{"url":"http:\/\/underscores.org\/#isNumber","title":"isNumber","description":"_.isNumber(object)"},{"url":"http:\/\/underscores.org\/#isFinite","title":"isFinite","description":"_.isFinite(object)"},{"url":"http:\/\/underscores.org\/#isBoolean","title":"isBoolean","description":"_.isBoolean(object)"},{"url":"http:\/\/underscores.org\/#isDate","title":"isDate","description":"_.isDate(object)"},{"url":"http:\/\/underscores.org\/#isRegExp","title":"isRegExp","description":"_.isRegExp(object)"},{"url":"http:\/\/underscores.org\/#isNaN","title":"isNaN","description":"_.isNaN(object)"},{"url":"http:\/\/underscores.org\/#isNull","title":"isNull","description":"_.isNull(object)"},{"url":"http:\/\/underscores.org\/#isUndefined","title":"isUndefined","description":"_.isUndefined(value)"},{"url":"http:\/\/underscores.org\/#noConflict","title":"noConflict","description":"_.noConflict()"},{"url":"http:\/\/underscores.org\/#identity","title":"identity","description":"_.identity(value)"},{"url":"http:\/\/underscores.org\/#times","title":"times","description":"_.times(n, iterator, [context])"},{"url":"http:\/\/underscores.org\/#random","title":"random","description":"_.random(min, max)"},{"url":"http:\/\/underscores.org\/#mixin","title":"mixin","description":"_.mixin(object)"},{"url":"http:\/\/underscores.org\/#uniqueId","title":"uniqueId","description":"_.uniqueId([prefix])"},{"url":"http:\/\/underscores.org\/#escape","title":"escape","description":"_.escape(string)"},{"url":"http:\/\/underscores.org\/#unescape","title":"unescape","description":"_.unescape(string)"},{"url":"http:\/\/underscores.org\/#result","title":"result","description":"_.result(object, property)"},{"url":"http:\/\/underscores.org\/#template","title":"template","description":"_.template(templateString, [data], [settings])"},{"url":"http:\/\/underscores.org\/#chain","title":"chain","description":"_.chain(obj)"},{"url":"http:\/\/underscores.org\/#value","title":"value","description":"_(obj).value()"}]
8 changes: 5 additions & 3 deletions test.php
Expand Up @@ -4,9 +4,11 @@
$str = html_entity_decode($str);
echo $str;

exit;
$type = "html";
$query = "wbr";
//exit;
//$type = "html";
$type = "underscore";
//$query = "wbr";
$query = "some";

require_once('search.php');

Expand Down

0 comments on commit 8cffebb

Please sign in to comment.