ice / framework

Source code of Ice framework
https://www.iceframework.org
BSD 3-Clause "New" or "Revised" License
341 stars 45 forks source link

Assets loading with themes and skins supported #191

Open Yahasana opened 6 years ago

Yahasana commented 6 years ago

Assets loading with themes and skins supported. assume that different apps (or plugins) are independent with each others but share the same basic modules and public resources

A) asset cases: there are stylesheet files in public css share by all apps and app specific stylesheet locate in its directory. e.g.

B) loading source and target

  1. load the min file
    • a) load from public: /css/style.css ===> public/min/css/style.min.css minify public/css/style.css to public/min/css/style.min.css
    • b) load from app dir: css/account.css ===> public/min/css/account.min.css minify account/default/css/account.css to public/min/css/account.min.css
  2. load the raw file
    • a) load from public: /css/style.css ===> public/css/style.css
    • b) load from app dir: default/css/account.css ===> public/default/css/account.css
      • i) if public/default/css/account.css not exists, copy account/default/css/account.css to public/default/css/
      • ii) else update account/default/css/account.css to public/default/css/

C) implement

1) if uri is start with /, it'll try to load asset from document root


$mySkin = 'Default';

// Register specific services for the module
public function registerServices(Di $di)
{
    $di->assets->setOptions([
            'source' => __DIR__ . '/Skin/' . $mySkin . '/',
            'target' => 'min/',
            'minify' => 3
        ]);
}

// css used by specific module
// load from module dir/Skin/Default/css/account.css
$this->assets->addCss(['css/account.css']); 

// css shared by all modules
// load from document_root/Skin/Default/css/style.css
$this->assets->addCss(['/Skin/' . $mySkin . '/css/style.css']); 

2) always store the min files in the document_root/target dir

ONE MORE THING

type parameter change from text/css or text/javascript to css or js

$assets->addCss(['css/style.css', 'type' => 'css'])
->addCss(['js/script.js', 'type' => 'js'])

but not


$assets->addCss(['css/style.css', 'type' => 'text/css'])
->addCss(['js/script.js', 'type' => 'text/javascript'])
Yahasana commented 5 years ago

@mruz please review the new features i just add to comment. i'll trying to implement it soon if you agree with that. and after that i think Ice is ready for new release and good for deploying to production

Yahasana commented 5 years ago

@mruz review plz