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("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)
def init(app=None): """Define asset files.""" app = app or Flask(__name__) with app.app_context(): env = Environment(app) env.load_path = [Path(__file__).parent / "static"] env.auto_build = False env.manifest = "file" css_font = Bundle("./font/Inter/stylesheet.css", filters="rcssmin", output="css/inter.min.css") env.register("css_font", css_font) css_site = Bundle("./css/site.css", filters="libsass,rcssmin", output="css/site.min.css") env.register("css_site", css_site) js_site = Bundle("./js/site.js", filters="jsmin", output="js/site.min.js") env.register("js_site", js_site) return [css_font, css_site, js_site]
def init(app=None): app = app or Flask(__name__) with app.app_context(): env = Environment(app) env.directory = 'aqandu/static' env.load_path = [path.join(path.dirname(__file__), 'aqandu/static')] # env.append_path('assets') # env.set_directory(env_directory) # App Engine doesn't support automatic rebuilding. env.auto_build = False env.versions = 'hash' # This file needs to be shipped with your code. env.manifest = 'file' all_css = Bundle('css/airu.css', 'css/visualization.css', 'css/ie10-viewport-bug-workaround.css', filters='cssmin', output='css/all_css.%(version)s.css') env.register('css', all_css) all_js = Bundle('js/db_data.js', 'js/map_reconfigure.js', filters='jsmin', output='js/all_js.%(version)s.js') env.register('js', all_js) # bundles = [css, js] bundles = [all_css, all_js] # bundles = [all_css] return bundles
def create_app(): app = Flask(__name__,\ static_folder="static/",\ template_folder="templates/",\ static_url_path="/static") # set config # app_settings = os.getenv('APP_SETTINGS', 'app.config.DevelopmentConfig') app.config.from_object('config') # set up extensions db.init_app(app) app.register_blueprint(charts_blueprint) app.register_blueprint(webapi) # Scss assets = Environment(app) assets.versions = 'timestamp' assets.url_expire = True assets.manifest = 'file:/tmp/manifest.to-be-deployed' # explict filename assets.cache = False assets.auto_build = True assets.url = app.static_url_path scss = Bundle('scss/__main__.scss', filters='pyscss', output='css/main.css', depends=['scss/*.scss']) assets.register('scss_all', scss) assets.debug = False app.config['ASSETS_DEBUG'] = False return app
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)
def create_app(): app = Flask(__name__,\ static_folder="static/",\ template_folder="templates/",\ static_url_path="/static") set_config(app) # set up extensions cache.init_app(app) db.init_app(app) datepicker(app) mail.init_app(app) # blueprints app.register_blueprint(auth) app.register_blueprint(admin_blueprint) app.register_blueprint(charts_blueprint) app.register_blueprint(webapi) app.register_blueprint(monitor_blueprint) # login_manager login_manager = LoginManager() login_manager.login_view = 'charts.now' login_manager.init_app(app) from .models import User @login_manager.user_loader def load_user(user_id): # since the user_id is just the primary key of our user table, use it in the query for the user return User.query.get(int(user_id)) # form csrf csrf.init_app(app) # Scss assets = Environment(app) assets.versions = 'timestamp' assets.url_expire = True assets.manifest = 'file:/tmp/manifest.to-be-deployed' # explict filename assets.cache = False assets.auto_build = True assets.url = app.static_url_path scss = Bundle('scss/__main__.scss', filters='pyscss', output='css/main.css', depends=['scss/*.scss']) assets.register('scss_all', scss) assets.debug = False app.config['ASSETS_DEBUG'] = False with app.app_context(): init_db_admin_config() toolbar = DebugToolbarExtension(app) return (app)
def register_assets(app): assets = Environment(app) assets.debug = app.debug assets.auto_build = True assets.url = app.static_url_path css_all = Bundle(*CSS_ASSETS, filters='cssmin', output='css/bundle.min.css') assets.register('css_all', css_all) app.logger.info("Registered assets...") return assets
def init_app(app, allow_auto_build=True): assets = Environment(app) # on google app engine put manifest file beside code # static folders are stored separately and there is no access to them in production folder = os.path.abspath(os.path.dirname(__file__)) if "APPENGINE_RUNTIME" in os.environ else "" assets.directory = os.path.join(app.static_folder, "compressed") assets.manifest = "json:{}/manifest.json".format(assets.directory) assets.url = app.static_url_path + "/compressed" compress = not app.debug # and False assets.debug = not compress assets.auto_build = compress and allow_auto_build assets.register('js', Bundle(*JS, filters='yui_js', output='script.%(version)s.js')) assets.register('css', Bundle(*CSS, filters='yui_css', output='style.%(version)s.css'))
def init_assets(app): with app.app_context(): env = Environment(app) env.load_path = [path.join(path.dirname(__file__), '..', 'static')] # App Enging doesn't support automatic building # so only auto build if in debug mode env.auto_build = app.debug app.logger.info('auto_build set to {}'.format( env.auto_build )) # Make sure this file is shipped env.manifest = 'file' bundles = { 'cv_js': Bundle( 'js/common.js', 'js/cv.js', output='gen/cv.js'), 'cv_css': Bundle( 'css/bootstrap-extensions.css', 'css/common.css', 'css/cv.css', output='gen/cv.css'), 'aboutMe_js': Bundle( 'js/common.js', output='gen/aboutMe.js'), 'aboutMe_css': Bundle( 'css/bootstrap-extensions.css', 'css/common.css', 'css/aboutMe.css', output='gen/aboutMe.css'), 'index_js': Bundle( 'js/common.js', output='gen/index.js'), 'index_css': Bundle( 'css/bootstrap-extensions.css', 'css/common.css', 'css/index.css', output='gen/index.css'), } env.register(bundles) return bundles
def init_app(): app = Flask(__name__, instance_relative_config=False) app.config.from_object("config") app.config["FLATPAGES_HTML_RENDERER"] = my_markdown assets = Environment() assets.init_app(app) with app.app_context(): assets.auto_build = True from . import routes from .plotlydash.dashboard import init_dashboard app = init_dashboard(app, routes.pages) return app
def init(app=None): app = app or Flask(__name__) bundles = [] with app.app_context(): env = Environment(app) env.load_path = [ASSETS_DIR] env.set_directory(STATIC_DIR) # App Engine doesn't support automatic rebuilding. env.auto_build = False # This file needs to be shipped with your code. env.manifest = 'file' bundles.extend(_add_base_bundle(env)) bundles.extend(_add_home_bundle(env)) bundles.extend(_add_ajaxy_bundle(env)) return bundles
def register_assets(app): assets = Environment(app) assets.debug = app.debug assets.auto_build = True assets.url = app.static_url_path css_blog = Bundle(*BLOG_ASSETS, filters='cssmin', output='css/blog.min.css') css_welcome = Bundle(*INDEX_ASSETS, filters='cssmin', output='css/welcome.min.css') js_all = Bundle(*JS_ASSETS, filters='rjsmin', output='js/all.min.js') assets.register('css_blog', css_blog) assets.register('css_welcome', css_welcome) assets.register('js_all', js_all) app.logger.info("Registered assets...") return assets
def init(app=None): app = app or Flask(__name__) with app.app_context(): env = Environment(app) env.load_path = [path.join(path.dirname(__file__), 'assets')] env.url = app.static_url_path env.directory = app.static_folder env.auto_build = app.debug env.manifest = 'file' scss = Bundle('stylesheet.scss', filters='pyscss', output='stylesheet.css') env.register('scss_all', scss) bundles = [scss] return bundles
def init(app=None): app = app or Flask(__name__) with app.app_context(): env = Environment(app) env.load_path = [path.join(path.dirname(__file__), 'assets')] # env.append_path('assets') # env.set_directory(env_directory) # App Engine doesn't support automatic rebuilding. env.auto_build = False # This file needs to be shipped with your code. env.manifest = 'file' css = Bundle("main.css", filters="cssmin", output="main.css") env.register('css', css) js = Bundle("main.js", filters="jsmin", output="main.js") env.register('js', js) bundles = [css, js] return bundles
def init(app) -> None: """ Bundle projects assets. :param app: Main application instance :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'] for key in ['js', 'css']: assets_key = '%s_ASSETS' % key.upper() build_files = app.config[assets_key] files_to_watch.extend(_get_files_for_settings(app, assets_key)) bundle = Bundle(*build_files, output=app.config['%s_OUTPUT' % assets_key], filters=app.config['%s_FILTERS' % assets_key] ) assets.register('%s_all' % key, bundle) app.logger.debug('Bundling files: %s%s', os.linesep, os.linesep.join(build_files)) app.assets = assets app._base_files_to_watch = files_to_watch app.logger.info('Base assets are collected successfully.')
def init_app(app): assets = Environment(app) styles = Bundle( 'main.scss', filters='scss', output='main.css', depends='**/*.scss' ) scripts = Bundle( '*.js', filters=('slimit'), output='main.js' ) assets.register('styles', styles) assets.register('scripts', scripts) # TODO: Move this config to an environment file assets.load_path = ['service/design/styles', 'service/design/scripts'] assets.config['SASS_STYLE'] = 'compressed' assets.url_expire = False assets.auto_build = True
def init(app=None): app = app or Flask(__name__) with app.app_context(): assets = Environment(app) assets.auto_build = False assets.manifest = 'file' css = Bundle( 'css/style.css', 'js/libs/prettify/*.css', filters='cssmin', output='css/styles.min.css', ) assets.register('css', css) js = Bundle( 'js/app.js', 'js/libs/prettify/*.js', 'js/libs/jquery-1.7.1.min.js', filters='jsmin', output='js/main.min.js' ) assets.register('js', js) bundles = [css, js] return bundles
from spaceship import app from flask_assets import Environment, Bundle assets = Environment(app) if app.config['IN_BUILD']: assets.auto_build = False assets.cache = False assets.manifest = 'file' js = Bundle( 'edit.js', 'copy.js', 'prevent-invalid-form-submit.js', 'wip-overlay.js', 'add_csrf_token.js', output='gen/all.%(version)s.js') assets.register('js_all', js) css = Bundle('spaceship.css', 'wip-overlay.css', output='gen/all.%(version)s.css') assets.register('css_all', css)
REDIS_PASS = os.environ.get("REDIS_PASS") REDIS_SERVER = os.environ.get("REDIS_SERVER") is_local = STATIC_LOCATION == "local" use_cdn = not is_local app.config.update(SECRET_KEY=secret_key, CDN_DOMAIN="static.no8.am", CDN_HTTPS=True, CDN_TIMESTAMP=False, BROWSERIFY_BIN='./node_modules/.bin/browserifyinc', CLEANCSS_BIN='./node_modules/.bin/cleancss', CLEANCSS_EXTRA_ARGS=['--skip-rebase'], UGLIFYJS_BIN='./node_modules/.bin/uglifyjs', UGLIFYJS_EXTRA_ARGS=['-c', '-m'], FLASK_ASSETS_USE_CDN=use_cdn, CDN_DEBUG=is_local) assets = Environment(app) assets.auto_build = is_local CDN(app) from no8am.metadata import DEPARTMENT_LIST, CCC_LIST, CREDIT_LIST from no8am.cache import course_data_get, course_data_set from no8am.database import store_link, get_link, generate_short_link from no8am.scraper import Department, CreditOrCCC, find_course_in_department, fetch_section_details, get_current_term, get_all_courses from no8am.utility import generate_course_descriptions from no8am.minify import update_static_files, generate_metadata, JS_OUTPUT_FILENAME from no8am.utility import is_valid_department, is_valid_ccc_req import no8am.views
def create_app(config_filename="config"): """Flask application factory. This is the flask application factory for this project. It loads the other submodules used to runs the collectives website. It also creates the blueprins and init apps. :param config_filename: name of the application config file. :type config_filename: string :return: A flask application for collectives :rtype: :py:class:`flask.Flask` """ app = Flask(__name__, instance_relative_config=True) app.wsgi_app = ReverseProxied(app.wsgi_app) # Config options - Make sure you created a 'config.py' file. app.config.from_object(config_filename) app.config.from_pyfile("config.py") # To get one variable, tape app.config['MY_VARIABLE'] fileConfig(app.config["LOGGING_CONFIGURATION"], disable_existing_loggers=False) # Initialize plugins models.db.init_app(app) auth.login_manager.init_app(app) # app is a Flask object api.marshmallow.init_app(app) profile.images.init_app(app) extranet.api.init_app(app) payline.api.init_app(app) app.context_processor(jinja.helpers_processor) _migrate = Migrate(app, models.db) with app.app_context(): # Initialize asset compilation assets = Environment(app) filters = "libsass" if app.config["ENV"] == "production": filters = "libsass, cssmin" assets.auto_build = False assets.debug = False scss = Bundle( "css/all.scss", filters=filters, depends=("/static/css/**/*.scss"), output="dist/css/all.css", ) assets.register("scss_all", scss) scss.build() # Register blueprints app.register_blueprint(root.blueprint) app.register_blueprint(profile.blueprint) app.register_blueprint(api.blueprint) app.register_blueprint(administration.blueprint) app.register_blueprint(auth.blueprint) app.register_blueprint(event.blueprint) app.register_blueprint(payment.blueprint) app.register_blueprint(technician.blueprint) app.register_blueprint(activity_supervison.blueprint) # Error handling app.register_error_handler(werkzeug.exceptions.NotFound, error.not_found) app.register_error_handler(werkzeug.exceptions.InternalServerError, error.server_error) forms.configure_forms(app) forms.csrf.init_app(app) # Initialize DB # models.db.create_all() populate_db(app) if app.config["STATISTICS_ENABLED"]: Statistics( app, models.db, models.Request, access.technician_required_f, disable_f=statistics.disable_f, ) return app
manager = Manager(app) manager.add_command("db", MigrateCommand) # init SeaSurf seasurf = SeaSurf(app) # init flask CDN if config.cdn_assets: CDN(app) # init flask HTMLMIN HTMLMIN(app) # init assets environment assets = Environment(app) assets.auto_build = (config.debug_enabled or config.auto_build) register_filter(BabiliFilter) register_filter(CSSOptimizerFilter) register_asset_bundles(assets) if not assets.auto_build: for bundle in assets: bundle.build() class MiniJSONEncoder(LazyJSONEncoder): """Minify JSON output.""" item_separator = ',' key_separator = ':' def default(self, obj):
data_path = config_frontend['data_path'] cache_path = os.path.join(data_path, 'cache', '.webassets-cache') static_path = os.path.abspath(os.path.join(data_path, 'static')) pathlib.Path(cache_path).mkdir(parents=True, exist_ok=True) assets.cache = os.path.abspath(cache_path) assets.directory = os.path.abspath(static_path) app.static_folder = static_path if os.path.exists(static_path): shutil.rmtree(static_path) shutil.copytree(os.path.join(app.root_path, 'static'), static_path) # Do not automatically build assets in deployment for performance assets.auto_build = False assets.append_path(os.path.join(app.root_path, 'uncompiled_assets')) js_bundle = Bundle('javascript/autocomplete.js', 'javascript/evaluation.js', 'javascript/utils.js', 'javascript/forms.js', 'javascript/articlelist.js', 'javascript/admin.js', 'javascript/semanticScholarPopup.js', filters='jsmin', output='generated/js/base.%(version)s.js') if topic_flag: js_bundle = Bundle('javascript/autocomplete.js', 'javascript/evaluation.js',
'sni/templates/docs/', 'sni/templates/podcast/']), ]) app.jinja_loader = my_loader db = SQLAlchemy(app) Markdown(app, extensions=['footnotes']) pages = FlatPages(app) manager = Manager(app) # Scss assets = Environment(app) assets.url_expire = True assets.auto_build = True assets.append_path('sni/assets') assets.cache = 'sni/assets/.webassets-cache' scss = Bundle('scss/__main__.scss', filters='pyscss', output='css/main.css', depends=['scss/*.scss']) assets.register('scss_all', scss) assets.debug = False app.config['ASSETS_DEBUG'] = False cache = Cache(app, config={'CACHE_TYPE': 'simple'}) if not app.debug: import logging from logging.handlers import RotatingFileHandler
'sni/templates/podcast/' ]), ]) app.jinja_loader = my_loader db = SQLAlchemy(app) Markdown(app, extensions=['footnotes']) pages = FlatPages(app) manager = Manager(app) # Scss assets = Environment(app) assets.url_expire = True assets.auto_build = True assets.append_path('sni/assets') assets.cache = 'sni/assets/.webassets-cache' scss = Bundle('scss/__main__.scss', filters='pyscss', output='css/main.css', depends=['scss/*.scss']) assets.register('scss_all', scss) assets.debug = False app.config['ASSETS_DEBUG'] = False cache = Cache(app, config={'CACHE_TYPE': 'simple'}) if not app.debug: