framework icon indicating copy to clipboard operation
framework copied to clipboard

Assets loading with themes and skins supported

Open Yahasana opened this issue 6 years ago • 2 comments

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.

  • public/css/style.css
  • public/min/css/style.min.css
  • app/account/skin/default/css/account.css
  • public/min/css/account.min.css

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']); 
  1. 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 avatar Sep 15 '18 15:09 Yahasana

@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 avatar Oct 04 '18 14:10 Yahasana

@mruz review plz

Yahasana avatar Oct 05 '18 14:10 Yahasana