Пример #1
0
    def install(cls, app):
        """Install the extension into the application."""
        Environment.resolver_class = InvenioResolver
        env = Environment(app)
        env.url = "{0}/{1}/".format(app.static_url_path,
                                    app.config["ASSETS_BUNDLES_DIR"])
        env.directory = os.path.join(app.static_folder,
                                     app.config["ASSETS_BUNDLES_DIR"])
        env.append_path(app.static_folder)
        env.auto_build = app.config.get("ASSETS_AUTO_BUILD", True)

        # The filters less and requirejs don't have the same behaviour by
        # default. Make sure we are respecting that.
        app.config.setdefault("LESS_RUN_IN_DEBUG", True)
        app.config.setdefault("REQUIREJS_RUN_IN_DEBUG", False)
        # Fixing some paths as we forced the output directory with the
        # .directory
        app.config.setdefault("REQUIREJS_BASEURL", app.static_folder)
        requirejs_config = os.path.join(env.directory,
                                        app.config["REQUIREJS_CONFIG"])
        if not os.path.exists(requirejs_config):
            app.config["REQUIREJS_CONFIG"] = os.path.relpath(
                os.path.join(app.static_folder,
                             app.config["REQUIREJS_CONFIG"]),
                env.directory)

        app.jinja_env.add_extension(BundleExtension)
        app.context_processor(BundleExtension.inject)
Пример #2
0
def assets_env(app):
    env = Environment(app)
    env.url = "/static"
    # App Engine doesn't support automatic rebuilding.
    env.auto_build = False
    # This file needs to be shipped with your code.
    env.manifest = ('file:' + os.path.join(root_dir, 'webassets.manifest'))
    env.versions = 'hash:32'
    # create static bundles
    env.register('new_js',
                 'js/hiro.js',
                 filters='yui_js',
                 output="javascript/hiro.%(version)s.js")
    env.register('hoc_js',
                 'js/hoc.js',
                 filters='yui_js',
                 output="javascript/hoc.%(version)s.js")
    env.register('new_css',
                 'css/hiro.css',
                 filters='cssmin',
                 output="stylesheets/hiro.%(version)s.css")
    env.register('hoc_css',
                 'css/hoc.css',
                 filters='cssmin',
                 output="stylesheets/hoc.%(version)s.css")
    env.debug = app.config['DEBUG']
    return env
Пример #3
0
def configure_extensions(app):
  # Flask-PyMongo
  mongo.init_app(app)

  # Flask-OAuthlib
  oauth.init_app(app)

  # Flask-Login
  @login_manager.user_loader
  def load_user(user_id):
    """Returns the currently active user as an object.

    Since this app doesn't handle passwords etc. there isn't as much
    incentive to keep pinging the database for every request protected
    by 'login_required'.

    Instead I set the expiration for the session cookie to expire at
    regular intervals.
    """
    # 1. Retrive user data from the session
    # 2. Create new User object based of that (potential) data
    data = {
      'user_id': session.get('user_id'),
      'name': session.get('name'),
      'email': session.get('email')
    }

    if data.get('email'):
      user = User(**data)
    else:
      user = None

    return user

  login_manager.init_app(app)

  # Flask-Assets
  # Doing setup here to avoid RuntimeError: assets instance not bound...
  assets = Environment(app)
  assets.auto_build = app.config.get('DEBUG')
  assets.load_path = [
    os.path.join(os.path.dirname(__file__), 'scss'),
    os.path.join(os.path.dirname(__file__), 'coffee'),
    os.path.join(os.path.dirname(__file__), 'handlebars'),
    os.path.join(os.path.dirname(__file__), 'vendor'),
  ]
  assets.url = app.static_url_path

  assets.register('js_all', js)
  assets.register('js_app', js_app)
  assets.register('ember_templates', ember_templates)
  assets.register('scss_all', scss)

  # New Relic Python Agent
  newrelic.agent.initialize('newrelic.ini')
Пример #4
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
Пример #5
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()]
Пример #6
0
def init(app):
    """
    Bundle projects assets

    :type app: flask.Flask
    """
    assets = Environment(app)
    assets.auto_build = app.config.get('ASSETS_AUTO_BUILD', True)
    files_to_watch = []

    if 'COLLECT_STATIC_ROOT' in app.config:
        assets.cache = app.config['COLLECT_STATIC_ROOT']
        collect = Collect()
        collect.init_app(app)
        collect.collect()
        app.static_folder = app.config['COLLECT_STATIC_ROOT']

    if 'JS_ASSETS' in app.config and len(app.config['JS_ASSETS']) > 0:
        files_to_watch += [
            os.path.join(app.static_folder, js_file)
            for js_file in app.config['JS_ASSETS']
        ]

        js = Bundle(*app.config['JS_ASSETS'],
                    output=app.config['JS_ASSETS_OUTPUT'],
                    filters=app.config['JS_ASSETS_FILTERS'])
        assets.register('js_all', js)

    if 'CSS_ASSETS' in app.config and len(app.config['CSS_ASSETS']) > 0:
        files_to_watch += [
            os.path.join(app.static_folder, css_file)
            for css_file in app.config['CSS_ASSETS']
        ]

        css = Bundle(*app.config['CSS_ASSETS'],
                     output=app.config['CSS_ASSETS_OUTPUT'],
                     filters=app.config['CSS_ASSETS_FILTERS'])
        assets.register('css_all', css)

    app.assets = assets
    app._base_files_to_watch = files_to_watch
