def env(): e = Environment(publicRoot='/pack', manifest={ 'a': 'b', 'foo.js': 'foo.123.js', 'bar.test': 'bar.123.test' }) return e
def rendering_env(): e = Environment(publicRoot='/pack', useDefaultRenderByExt=True, manifest={ 'a': 'b', 'foo.js': 'foo.123.js', 'bar.test': 'bar.123.test' }) return e
def includeme(config): registry_settings = config.registry.settings settings = webpack_settings_from_settings(registry_settings) registry_settings['webpack'] = settings # Load the webpack environment environment = Environment(**settings) config.registry.registerUtility(environment, IWebpackEnvironment) # Add callbacks config.add_directive('get_webpack_environment', get_webpack_environment) config.add_request_method(get_webpack_environment, 'webpack_environment', reify=True) # Expose a webpack filter to jinja2 environment webpack_filter = WebpackFilter(environment) try: jinja2_env = config.get_jinja2_environment() except AttributeError: raise Jinja2EnvironmentMissingException( 'Unable to find jinja2 environment. ' 'Try config.commit() after including jinja2') jinja2_env.filters['webpack'] = webpack_filter
def test_identify_error_on_invalid_reference(): env = Environment(errorOnInvalidReference=True, manifest=None) with pytest.raises(AssetNotFoundException): env.identify_assetspec('test')
def test_identify_invalid_asset(): env = Environment(errorOnInvalidReference=False, manifest=None) assert env.identify_assetspec('baz') is None
def test_invalid_error(): env = Environment(manifest=None, errorOnInvalidReference=True) f = WebpackFilter(env) with pytest.raises(AssetNotFoundException): f('a')
def test_invalid_empty(): env = Environment(manifest=None, errorOnInvalidReference=False) f = WebpackFilter(env) assert f('a') is None
def test_basename_lookup(): env = Environment(manifest={'a': 'b'}) f = WebpackFilter(env) assert f('/path/to/a') == '/static/pack/b'
def test_simple_lookup(): env = Environment(manifest={'a': 'b'}) f = WebpackFilter(env) assert f assert f('a') == '/static/pack/b'
def test_slash_renderer(): env = Environment(publicRoot='/', manifest={'a': 'b'}) a = env.identify_assetspec('a') assert env.render_asset(a) == '/b'