Skip to content

Commit

Permalink
Add Sublime Text package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
yicone committed Dec 27, 2016
1 parent 35744e6 commit 5426e8f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
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 v3.12](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.12/Package.Managers.alfredworkflow))
# Package Managers ([Download v3.13](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.13/Package.Managers.alfredworkflow))

Package Repo Search

Expand Down Expand Up @@ -31,6 +31,7 @@ Quick package/plugin/component (repo) lookup for your favourite package managers
* `pypi {query}`: [Python Packages](https://pypi.python.org)
* `raspbian {query}`: [Rasberry Pi Packages](http://www.raspbian.org)
* `rpm {query}`: [Linux Packages](http://rpmfind.net)
* `st {query}`: [Sublime Text Packages](https://packagecontrol.io)
* `yo {query}`: [Yeoman Generators](http://yeoman.io)

## Action Modifiers
Expand Down Expand Up @@ -68,6 +69,7 @@ The Python Package Index is very slow due to a lack on API and pagination. A min
![][chef]
![][apm]
![][hex]
![][st]

Featured on [Smashing Magazine](http://www.smashingmagazine.com/2013/10/25/hidden-productivity-secrets-with-alfred/)

Expand All @@ -89,4 +91,5 @@ Featured on [Smashing Magazine](http://www.smashingmagazine.com/2013/10/25/hidde
[pear]: ./screenshots/pear.png "Sample pear result"
[pypi]: ./screenshots/pypi.png "Sample pypi result"
[rpm]: ./screenshots/rpm.png "Sample rpm result"
[st]: ./screenshots/stpm.png "Sample stpm result"
[yo]: ./screenshots/yo.png "Sample yo result"
Binary file added icon-cache/stpm.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/stpm.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/stpm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/Stpm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
namespace WillFarrell\AlfredPkgMan;

require_once('Cache.php');
require_once('Repo.php');

class Stpm extends Repo
{
protected $id = 'stpm';
protected $url = 'https://packagecontrol.io';
protected $search_url = 'https://packagecontrol.io/search/';

public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
return $this->xml();
}

$data = $this->cache->get_query_regex(
$this->id,
$query,
"{$this->search_url}{$query}",
'/<ul class="packages results">([\s\S]*?)<\/ul>/i'
);

$this->pkgs = explode('<li class="package">', $data[0]);
array_shift($this->pkgs);

foreach($this->pkgs as $pkg) {
// make params
preg_match('/<h3>([\s\S]*?)<\/h3>/i', $pkg, $matches);
$title = trim(strip_tags($matches[1]));

preg_match(
'/<div class="description">([\s\S]*?)<\/div>/i',
$pkg,
$matches
);

$description = html_entity_decode(trim(strip_tags($matches[1])));

preg_match('/<span class="author">([\s\S]*?)<\/span>/i', $pkg, $matches);
$author = trim(strip_tags($matches[1]));
// $version = trim(strip_tags($matches[1]));

$this->cache->w->result(
$title,
$this->makeArg($title, "{$this->url}/packages/{$title}"),
"{$title} ~ {$author}", // "v{$version}"
$description,
"icon-cache/{$this->id}.png"
);

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

$this->noResults($query, "{$this->search_url}{$query}");

return $this->xml();
}
}

// Test code, uncomment to debug this script from the command-line
// $repo = new Atom();
// echo $repo->search('q');

0 comments on commit 5426e8f

Please sign in to comment.