Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Metrakit committed May 9, 2016
0 parents commit 8dbe065
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# hain-plugin-meme

[![npm](https://img.shields.io/npm/dt/hain-plugin-meme.svg)](https://www.npmjs.com/package/hain-plugin-meme
) [![npm](https://img.shields.io/npm/dm/hain-plugin-meme.svg)](https://www.npmjs.com/package/hain-plugin-meme
) [![GitHub release](https://img.shields.io/github/release/metrakit/hain-plugin-meme.svg)](https://www.npmjs.com/package/hain-plugin-meme)

A plugin for generate fastly a meme in the [Hain](https://github.com/appetizermonster/hain) app (Alfred clone for Windows).
This plugin use the [Memegen API](http://memegen.link).

## Install

Type this command in the Hain input :
```
/hpm install meme
```

## Usage

```
/meme I'm awesome / Yeah ! /
```

### Credit

Thanks to [Memegen](http://memegen.link/)
70 changes: 70 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

const got = require('got');
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const ncp = require("copy-paste");

const tplUrl = 'http://memegen.link/templates/';

module.exports = (context) => {
const shell = context.shell;
const logger = context.logger;

let html = [];
let tpls = [];

function startup() {
html = fs.readFileSync(path.join(__dirname, 'preview.html'), 'utf8');
got(tplUrl).then(response => {
tpls = JSON.parse(response.body);
});
}

function search(query, res) {
const query_trim = query.trim();
const query_parts = _.split(query_trim, '/', 3);

logger.log(query_parts);
logger.log(query_parts.length);

res.add({
id: `help`,
payload: 'help',
title: 'How to',
desc: 'For generate a meme type : /meme Example / awesome meme /'
});

if (query_parts.length === 3) {
return _.forEach(tpls, (url, name) => {
url = _.replace(url, 'templates/', '');
url += '/' + encodeURIComponent(query_parts[0]) + '/' + encodeURIComponent(query_parts[1]) + '.jpg';
res.add({
id: url,
payload: 'open',
title: name,
desc: 'Click for copy the meme to your clipboard',
icon: '#fa fa-file-image-o',
preview: true
});
});
}
}

function execute(url, payload) {
if (payload !== 'open')
return;
ncp.copy(url, function() {
context.toast.enqueue('Pasted to clipboard !');
})
}

function renderPreview(url, payload, render) {
var preview = html.replace('%picture%', url);
preview = preview.replace('%url%', url);
render(preview);
}

return { startup, search, execute, renderPreview };
};
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "hain-plugin-meme",
"version": "0.0.1",
"description": "hain plugin to search a meme on giphy.com",
"main": "index.js",
"scripts": {},
"repository": {
"type": "git",
"url": "git+https://github.com/metrakit/hain-plugin-meme.git"
},
"author": "Jordane JOUFFROY",
"license": "MIT",
"keywords": [
"hain0"
],
"bugs": {
"url": "https://github.com/metrakit/hain-plugin-meme/issues"
},
"homepage": "https://github.com/metrakit/hain-plugin-meme",
"dependencies": {
"got": "^6.2.0",
"lodash": "^4.6.1",
"copy-paste": "^1.1.4"
},
"hain": {
"prefix": "/meme",
"usage": "/meme an awesome meme",
"icon": "/logo.png",
"redirect": "/meme "
}
}
26 changes: 26 additions & 0 deletions preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<head>
<style type="text/css">
img {
max-width: 100%;
}
input {
height: 28px;
border-radius: 5px;
border: solid 1px lightgray;
padding-left: 2%;
padding-right: 2%;
width: 96%;
outline: 0;
}
.img-block {
text-align: center;
}
</style>
<body>
<div class="img-block">
<img src="%picture%">
</div>
<input type="text" value="%url%">
</body>
</html>

0 comments on commit 8dbe065

Please sign in to comment.