Skip to content

Commit

Permalink
Merge pull request duckduckgo#2224 from soleo/cocoapods
Browse files Browse the repository at this point in the history
New Cocoapods Spice
  • Loading branch information
moollaza committed Oct 21, 2015
2 parents 4061952 + d05cbc0 commit 319c250
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/DDG/Spice/Cocoapods.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package DDG::Spice::Cocoapods;

use DDG::Spice;

spice is_cached => 1;

name "Cocoapods";
source "https://cocoapods.org";
icon_url "https://cocoapods.org/favicons/favicon.ico";
description "Search Pod Info from Cocoapods";
primary_example_queries "cocoapods AFNetworking", "cocoapods SVProgressHUD";
secondary_example_queries "cocoapods AFNetworking for ios";

category "programming";

topics "computing", "programming";
code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Cocoapods.pm";
attribution github => ["https://github.com/soleo", "Xinjiang Shao"],
twitter => ['https://twitter.com/soleoshao', 'Xinjiang Shao'];

triggers startend => 'cocoapods';

spice to => 'http:https://search.cocoapods.org/api/v1/pods.flat.hash.json?query=$1';
spice wrap_jsonp_callback => 1;

handle remainder => sub {
return lc $_ if $_;
return;
};


1;
49 changes: 49 additions & 0 deletions share/spice/cocoapods/cocoapods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(function (env) {
"use strict";
env.ddg_spice_cocoapods = function(api_result){


if (!api_result || api_result.error) {
return Spice.failed('cocoapods');
}

// Get the original query.
var query = DDG.get_query().replace("cocoapods", "");

// Render the response
Spice.add({
id: "cocoapods",
name: "Software",
data: api_result,
meta: {
sourceName: "CocoaPods",
sourceUrl: 'https://cocoapods.org/?q=' + encodeURIComponent(query),
sourceIconUrl: 'http:https://cocoapods.org/favicons/favicon.ico',
total: api_result.length
},

normalize: function(item) {
return {
title: item.id,
subtitle: item.version,
url: item.link,
description: item.summary,
platforms: item.platforms.join(', ').toUpperCase()
}
},

templates: {
group: 'list',
detail: false,
item_detail: false,
variants: {
tile: 'basic4',
tileSnippet: 'small'
},
options: {
footer: Spice.cocoapods.footer
}
}
});
};
}(this));
4 changes: 4 additions & 0 deletions share/spice/cocoapods/footer.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="one-line opt--right">
{{platforms}}
</div>

41 changes: 41 additions & 0 deletions t/Cocoapods.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use DDG::Test::Spice;

spice is_cached => 1;

ddg_spice_test(
[qw( DDG::Spice::Cocoapods)],

'cocoapods test' => test_spice(
'/js/spice/cocoapods/test',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),
'cocoapods afnetworking' => test_spice(
'/js/spice/cocoapods/afnetworking',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),
'cocoapods SVProgressHUD' => test_spice(
'/js/spice/cocoapods/svprogresshud',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),
'cocoapods AFNetworking for ios' => test_spice(
'/js/spice/cocoapods/afnetworking%20for%20ios',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),

# Try to include some examples of queries on which it might
# appear that your answer will trigger, but does not.
'cocoapod test afnetworking' => undef,
'pod afnetworking' => undef,
);

done_testing;

0 comments on commit 319c250

Please sign in to comment.