PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/share/spice/travis_status/travis_status.js

http://github.com/duckduckgo/zeroclickinfo-spice
JavaScript | 57 lines | 50 code | 7 blank | 0 comment | 7 complexity | 1a04405aa4c1e18af66f28f9c23aa349 MD5 | raw file
Possible License(s): Apache-2.0
  1. (function (env) {
  2. "use strict";
  3. env.ddg_spice_travis_status = function(api_result) {
  4. if (!api_result) {
  5. return Spice.failed('travis_status');
  6. }
  7. var relevantDetails = {
  8. status: api_result.status.indicator,
  9. description: api_result.status.description,
  10. activeIncidents: []
  11. };
  12. for(var i=0,max=api_result.incidents.length; i<max; i++) {
  13. var incident = api_result.incidents[i];
  14. if(incident.status === 'monitoring' || incident.status === 'investigating' || incident.status === 'identified') {
  15. relevantDetails.activeIncidents.push(incident);
  16. }
  17. }
  18. Spice.add({
  19. id: "travis_status",
  20. name: "Status",
  21. data: relevantDetails,
  22. signal: 'low',
  23. meta: {
  24. sourceName: api_result.page.name,
  25. sourceUrl: api_result.page.url,
  26. sourceIconUrl: "https://icons.duckduckgo.com/ip2/docs.travis-ci.com.ico"
  27. },
  28. templates: {
  29. group: 'base',
  30. options:{
  31. content: Spice.travis_status.content,
  32. moreAt: true
  33. }
  34. }
  35. });
  36. }
  37. Spice.registerHelper("TravisStatus_ifCond", function(string1, string2, options) {
  38. return ((string1 === string2) ? options.fn(this) : options.inverse(this));
  39. });
  40. Spice.registerHelper("TravisStatus_ifNotEmpty", function(string, options) {
  41. return ((typeof(string) !== "undefined" && string !== '') ? options.fn(this) : options.inverse(this));
  42. });
  43. Spice.registerHelper("TravisStatus_iterateOver", function(list, block) {
  44. var result = '';
  45. for(var i=0,max=list.length; i<max; i++) {
  46. result += block.fn(list[i]);
  47. }
  48. return result;
  49. });
  50. }(this));