3
0
Fork 0

feat: add basic support for fanstatic / libcache

This commit is contained in:
Lance Edgar 2024-08-06 22:33:54 -05:00
parent d35e6e71c9
commit 23d227b2c6
16 changed files with 128 additions and 3 deletions

View file

@ -114,6 +114,7 @@ def make_pyramid_config(settings):
:returns: Instance of
:class:`pyramid:pyramid.config.Configurator`.
"""
settings.setdefault('fanstatic.versioning', 'true')
settings.setdefault('mako.directories', ['wuttaweb:templates'])
settings.setdefault('pyramid_deform.template_search_path',
'wuttaweb:templates/deform')
@ -130,6 +131,7 @@ def make_pyramid_config(settings):
pyramid_config.include('pyramid_beaker')
pyramid_config.include('pyramid_deform')
pyramid_config.include('pyramid_fanstatic')
pyramid_config.include('pyramid_mako')
pyramid_config.include('pyramid_tm')

View file

@ -248,40 +248,73 @@ def get_liburl(
version = get_libver(request, key, prefix=prefix)
static = config.get('wuttaweb.static_libcache.module')
if static:
static = importlib.import_module(static)
needed = request.environ['fanstatic.needed']
liburl = needed.library_url(static.libcache) + '/'
# nb. add custom url prefix if needed, e.g. /wutta
if request.script_name:
liburl = request.script_name + liburl
if key == 'buefy':
if static and hasattr(static, 'buefy_js'):
return liburl + static.buefy_js.relpath
return f'https://unpkg.com/buefy@{version}/dist/buefy.min.js'
elif key == 'buefy.css':
if static and hasattr(static, 'buefy_css'):
return liburl + static.buefy_css.relpath
return f'https://unpkg.com/buefy@{version}/dist/buefy.min.css'
elif key == 'vue':
if static and hasattr(static, 'vue_js'):
return liburl + static.vue_js.relpath
return f'https://unpkg.com/vue@{version}/dist/vue.min.js'
elif key == 'vue_resource':
if static and hasattr(static, 'vue_resource_js'):
return liburl + static.vue_resource_js.relpath
return f'https://cdn.jsdelivr.net/npm/vue-resource@{version}'
elif key == 'fontawesome':
if static and hasattr(static, 'fontawesome_js'):
return liburl + static.fontawesome_js.relpath
return f'https://use.fontawesome.com/releases/v{version}/js/all.js'
elif key == 'bb_vue':
if static and hasattr(static, 'bb_vue_js'):
return liburl + static.bb_vue_js.relpath
return f'https://unpkg.com/vue@{version}/dist/vue.esm-browser.prod.js'
elif key == 'bb_oruga':
if static and hasattr(static, 'bb_oruga_js'):
return liburl + static.bb_oruga_js.relpath
return f'https://unpkg.com/@oruga-ui/oruga-next@{version}/dist/oruga.mjs'
elif key == 'bb_oruga_bulma':
if static and hasattr(static, 'bb_oruga_bulma_js'):
return liburl + static.bb_oruga_bulma_js.relpath
return f'https://unpkg.com/@oruga-ui/theme-bulma@{version}/dist/bulma.mjs'
elif key == 'bb_oruga_bulma_css':
if static and hasattr(static, 'bb_oruga_bulma_css'):
return liburl + static.bb_oruga_bulma_css.relpath
return f'https://unpkg.com/@oruga-ui/theme-bulma@{version}/dist/bulma.css'
elif key == 'bb_fontawesome_svg_core':
if static and hasattr(static, 'bb_fontawesome_svg_core_js'):
return liburl + static.bb_fontawesome_svg_core_js.relpath
return f'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-svg-core@{version}/+esm'
elif key == 'bb_free_solid_svg_icons':
if static and hasattr(static, 'bb_free_solid_svg_icons_js'):
return liburl + static.bb_free_solid_svg_icons_js.relpath
return f'https://cdn.jsdelivr.net/npm/@fortawesome/free-solid-svg-icons@{version}/+esm'
elif key == 'bb_vue_fontawesome':
if static and hasattr(static, 'bb_vue_fontawesome_js'):
return liburl + static.bb_vue_fontawesome_js.relpath
return f'https://cdn.jsdelivr.net/npm/@fortawesome/vue-fontawesome@{version}/+esm'