Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure filters using the YAML config option? Specifically cssrewrite. #540

Open
gg2 opened this issue Nov 11, 2021 · 1 comment

Comments

@gg2
Copy link

gg2 commented Nov 11, 2021

I'm using webassets, as part of a platform on Flask (CKAN) (so as built-in of Flask? I don't know).

I have a plugin that uses a js library, that uses some css themes, that are initially located relatively to each other:
js.js
js-themes/
default/
icons.png
style.css

style.css references url(icons.png).

Using webassets to bundle style.css, just adding cssrewrite as a filter without config fails with a ValueError in query_url_mapping: "'Cannot determine url for %s' % filepath".

I see in the docs, get_filter('cssrewrite', replace={'old_directory':'/custom/path/'})
replace looks like what I need.

I see there is the documentation for adding a config section to a YAML (if I interpret correctly):

config:
    another_custom_config_value: foo
bundles:
    # ...

So, what should cssrewrite config look like via YAML?
Variations on the following stabs-in-the-dark don't work or cause crashes parsing the YAML:

config:
  cssrewrite:
    - replace={'': 'assets/js-themes/default/'}
@gg2
Copy link
Author

gg2 commented Nov 11, 2021

So, I assume, now that I'm looking at it again a 2nd time, cssrewrite simply accepts no config from the environment.
The "manual mode" is the expectation for use.

If so, then I'd like to lobby for enabling "replace" as a config for cssrewrite, especially via YAML (presumably an option can be set via YAML by default, if environment.config can be set). For the platform I'm working with, I'm not sure they provide a means to hook into webassets before/after it runs, aside from simply setting up the YAML config. And I always dislike setting up custom hacks to make things work outside the regular flow.

Anyway, thank you for the consideration.

Also, now that I've had the presence of mind to find the environment config docs, I suppose the YAML might look more like this?

config:
    cssrewrite_replace:
        - ''
          'assets/js-themes/default/'
        - 'etc'
          ...

If I can't specify to simply add a prefix where there is none, and must use the regex replace, that would be helpful to elaborate in the docs. Thank you, again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant