LastCallMedia / Mannequin

Mannequin Component Theming Tool
https://mannequin.io/
MIT License
38 stars 8 forks source link

How to get assets in a directory above mannequin #114

Closed claytron5000 closed 6 years ago

claytron5000 commented 6 years ago

I have mannequin installed in a shared directory in my custom theme directory. I want to pull CSS and JS from a theme into Mannequin. Desired directory structure:

 custom
 |__shared
 |   |   .mannequin.php
 |   |__html
 |   |...
 |__theme1
     |__js
     |   main.js

I'm trying to do something like this:

return MannequinConfig::create()
    ->setGlobalJs([__DIR__ . '/../theme1/js/main.js'])
    ->addExtension($htmlExtension);

Is there a recommended way of keeping the Mannequin install separate from the theme?

claytron5000 commented 6 years ago

After writing this out I tried the reverse: install Mannequin in the theme, and include the shared directory from there:

custom
|__shared
|   |...
|__theme1
    |  .mannequin.php
    |__js
        |    main.js

And

Finder::create()
  ->files()
  ->in(__DIR__.'/../shared/html/')

...

->setGlobalJs([ '/js/main.js'])

This actually makes more sense than the other way around.

claytron5000 commented 6 years ago

The other option would be to install Mannequin at the site root or above. This kinda feels like it breaks the "isolated environment" goal.

rbayliss commented 6 years ago

Hey @claytron5000 - did you get this figured out? The .mannequin.php file should live above all of the components and assets. As it stands now, the setup we're recommending is one where .mannequin.php lives in the site root (or repo root), and reference templates and styles from your theme.

That being said, I'm not sure if you'd be able to make this work with the .mannequin.php file in the theme, then referencing CSS and JS above your current directory. Maybe something like this?

$config = MannequinConfig::create([
  'docroot' => __DIR__.'/../', 
]);

// This becomes relative to ../
$config->setGlobalJs([ '/shared/js/main.js']); 

The docroot property is undocumented at the moment because we're not certain it's a good idea to use yet (or how we want to recommend using it), but you could try it and see if it works for you. If it does, let us know!

claytron5000 commented 6 years ago

Thanks Rob, I might try the docroot property. We're still working out how Mannequin gets integrated into the project, both of these suggestions are helpful.