adonis-gravatar
v0.0.1
Published
Integration gravatar into adonis
Downloads
8
Readme
Adonis Gravatar
Integration gravatar into adonis.
Getting Started
Install the package using the adonis
CLI.
> adonis install adonis-gravatar
Instruction: (Click Here).
Instructions
Config
The config file is saved as config/gravatar.js
.
module.exports = {
size : Env.get('GRAVATAR_SIZE', 100),
rating: Env.get('GRAVATAR_RATING', 'r'),
default: Env.get('GRAVATAR_DEFAULT', 'mp')
}
or you can use environment variables that you can set on .env
file.
GRAVATAR_SIZE=false
GRAVATAR_RATING=r
GRAVATAR_DEFAULT=mp
How To Use
on controller:
const Gravatar = use('Gravatar');
class AwesomeController {
index ({ view }) {
const gravatarUrl = Gravatar.generateSrc('[email protected]');
// result: `https://www.gravatar.com/avatar/91f0a80a65760?s=100&r=r&d=retro`
const gravatarHtmlImage = Gravatar.generateImage(
'[email protected]', 'Current User'
);
const gravatarHtmlImageWithConfig = Gravatar.generateImage(
'[email protected]', 'Current User', { size: 200, default: 'retro' }
);
// result: `<img src="https://www.gravatar.com/avatar/91f0a80a65760 alt="Current User" ... >`
return gravatarUrl;
}
}
on view:
<body>
<h1>Hello World</h1>
<div>
<img
src="{{ gravatarUrl('[email protected]', { size: 100 }) }}"
alt="Current User">
</div>
<div>
<!-- INFO: with {{{ ... }}} instead of {{ ... }} -->
{{{ gravatarImage('[email protected]', 'Current User') }}}
<!-- with custom config -->
{{{ gravatarImage('[email protected]', 'Current User', { width: 100, height: 100 }) }}}
{{{ gravatarImage('[email protected]', 'Current User', { width: 100, height: 100, default: 'robohash' }) }}}
</div>
</body>
Properties
| Argument | Description | Type | Default |
| ------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | -------------------------------- |
| size
| Size of gravatar. | number
| 100 |
| rating
| Rating of gravatar. | g
, pg
, r
, x
| r |
| default
| gravatar has a number of built in options which you can also use as defaults | 404
, mp
, identicon
, monsterid
, wavatar
, retro
, robohash
, blank
| mp |
| width
| set attribute width for HTML image, used by gravatarImage
function | string
| same as size argument |
| height
| set attribute height for HTML image, used by gravatarImage
function | string
| same as size argument |