当前位置: 首页>>代码示例>>Python>>正文


Python Environment.from_yaml方法代码示例

本文整理汇总了Python中flask_assets.Environment.from_yaml方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.from_yaml方法的具体用法?Python Environment.from_yaml怎么用?Python Environment.from_yaml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_assets.Environment的用法示例。


在下文中一共展示了Environment.from_yaml方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup

# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import from_yaml [as 别名]
class TestEnv:

    def setup(self):
        self.app = Flask(__name__)
        self.env = Environment(self.app)
        self.env.debug = True
        self.env.register('test', 'file1', 'file2')

    def test_tag_available(self):
        """Jinja tag has been made available.
        """
        t = self.app.jinja_env.from_string('{% assets "test" %}{{ASSET_URL}};{% endassets %}')
        assert t.render() == '/static/file1;/static/file2;'

    def test_from_yaml(self):
        """YAML configuration gets loaded
        """
        f = open('test.yaml', 'w')
        f.write("""
        yamltest:
            contents:
                - yamlfile1
                - yamlfile2
        """)
        f.close()

        self.env.from_yaml('test.yaml')

        t = self.app.jinja_env.from_string('{% assets "yamltest" %}{{ASSET_URL}};{% endassets %}')
        assert t.render() == '/static/yamlfile1;/static/yamlfile2;'

        os.remove('test.yaml')

    def test_from_python_module(self):
        """Python configuration module gets loaded
        """
        import types
        module = types.ModuleType('test')
        module.pytest = Bundle('pyfile1', 'pyfile2')

        self.env.from_module(module)

        t = self.app.jinja_env.from_string('{% assets "pytest" %}{{ASSET_URL}};{% endassets %}')
        assert t.render() == '/static/pyfile1;/static/pyfile2;'
开发者ID:adamchainz,项目名称:flask-assets,代码行数:46,代码来源:test_env.py

示例2: Manager

# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import from_yaml [as 别名]
manager = Manager(app)
manager.add_command("db", MigrateCommand)

# add commands to manage chart cache
from whiskyton.managers.charts import ChartsCommand
manager.add_command("charts", ChartsCommand)

# add command to save analytics data via FTP
from whiskyton.managers.anaytics import AnalyticsCommand
manager.add_command("analytics", AnalyticsCommand)

# enable gzip compression
Compress(app)

# scss
assets = Environment(app)
assets.load_path = [app.config["BASEDIR"].child("whiskyton")]
assets.from_yaml(app.config["BASEDIR"].child("whiskyton", "assets.yaml"))

# log errors
log_handler = StreamHandler()
app.logger.setLevel(logging.DEBUG)
app.logger.addHandler(log_handler)

# register blueprints
from whiskyton.blueprints.site import site
from whiskyton.blueprints.files import files
app.register_blueprint(site)
app.register_blueprint(files)

开发者ID:cuducos,项目名称:whiskyton,代码行数:31,代码来源:__init__.py

示例3: create_app

# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import from_yaml [as 别名]
def create_app(config=None):
    """ config should be a python file """
    from pathlib import Path

    from flask import (Flask,
            current_app,
            g,
            session,
            url_for,
            render_template)

    from flask_sqlalchemy import SQLAlchemy
    from flask_security import (Security, SQLAlchemyUserDatastore)

    from flask_wtf.csrf import CsrfProtect

    from flask_assets import (Environment, Bundle)

    from .app_setup import (init_db, setup_dirs)
    from .core import (db, load_blueprints, setup_logger)
    from .lib.template_filters import (
        fmt_datetime,
        none_as_str,
        next_page_url,
        prev_page_url,
        get_page_url,
        get_images)

    from .models.user import (User, Role, user_datastore)

    from .Admin import (index, series, images, texts, contact)
    from .Public import (index, contact, texts)
    from .Security import user

    app = Flask(__name__.split('.')[0], instance_relative_config=True)

    app.config.from_object('config')
    app.config.from_pyfile('config.py')

    if config is not None:
        app.config.from_pyfile(config)
        setup_logger(app)
        app.logger.info('Started with config from: {}'.format(config))
    else:
        setup_logger(app)
        app.logger.info('Started App')

    # Flask.sqlalchemy
    db.init_app(app)

    load_blueprints(app)

    # make sure db tables and required directories exist
    before_first_request_funcs = [setup_dirs(app),
                                  init_db(app)]

    #Security
    csrf = CsrfProtect()
    csrf.init_app(app)
    security = Security()
    security.init_app(app, user_datastore, register_blueprint=False)

    # Assets
    assets = Environment(app=app)
    assets.from_yaml('assets.yml')

    # template filters
    app.add_template_filter(fmt_datetime)
    app.add_template_filter(none_as_str)
    app.add_template_filter(next_page_url)
    app.add_template_filter(prev_page_url)
    app.add_template_filter(get_page_url)
    app.add_template_filter(get_images)

    return app
开发者ID:GregoryVigoTorres,项目名称:PaintingsApp,代码行数:77,代码来源:App.py

示例4: Environment

# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import from_yaml [as 别名]
from flask import current_app
from flask_assets import Environment
from flask_sqlalchemy import SQLAlchemy

from .cache import Cache
from .gzip import Gzip


assets_env = Environment()
cache = Cache()
db = SQLAlchemy()
gzip = Gzip()


def get_queue():
    try:
        from flask import _app_ctx_stack as stack
    except ImportError:
        from flask import _request_ctx_stack as stack
    ctx = stack.top
    if ctx is not None:
        if not hasattr(ctx, 'queue'):
            import rq
            rq.connections.use_connection(
                current_app.extensions['cache'][cache]._client)
            ctx.queue = rq.Queue()
        return ctx.queue


assets_env.from_yaml(join(dirname(__file__), 'static/assets.yaml'))
开发者ID:clee704,项目名称:NaverWebtoonFeeds,代码行数:32,代码来源:ext.py


注:本文中的flask_assets.Environment.from_yaml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。