adonis-gravatar

0.0.1 • Public • Published

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('agung.96tm@gmail.com');
    // result: `https://www.gravatar.com/avatar/91f0a80a65760?s=100&r=r&d=retro`

    const gravatarHtmlImage = Gravatar.generateImage(
        'agung.96tm@gmail.com', 'Current User'
    );
    const gravatarHtmlImageWithConfig = Gravatar.generateImage(
        'agung.96tm@gmail.com', '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('agung.9tm@gmail.com', { size: 100 })  }}" 
        alt="Current User">
  </div>

  <div>
    <!-- INFO: with {{{ ... }}} instead of {{ ... }} -->

    {{{ gravatarImage('agung.96tm@gmail.com', 'Current User')  }}}

    <!-- with custom config -->
    {{{ gravatarImage('agung.96tm@gmail.com', 'Current User', { width: 100, height: 100 })  }}}
    {{{ gravatarImage('agung.96tm@gmail.com', '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

Authors


Agung Yuliyanto
💻

Readme

Keywords

none

Package Sidebar

Install

npm i adonis-gravatar

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

9.91 kB

Total Files

8

Last publish

Collaborators

  • agung96tm