GithubHelp home page GithubHelp logo

minhoryang / flask-yeoman Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tsileo/flask-yeoman

0.0 3.0 0.0 88 KB

A Flask blueprint to make create web application using Yeoman and Flask an easy task.

Home Page: http://thomassileo.com/blog/2013/12/12/using-yeoman-with-flask/

License: MIT License

Python 100.00%

flask-yeoman's Introduction

Flask-Yeoman

A Flask blueprint to make create web application using Yeoman and Flask an easy task.

Features

  • Automatically inject Flask config in index.html
  • Support for development and production mode

Installation

$ pip install flask-yeoman

Getting Started

Create a server.py file in at the root of your yeoman app:

from flask import Flask, jsonify
from flask_yeoman import flask_yeoman

app = Flask(__name__)
app.register_blueprint(flask_yeoman)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000)

You can start working on your app as usual, and since it automatically injects Flask config allowing you to easily share configuration between Flask and your Backbone app (using the tojson` jinja helper):

<script>
window.myapp.config = {myvar: {{ config.MYVAR|tojson }},
                       myvar2: {{ config.MYVAR2|tojson }}};
</script>

Grunt configuration

In order to use your own server with Yeoman, you must create a new task in your Gruntfile.js file:

// New task for flask server
grunt.registerTask('flask', 'Run flask server.', function() {
   var spawn = require('child_process').spawn;
   grunt.log.writeln('Starting Flask development server.');
   // stdio: 'inherit' let us see flask output in grunt
   process.env.FLASK_YEOMAN_DEBUG = 1;
   var PIPE = {stdio: 'inherit'};
   spawn('python', ['server.py'], PIPE);
});

And replace the connect:reload task by flask in the server task:

grunt.registerTask('server', function (target) {
    if (target === 'dist') {
        return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
    } else if (target === 'test') {
        return grunt.task.run([
            'clean:server',
            'coffee',
            'createDefaultTemplate',
            'jst',
            'compass:server',
            'connect:test:keepalive'
        ]);
    }

    grunt.task.run([
        'clean:server',
        'coffee:dist',
        'createDefaultTemplate',
        'jst',
        'compass:server',
        'flask',
        'open',
        'watch'
    ]);
});

Livereload support

And for the livereload support, add this snippet before the closing body in your index.html file:

{% if config.FLASK_YEOMAN_DEBUG %}
<!-- livereload script -->
<script>document.write('<script src="http://'
+ (location.host || 'localhost').split(':')[0]
+ ':35729/livereload.js?snipver=1" type="text/javascript"><\/script>')
</script>
{% endif %}

License (MIT)

Copyright (c) 2013 Thomas Sileo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

flask-yeoman's People

Contributors

minhoryang avatar tsileo avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.