Repository: abhiomkar/flask-react Branch: master Commit: 503d4dad5c39 Files: 13 Total size: 7.4 KB Directory structure: gitextract_u2vxkvbm/ ├── .bowerrc ├── .gitignore ├── LICENSE ├── Procfile ├── README.md ├── app/ │ ├── __init__.py │ ├── static/ │ │ ├── css/ │ │ │ ├── main.css │ │ │ └── styles.css │ │ └── jsx/ │ │ ├── components/ │ │ │ └── App.js │ │ └── main.js │ └── templates/ │ └── base.html ├── bower.json └── requirements.txt ================================================ FILE CONTENTS ================================================ ================================================ FILE: .bowerrc ================================================ { "directory": "app/static/libs" } ================================================ FILE: .gitignore ================================================ app/static/libs/ app/static/js/ node_modules .DS_Store .module-cache Gruntfile.js package.json ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2014 Abhinay Omkar 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. ================================================ FILE: Procfile ================================================ web: gunicorn app:app --log-file=- ================================================ FILE: README.md ================================================ Flask React =========== Introduction ------------ Boilerplate to create a simple web app with Flask and React. Other fontend libraries included Twitter Bootstrap, jQuery, Lodash, Require.js & Font Awesome. Demo ---- Deployed on Heroku: [flask-react.herokuapp.com](http://flask-react.herokuapp.com) Installation ------------ * Install python dependencies pip install flask requests * Install required frontend libraries using [bower](http://bower.io/#install-bower). bower install * Transform JSX to JS using [React tool](http://facebook.github.io/react/docs/tooling-integration.html#productionizing-precompiled-jsx) for development purpose jsx --watch app/static/jsx app/static/js * Run Flask server python app/main.py * Start coding! :) Author ------ Abhinay Omkar License ------- MIT TODO ---- - Migrate to ES6. Get rid of deprecated JSX. - Support server side rendering of React components - Use webpack & gulp for packaging and building. - Use PostCSS. - Add deploy instructions. ================================================ FILE: app/__init__.py ================================================ import requests import os import json from flask import Flask, Response, request, session, g, redirect, url_for, abort, render_template, flash from urlparse import urljoin app = Flask(__name__) @app.route("/") def index(): return render_template('base.html') @app.route('/api/', methods=['GET']) def api(path): clientToken = '' clientSecret = '' baseUrl = 'https://suggestqueries.google.com' accessToken = '' # Authentication # # session.auth = EdgeGridAuth ( # client_token = clientToken, # client_secret = clientSecret, # access_token = accessToken # ) r = requests.get(urljoin(baseUrl, path), params=request.args) if r.status_code != requests.codes.ok: return None return Response(r.content, mimetype='application/json') if __name__ == "__main__": app.run(debug=True) ================================================ FILE: app/static/css/main.css ================================================ @import '../libs/bootstrap/dist/css/bootstrap.min.css'; @import '../libs/font-awesome/css/font-awesome.css'; @import 'styles.css'; ================================================ FILE: app/static/css/styles.css ================================================ .r-container { margin: auto; width: 400px; margin-top: 200px; } .r-container h1 { font-family: 'Helvetica Nueu', Helvetica, Arial, sans-serif; font-weight: 300; font-size: 16px; color: #3F3F3F; } .r-container > input { width: 100%; font-size: 15px; font-weight: 300; border: 1px solid #cdcdcd; padding: 6px; outline: 0; } .r-container > input:hover, .r-container > input:active, .r-container > input:focus { border: 1px solid #bbb; } .r-container > ul.list { margin: 0; padding: 0; list-style: none; border-left: 1px solid #cdcdcd; border-bottom: 1px solid #cdcdcd; border-right: 1px solid #cdcdcd; box-shadow: 1px 1px 3px #cdcdcd; overflow: scroll; } .r-container > ul.list a { cursor: default; color: #333; padding-left: 7px; padding-right: 7px; display: block; } .r-container > ul.list a:hover { text-decoration: none; background: #f1f1f1; } ================================================ FILE: app/static/jsx/components/App.js ================================================ /** @jsx React.DOM */ define([ 'react', ], function(React) { var App = React.createClass({ getInitialState: function() { return { suggestions: [] } }, getAutoSuggestions: function(keywords) { /* @keywords - array of keywords Returns: JSON Response */ var self = this; if (_.isArray(keywords)) { this._xhr = $.get('/api/complete/search?client=firefox&q=' + keywords.join('+'), function(data) { self.setState({suggestions: data[1]}) }); } else { return false; } }, handleChange: function(e) { var keywords = e.target.value.match(/\S+/g), self = this; // clear timeout if timeout is already set if (this._t) { clearTimeout(this._t); } // abort any ajax calls if (this._xhr) { this._xhr.abort(); } // if no keywords then set the suggestions to empty array if (keywords === null) { this.setState({suggestions: []}); } else { this._t = setTimeout(function() { self.getAutoSuggestions(keywords) }, 500); } }, render: function() { var suggestions = []; _.forEach(this.state.suggestions, function(s, i) { suggestions.push(
  • {s}
  • ); }) return (

    Google Auto Suggestion

    {suggestions.length > 0 ?
      {suggestions}
    : null}
    ); } }); return App; }); ================================================ FILE: app/static/jsx/main.js ================================================ require.config({ paths: { react: '../libs/react/react', jquery: '../libs/jquery/dist/jquery.min', lodash: '../libs/lodash/dist/lodash.min', bootstrap: '../libs/bootstrap/dist/js/bootstrap.min' }, shim: { react: { exports: 'React' }, jquery: { exports: '$' }, lodash: { exports: '_' }, bootstrap: { deps: ['jquery'] } } }); require([ 'react', 'components/App', 'jquery', 'lodash', 'bootstrap' ], function(React, App) { React.renderComponent(App(), document.getElementById('app')); }); ================================================ FILE: app/templates/base.html ================================================
    ================================================ FILE: bower.json ================================================ { "name": "Flask React", "version": "0.1.0", "authors": [ "Abhinay Omkar " ], "license": "MIT", "ignore": [ "**/.*", "node_modules", "bower_components", "libs", "test", "tests" ], "dependencies": { "bootstrap": "~3.2.0", "jquery": "~2.1.1", "requirejs": "~2.1.15", "react": "~0.11.1", "font-awesome": "~4.2.0" } } ================================================ FILE: requirements.txt ================================================ Flask==0.10.1 Jinja2==2.7.3 MarkupSafe==0.23 Werkzeug==0.9.6 gunicorn==19.1.1 itsdangerous==0.24 requests==2.4.1 wsgiref==0.1.2