{"id":13805718,"url":"https://github.com/sontek/pyramid_webassets","last_synced_at":"2025-08-20T08:32:42.194Z","repository":{"id":2186002,"uuid":"3133628","full_name":"sontek/pyramid_webassets","owner":"sontek","description":"Pyramid extension for working with the webassets library","archived":false,"fork":false,"pushed_at":"2018-11-03T20:40:06.000Z","size":158,"stargazers_count":64,"open_issues_count":7,"forks_count":36,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-12T17:50:14.423Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sontek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-01-09T02:40:31.000Z","updated_at":"2024-02-06T10:27:25.000Z","dependencies_parsed_at":"2022-09-20T07:50:55.312Z","dependency_job_id":null,"html_url":"https://github.com/sontek/pyramid_webassets","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sontek%2Fpyramid_webassets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sontek%2Fpyramid_webassets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sontek%2Fpyramid_webassets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sontek%2Fpyramid_webassets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sontek","download_url":"https://codeload.github.com/sontek/pyramid_webassets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230408170,"owners_count":18220974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:01:04.132Z","updated_at":"2024-12-19T09:07:27.762Z","avatar_url":"https://github.com/sontek.png","language":"Python","funding_links":[],"categories":["Asset Management"],"sub_categories":[],"readme":"Installation\n===================\n\n[![Build Status](https://travis-ci.org/sontek/pyramid_webassets.svg?branch=master)](https://travis-ci.org/sontek/pyramid_webassets)\n[![Coverage](https://img.shields.io/coveralls/sontek/pyramid_webassets.svg)](https://coveralls.io/r/sontek/pyramid_webassets)\n\nInstall the package:\n\n``` bash\n$ pip install pyramid_webassets\n```\n\nEITHER add it to your Pyramid `production.ini` and `development.ini`:\n\n```\npyramid.includes =\n    pyramid_debugtoolbar\n    pyramid_tm\n    pyramid_webassets\n```\n\nOR include it when configuring your application, usually in `__init__.py`:\n\n``` python\ndef main(global_config, **settings):\n    ...\n    config.include('pyramid_webassets')\n```\n\nConfiguration\n====================\nYou are required to set ``base_dir`` and ``base_url``, the rest are optional,\nbut we currently support:\n\n * ``base_dir``: The directory to output and search for assets\n * ``base_url``: The url static assets will be located\n * ``debug``: If webassets should be in debug mode (i.e no compression)\n * ``updater``: Different update configurations (i.e always, timestamp)\n * ``cache``: If we should use webassets cache (if boolean), or override default path to cache directory\n * ``jst_compiler``: A custom jst compiler, by default it uses underscore\n * ``url_expire``: If a cache-busting query string should be added to URLs\n * ``static_view``: If assets should be registered as a static view using Pyramid config.add_static_view()\n * ``cache_max_age``: If static_view is true, this is passed as the static view's cache_max_age argument (allowing control of expires and cache-control headers)\n * ``paths``: A JSON dictionary of PATH=URL mappings to add paths to alternative asset locations (`URL` can be null to only add the path)\n * ``bundles``: filename or [asset-spec] (or a list of either) (http://docs.pylonsproject.org/projects/pyramid/en/latest/glossary.html#term-asset-specification) of a YAML [bundle spec](http://webassets.readthedocs.org/en/latest/loaders.html?highlight=loader#webassets.loaders.YAMLLoader) whose bundles will be auto-registered\n\n``` ini\nwebassets.base_dir              = %(here)s/app/static\nwebassets.base_url              = static\nwebassets.debug                 = True\nwebassets.updater               = timestamp\nwebassets.cache                 = False\nwebassets.jst_compiler          = Handlebars.compile\nwebassets.url_expire            = False\nwebassets.static_view           = True\nwebassets.cache_max_age         = 3600\nwebassets.bundles               = mypackage:webassets.yaml\n```\n\nThen you can just use config.add_webasset to add bundles to your environment\n\n``` python\nfrom webassets import Bundle\n\njst = Bundle('templates/*.html',\n        filters='jst',\n        output='js/jst.js', debug=False)\n\nconfig.add_webasset('jst', jst)\n```\n\nAll other configurations are passed through to webassets, including\nfilter settings. These are adjusted as follows: if a value is exactly\n``true`` or ``false``, then it is converted to a boolean; if a value\nis prefixed with the string ``json:``, then it is JSON-parsed. This\nallows pyramid-webassets to handle basic extensible filter\nconfigurations without needing any python code, for example:\n\n``` ini\nwebassets.less_run_in_debug     = true\nwebassets.less_extra_args       = json:[\"--line-numbers=mediaquery\", \"-O2\"]\n```\n\nUse asset specs instead of files and urls\n----------------------------------------------\nIt's possible to use an asset specifications (package:file) instead of simple file names.\n\n- If the asset specifications declares a path outside the base_dir, the file will be copied.\n- Otherwise, it will work like a normal bundle file.\n\nIf files are bundled from other packages and those packages act like pyramid\nplugins adding their own ``add_static_view``, webassets will use those static\nview urls to show the individual files if needed (for example, in development mode).\n\nIf you have defined your own static route and you want to use it with webassets,\nfor example:\n\n``` python\nconfig.add_static_view('static-stuff', 'my.super.app:static')\n```\n\nSetting the base url configuration option to an asset specification:\n\n```\nbase_url = my.super.app:static\n```\n\nWill make webassets use the ``/static-stuff`` route for your assets. Note:\nthe absolute or relative path depends on where is your application is deployed.\n\nUse with templates\n========================\nIncluded are helpers that you can use with your templates. Additional helpers\nare documented below in the section labeled \"Extras\".\n\nMako\n-----\n\nYou can use the global webassets tag:\n``` python\n% for url in webassets(request, 'css/bootstrap.css', 'css/bootstrap-responsive.css', output='css/generated.css', filters='cssmin'):\n    \u003clink href=\"${url}\" rel=\"stylesheet\"\u003e\n% endfor\n```\n\nor you can grab the environment from the request.\n\nJinja2\n-------\nIf you are using Jinja2, you can just do the following configuration (this assumes use of pyramid_jinja2):\n\n``` python\nconfig.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')\nassets_env = config.get_webassets_env()\njinja2_env = config.get_jinja2_environment()\njinja2_env.assets_environment = assets_env\n```\nand then:\n\n``` python\n{% assets \"jst\" %}\n\u003cscript type=\"text/javascript\" src=\"{{ ASSET_URL }}\"\u003e\u003c/script\u003e\n{% endassets %}\n```\n\nGeneric\n--------\nIt's always possible to access the environment from the request.\n\n```python\njst_urls = request.webassets_env['jst'].urls()\n```\n\nExtras\n====================\n\nThere are a few more utility methods you can use to make working with webassets\nwithin your Pyramid application easier.\n\nConfiguration\n---------------\nThese methods can be called on the `Configurator` instance during startup:\n\n``add_webasset(name, bundle)``: Registers a bundle with webassets\n\n``add_webassets_setting(key, value)``: Update the environment configuration\n\n``add_webassets_path(path, url)``: Append a URL mapping to the environment\n\n``get_webassets_env_from_settings(settings, prefix='static_assets')``: Pass a\ndictionary of your settings and an optional keyword argument of the prefix in\nyour configuration and it will return a webassets environment.\n\n``get_webassets_env()``: This will pull the environment out of the registry.\n\nRequest handling\n------------------\nThese properties and helpers are attached to the `Request` object:\n\n``request.webassets_env``: Access the webassets environment\n\n``request.webassets(*bundle_names, **kwargs)``: Build the named bundles.\nKeyword arguments will be passed to webassets to influence bundling.\n\nBuilding assets from a script\n=======================================\nThe `webassets` module includes a command line script, also called `webassets`,\nwhich can be used to build bundles offline. When integrating with Pyramid, it\ncan be helpful to bootstrap the environment using paster instead, like so:\n\n``` python\nimport pyramid.paster\nimport webassets.script\n\napp_env = pyramid.paster.bootstrap('config.ini')\nassets_env = app_env['request'].webassets_env\nwebassets.script.main(['build'], assets_env)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsontek%2Fpyramid_webassets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsontek%2Fpyramid_webassets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsontek%2Fpyramid_webassets/lists"}