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

Added functionality to remove assets programatically #47

Open
leemason opened this issue Sep 27, 2013 · 0 comments
Open

Added functionality to remove assets programatically #47

leemason opened this issue Sep 27, 2013 · 0 comments

Comments

@leemason
Copy link

im working on a fuel app, which is using the theme class, and i want themes to able to remove/add assets as needed.

your package is brilliant and will help in explaining the steps to theme debs (which i why i chose it over Asset).

the one thing missing for me (i was considering ie if, but found the agent class does it pretty well). anyway back on track, the one thing missing is the ability to remove assets once added.

sure you can disable a group, but say i have a page i dont want "table-styling.css" loaded on, but the file is loaded in my "theme" group.

the problem with this is i cant disable the entire group.

i know this can be handled by not adding the file to the group per page, but trying to be efficient i ended up extending the class and adding these functions:

   public static function remove_css($sheet, $group){
        static::remove_asset('css', $sheet, $group);
    }

    public static function remove_js($sheet, $group){
        static::remove_asset('js', $sheet, $group);
    }

    public static function remove_asset($type, $sheet, $group){
        foreach(static::$groups[$type][$group]['files'] as $key => $filegroup ){
            if($filegroup[0] == $group.'::'.$sheet || $filegroup[1] == $group.'::'.$sheet){
                unset(static::$groups[$type][$group]['files'][$key]);
            }
        }
    }

quick and dirty removing of the files from the array deals with this well.

it probably needs a bit more work to deal with none namespaced assets, but it works for me, maybe you could add it to the next version?

might even be an idea to put the values in a "disabled" array, so it could then be loaded after (although i cant see this being needed once removed).

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