Flask-Share

Create social share component in Jinja2 template based on share.js.

Installation

$ pip install flask-share

Initialize

from flask_share import Share
...
share = Share(app)

Also support for factory pattern:

from flask_share import Share
share = Share()

def create_app():
    app = Flask(__name__)
    ...
    share.init_app(app)

Example

Here is a simple demo to demonstrate how to create a share component in template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flask-Share Demo</title>
    {{ share.load() }}
</head>
<body>
    <h1>Hello, Flask-Share!</h1>
        <p>Maecenas tincidunt lacus at velit. Phasellus in felis. Praesent
        id massa id nisl venenatis lacinia. Integer ac neque. Morbi ut odio.
        Nullam varius. Sed vel enim sit amet nunc viverra dapibus. Nullam
        varius. In hac habitasse platea dictumst.</p>
        {{ share.create(title='Share with: ') }}
</body>
</html>

And here is what you get:

https://raw.githubusercontent.com/greyli/flask-share/master/images/demo.png

Before you ask, the share component is highly customizable.

Development

We welcome all kinds of contributions. You can run test like this:

$ python setup.py test

Authors

Maintainer: Grey Li

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License (see the LICENSE file for details).

API

class flask_share.Share(app=None)
static create(title='', sites=None, mobile_sites=None, align='left', addition_class='')

Create a share component.

Parameters:
  • title – the prompt displayed on the left of the share component.
  • sites – a string that consist of sites, separate by comma. supported site name: weibo, wechat, douban, facebook, twitter, google, linkedin, qq, qzone. for example: ‘weibo, wechat, qq’.
  • mobile_sites – the sites displayed on mobile.
  • align – the align of the share component, default to ‘left’.
  • addition_class – the style class added to the share component.
static load(css_url=None, js_url=None, serve_local=False)

Load share.js resources.

Parameters:
  • css_url – if set, will be used as css url.
  • js_url – if set, will be used as js url.
  • serve_local – if set to True, the local resource will be used.

Flask-Share Changelog

0.1.2

release date: not release

  • Add documentation.

0.1.1

  • Add unit test.
  • Add local resources.

0.1.0

  • Initial release.