Пример #7
0
def register_assets(app, debug=False):
    """We add the app's root path to assets search path. However, the
    output directory is relative to `app.static_folder`.
    """
    assets = Environment(app)
    assets.debug = debug
    assets.auto_build = True
    assets.manifest = 'file'
    assets.append_path(app.root_path)

    site_js = Bundle(
        'static/app.js',
        filters=('uglifyjs',),
        output='js/bundle.js'
    )
    assets.register('site_js', site_js)

    site_css = Bundle(
        'static/style.css',
        filters=('cssmin',),
        output='css/bundle.css'
    )
    assets.register('site_css', site_css)
Пример #8
0
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script import Manager
from flask.ext.sqlalchemy import SQLAlchemy
from webassets.loaders import PythonLoader

import project.asset_bundles

app = Flask(__name__)
app.config.from_object('project.config')

db = SQLAlchemy(app)
migrate = Migrate(app, db)

import routes
# from models import *

assets = Environment(app)
assets.versions = "hash:32"
assets.auto_build = app.config["SERVER_ENV"] == 'development'
assets.debug = False
bundles = PythonLoader(project.asset_bundles).load_bundles()
for name, bundle in bundles.iteritems():
    assets.register(name, bundle)

manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command('assets', ManageAssets)

if __name__ == '__main__':
    manager.run()
Пример #9
0
import logging
from flask import Flask
from flask.ext.assets import Environment
from flask.ext.cache import Cache
from flask_frozen import Freezer

from doubleoffshore import default_settings

logging.basicConfig(level=logging.DEBUG)

# specific loggers
# logging.getLogger('requests').setLevel(logging.WARNING)
# logging.getLogger('urllib3').setLevel(logging.WARNING)

app = Flask(__name__)
app.config.from_object(default_settings)
assets = Environment(app)
cache = Cache(app)
freezer = Freezer(app)

if not app.debug:
    assets.auto_build = False
    assets.manifest = 'file'
Пример #10
0
__author__ = "sjlu"

from flask import Flask, render_template
from flask.ext.assets import Environment as Assets, Bundle

# Initialize
app = Flask(__name__)

# Assets
assets = Assets(app)
assets.auto_build = True

# Define our routes.
@app.route("/")
def index():
  return render_template('homepage.html')

# Execute
if __name__ == "__main__":
  app.run(debug=True)
Пример #11
0
    qgic
    ~~~~

    Website for the Queen's Global Innovation Conference (2013)

    blah blah blah
