canton7 / canton7/fuelphp-casset

Added functionality to remove assets programatically

Open
#47 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
102
Forks
29
PR merge metrics
No merged PRs in 30d

Description

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:

``` php
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).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the asset-group management entry point and the existing add/disable behavior; the issue does not name a file or test. Done means assets can be removed from a group without disabling the whole group, including the namespaced cases described, with coverage for the requested CSS and JavaScript behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.