Skip to content

Commit

Permalink
Merge pull request #61 from zabirauf/master
Browse files Browse the repository at this point in the history
Added Hex package manager
  • Loading branch information
willfarrell committed Mar 22, 2015
2 parents e2ff3c5 + fed37ad commit 8c9a356
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 4 deletions.
Binary file modified Package Managers.alfredworkflow
Binary file not shown.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Package Managers ([Download v2.10](https://raw.github.com/willfarrell/alfred-pkgman-workflow/master/Package%20Managers.alfredworkflow))
# Package Managers ([Download v2.12](https://raw.github.com/willfarrell/alfred-pkgman-workflow/master/Package%20Managers.alfredworkflow))

Package Repo Search

Expand All @@ -22,6 +22,7 @@ Quick package/plugin/component (repo) lookup for your favourite package managers
* `gradle {query}`: Java [Gradle Packages](http://www.gradle.org)
* `grunt {query}`: nodeJS task-runner [Grunt Plugins](http://gruntjs.com)
* `gulp {query}`: nodeJS task-runner [Gulp plugins](http://gulpjs.com)
* `hex {query}`: Elixir [Hex Packages](http://hex.pm)
* `maven {query}`: Java [Maven Libraries](http://mvnrepository.com)
* `npm {query}`: nodeJS [NPM Packages](https://www.npmjs.org)
* `pear {query}`: PHP [Pear Packages](http://pear.php.net)
Expand Down Expand Up @@ -63,6 +64,7 @@ The Python Package Index is very slow due to a lack on API and pagination. A min
![][rpm]
![][docker]
![][chef]
![][hex]

[alcatraz]: ./screenshots/alcatraz.png "Sample alcatraz result"
[bower]: ./screenshots/bower.png "Sample bower result"
Expand All @@ -74,6 +76,7 @@ The Python Package Index is very slow due to a lack on API and pagination. A min
[gems]: ./screenshots/gems.png "Sample gems result"
[grunt]: ./screenshots/grunt.png "Sample grunt result"
[gulp]: ./screenshots/gulp.png "Sample gulp result"
[hex]: ./screenshots/hex.png "Sample hex resuls"
[maven]: ./screenshots/maven.png "Sample maven result"
[npm]: ./screenshots/npm.png "Sample npm result"
[pear]: ./screenshots/pear.png "Sample pear result"
Expand Down
2 changes: 1 addition & 1 deletion current-version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 2.11,
"version": 2.12,
"download_url": "https://raw.github.com/willfarrell/alfred-pkgman-workflow/master/Package%20Managers.alfredworkflow",
"description": "Package Repo Search"
}
Binary file added icon-cache/hex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon-src/hex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/hex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions v2/hex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

/*
Hex
*/

// ****************

require_once('cache.php');

class Repo {

private $id = 'hex';
private $kind = 'components'; // for none found msg
private $min_query_length = 1; // increase for slow DBs
private $max_return = 25;

private $cache;
private $w;
private $pkgs;

function __construct() {

$this->cache = new Cache();

// get DB here if not dynamic search
//$data = (array) $this->cache->get_db('.$this->id.');
}

// return id | url | pkgstr
function makeArg($id, $url, $version) {
return $id . "|" . $url . "|" . "\"$id\":\"$version\",";
}

/*function check($pkg, $query) {
if (!$query) { return true; }
if (strpos($pkg["name"], $query) !== false) {
return true;
} else if (strpos($pkg["description"], $query) !== false) {
return true;
}
return false;
}*/

function search($query) {
if ( strlen($query) < $this->min_query_length) {
if ( strlen($query) === 0 ) { return; }
$this->cache->w->result(
"{$this->id}-min",
$query,
"Minimum query length of {$this->min_query_length} not met.",
"",
"icon-cache/{$this->id}.png"
);
return;
}

$this->pkgs = $this->cache->get_query_json('hex', $query, 'https://hex.pm/api/packages?search='.$query);

foreach($this->pkgs as $pkg) {
$url = str_replace("api/", "", $pkg->url);
$this->cache->w->result(
$pkg->url,
$this->makeArg($pkg->name, $url, "*"),
$pkg->name, $url,
"icon-cache/{$this->id}.png"
);

// only search till max return reached
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
break;
}
}

if ( count( $this->cache->w->results() ) == 0) {
$this->cache->w->result(
"{$this->id}-search",
"https://hex.pm/packages?search={$query}",
"No {$this->kind} were found that matched \"{$query}\"",
"Click to see the results for yourself",
"icon-cache/{$this->id}.png"
);
}
}

function xml() {
$this->cache->w->result(
"{$this->id}-www",
"http://hex.pm/",
"Go to the website",
"http://hex.pm",
"icon-cache/{$this->id}.png"
);

return $this->cache->w->toxml();
}

}

// ****************

/*$query = "leaflet";
$repo = new Repo();
$repo->search($query);
echo $repo->xml();*/

?>
4 changes: 2 additions & 2 deletions v2/update.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": 2.03,
"version": 2.04,
"remote_json": "https://raw.githubusercontent.com/willfarrell/alfred-pkgman-workflow/master/current-version.json"
}
}

0 comments on commit 8c9a356

Please sign in to comment.