"""

from flask import Flask, render_template, url_for
from flask.ext.assets import Environment, Bundle

app = Flask(__name__)
assets = Environment(app)

assets.url = '/static'  # HACK HACK HACK
assets.auto_build = False
assets.debug = False
assets.manifest = "file:assets-manifest"

assets.register('css_screen', 'sass/screen.sass',
                filters='compass', output='css/screen.%(version)s.css')
assets.register('css_print', 'sass/print.sass',
                filters='compass', output='css/print.%(version)s.css')

assets.register('js', 'coffee/main.coffee',
                filters='coffeescript', output='js/main.%(version)s.js')


@app.route('/')
def home():
    team_members = [
Пример #12
0
# setup logging
@app.before_first_request
def setup_logging():
    if not app.debug:
        app.logger.addHandler(logging.StreamHandler())
        app.logger.setLevel(logging.INFO)

# Getting the supported languages from SUMO
LANGUAGES = requests.get((app.config['SUMO_URL'] +
                         'offline/get-languages')).json()
LANGUAGES = json.dumps(LANGUAGES['languages'])

# Sets up the assets
assets = Environment(app)
assets.auto_build = app.debug
assets.debug = app.debug
# we don't need this as manifest.appcache will change
assets.url_expire = False

css = Bundle(
    'css/develop/gaia.css',
    'css/develop/doc.css',
    'css/develop/installer.css',
    'css/develop/nav.css',
    'css/develop/app.css',
    filters='cssmin',
    output='css/app.min.css'
)
assets.register('css_all', css)
Пример #13
0
    'db1': app.config['SQLALCHEMY_DATABASE_URI'],
}

root_path = os.path.abspath("%s/.." % os.path.dirname(__file__))
tmp_path = "%s/tmp" % root_path

os.environ['BOTO_ENDPOINTS'] = os.path.abspath(
    "%s/config/boto_endpoints.json" % root_path)

###################
# ASSETS SETTINGS #
###################
assets = Environment(app)
loader = YAMLLoader("%s/assets/assets.yml" % root_path)
bundles = loader.load_bundles()
assets.register(bundles)

assets.set_directory("%s/public" % root_path)
assets.load_path.append('./assets/')
assets.url = '/'
assets.manifest = "json:%s/public/gen/webassets-manifest.json" % root_path

development_mode = not environment.equals('production')
assets.cache = development_mode
assets.auto_build = development_mode
assets.debug = development_mode

# MD Feb-2015 Allow created files to be group writeable. This will fix some problems with files created in the /tmp
# directory that are accessed both by Celery and duesty scripts. The /tmp directory should have set "chmod g+s tmp"
os.umask(0o002)
Пример #14
0
"""Auto add role and creation time to new users"""
@user_registered.connect_via(app)
def user_registered_sighandler(app, user, confirm_token):
    default_role = user_datastore.find_role('user')
    user_datastore.add_role_to_user(user, default_role)
    user.created_at = datetime.utcnow()
    db.session.commit()

"""Add various extensions"""
mail = Mail(app)
assets = Environment(app)
compress = Compress(app)

"""If we are in prod, don't autobuild"""
assets.auto_build = app.config['ASSETS_AUTO_BUILD']
assets.manifest = 'file'

"""Configure blueprints in views."""
for blueprint in DEFAULT_BLUEPRINTS:
    app.register_blueprint(blueprint)

def configure_template_filters(app):

    @app.template_filter()
    def time_ago(value):
        return pretty_date(value)

    @app.template_filter()
    def time(value):
        return local_time(value)
Пример #15
0
# setup logging
@app.before_first_request
def setup_logging():
    if not app.debug:
        app.logger.addHandler(logging.StreamHandler())
        app.logger.setLevel(logging.INFO)


# Getting the supported languages from SUMO
LANGUAGES = requests.get(
    (app.config['SUMO_URL'] + 'offline/get-languages')).json()
LANGUAGES = json.dumps(LANGUAGES['languages'])

# Sets up the assets
assets = Environment(app)
assets.auto_build = app.debug
assets.debug = app.debug
# we don't need this as manifest.appcache will change
assets.url_expire = False

css = Bundle('css/develop/gaia.css',
             'css/develop/doc.css',
             'css/develop/installer.css',
             'css/develop/nav.css',
             'css/develop/app.css',
             filters='cssmin',
             output='css/app.min.css')
assets.register('css_all', css)

scripts = ['js/develop/app.js']
for root, subdir, fnames in os.walk('static/js/develop'):
def init(app):
  assets = Environment(app)
  if app.config.get('CARAVELA_ENV') == 'production':
    assets.debug=False
    assets.auto_build=False
  #else:
  #  assets.debug = True

  assets.url = app.static_url_path

  assets.register('common.js', Bundle(
    'lib/jquery-1.9.1.min.js',
    'lib/bootstrap.js',
    'lib/modernizr-2.6.1.min.js',
    'lib/underscore-min.js',
    'lib/less-1.3.0.min.js',

    'lib/jquery-ui-1.10.1.custom.min.js',
    'lib/jquery.mousewheel.js',

    'lib/handlebars-1.0.0.js',
    'lib/ember-1.0.0.js',
    'lib/ember-data.js',
    'lib/ember-table.js',


    'lib/d3.v3.min.js',
    'lib/vega.js',
    'lib/d3.geo.projection.min.js',


    'lib/codemirror.js',

    'lib/mode/javascript/javascript.js',


    'js/app.js',
    'js/routes/*.js',
    'js/controllers/*.js',
    'js/models/*.js',
    'js/views/*.js',
    
    #filters='rjsmin',
    output='assets/common.js'
  ))

  sass = Bundle(
    '**/*.sass',
    filters='compass', 
    output='assets/sass.css'
  )

  assets.register('sass.css', sass)

  assets.register('common.css', Bundle(
    sass,
    'css/bootstrap.min.css',
    'lib/codemirror.css',
    'css/persona-buttons.css',
    'css/style.css',

    output='assets/common.css'
  ))

  assets.config.update(dict(
    jst_compiler = "Em.Handlebars.compile",
    jst_namespace= "Em.TEMPLATES"
  ))

  assets.register('app.handlebars', Bundle(
    'templates/*.handlebars',
    'templates/**/*.handlebars',
    filters='jst',

    output='assets/app.handlebars'
  ))