Пример #1
0
    def init_extensions(self):
        super(App, self).init_extensions()

        manifest = os.path.join(path, 'assets', 'manifest.yaml')
        bundles = YAMLLoader(manifest).load_bundles()

        for name, bundle in bundles.iteritems():
            self.assets.register(name, bundle)
Пример #2
0
def setup_bundles(app):
    assets_env = Environment(app)
    assets_env.url = '/statics'
    assets_env.manifest = 'file:Compiled/static-manifest-version'
    assets_env.cache = False
    assets_env.auto_build = False
    assets_env.debug = app.config.get('DEVELOPMENT') == True

    # load and register bundles
    config_path = app.instance_path + '/config/asset_bundles.yaml'
    bundles = YAMLLoader(config_path).load_bundles()
    for name, bundle in bundles.iteritems():
       assets_env.register(name, bundle)

    app.assets_env = assets_env
Пример #3
0
def init_app(app):
    here, f = os.path.split(os.path.abspath(__file__))

    # configure assets
    assets = Environment(app)
    assets.versions = 'hash'
    assets.directory = '%s/src' % here
    if app.debug == False:
        assets.auto_build = False

    # i have no idea why, but an arbitrary
    # second path segment is required here
    assets.url = '/static/turnip'

    # load asset bundles
    bundles = YAMLLoader("%s/src/assets.yaml" % here).load_bundles()
    [assets.register(name, bundle) for name, bundle in bundles.iteritems()]
Пример #4
0
 def from_yaml(self, path):
     """Register bundles from a YAML configuration file"""
     bundles = YAMLLoader(path).load_bundles()
     [self.register(name, bundle) for name, bundle in bundles.iteritems()]
Пример #5
0
 def from_yaml(self, path):
     """Register bundles from a YAML configuration file"""
     bundles = YAMLLoader(path).load_bundles()
     [self.register(name, bundle) for name, bundle in bundles.iteritems()]
Пример #6
0
def make_app(env="dev"):
    """
    This is still needlessly complicated.

    Returns a Flask WSGI instance.
    """
    debug = env == "dev"

    url_root = dict(
        dev="/",
        build="/dist/",
        test="/dist/",
        prod="/"
    )[env]

    app_home = os.path.dirname(__file__)

    cfg = dict(
        dev=dict(
            static_url_path="/static",
            template_folder="./templates",
            static_folder=opa(opj(app_home, "static"))
        ),
        build=dict(
            static_url_path="/",
            template_folder="./templates",
            static_folder=opa(opj(app_home, "static"))
        ),
        test=dict(
            static_url_path="/dist",
            template_folder="../dist",
            static_folder=opa(opj(app_home, "..", "dist"))
        ),
        prod=dict(
            static_url_path="/static",
            template_folder="./templates",
            static_folder=opa(opj(app_home, "static"))
        )
    )[env]

    app = Flask(__name__, **cfg)

    app.config.update(dict(
        CSRF_ENABLED=debug,
        SECRET_KEY=os.environ.get("FLASK_SECRET_KEY", "totally-insecure"),
        DEBUG=debug,
        ASSETS_DEBUG=debug,
        BOOTSTRAP_JQUERY_VERSION=None
    ))

    Bootstrap(app)

    def font_stuff(url):
        """
        Some font URL rewriting
        """
        repl = "./lib/awesome/font/"
        if env == "build":
            repl = "./font/"
        return url.replace("../font/", repl)

    fix_font_css = CSSRewrite(replace=font_stuff)

    assets = Environment(app)

    bundles = YAMLLoader(os.path.join(app_home, 'assets.yaml')).load_bundles()

    for to_fix in ["prod", "build"]:
        bundles["css-%s" % to_fix].filters.insert(0, fix_font_css)

    for name, bundle in bundles.iteritems():
        assets.register(name, bundle)


    @app.route(url_root)
    def index():
        kwargs = {
            "gh_client_id": os.environ.get("GITHUB_CLIENT_ID", 
                "deadbeef")
        }

        return render_template("index.html", env=env, **kwargs)


    @app.route("/login")
    def login(code=None):
        return render_template("login.html")


    @app.route("/oauth")
    def oauth():
        oauth_args = dict(
            code=request.args.get("code", ""),
            state=request.args.get("state", ""),
            client_id=os.environ["GITHUB_CLIENT_ID"],
            client_secret=os.environ["GITHUB_CLIENT_SECRET"]
        )
        
        req = requests.post(
            "https://github.com/login/oauth/access_token",
            data=oauth_args
        )
        
        query = urlparse.parse_qs(req.content)
        
        return query["access_token"][0]

    return app