wvuweb / hammer

A tool for CleanSlate theme development
https://cleanslate.wvu.edu
4 stars 2 forks source link

Shared Themes with same partial paths. #22

Closed zeroedin closed 9 years ago

zeroedin commented 9 years ago

Say you have the following mock_data.yml file:

shared_themes:
  layouts__masthead--v1: "code"
  layouts__footer__credits--v1: "code"
  layouts__frontpage: "cleanslate-toolkit"
  layouts__frontpage: "code"

And you have the following radius tags in your theme:

<r:partial name="layouts/frontpage" theme="Cleanslate Toolkit" />

<r:partial name="layouts/frontpage" theme="Code" />

The second radius tag would never render from the correct theme. It would also render from cleanslate-toolkit as it appears first in the YAML file.

This is a bug and an unintended outcome.

The radius tag should still be able to render the correct partial. However Hammer at this time is loading partials based on the "partial path" key.

In order to correct this Hammer needs to be made aware of the CleanSlate theme name passed on the radius tag. Here is the proposed fix:

Mock Data proposed syntax change around shared_themes:

shared_themes:
  "Code":
    "layouts/masthead--v1" : "code"
    "layouts/masthead--v1" : "code"
    "layouts/footer__contact--v1": "code"
    "layouts/footer__credits--v2": "code"
    "layouts/footer__icons--v1": "code"
    "layouts/browser-update-org--v2": "code"

  "Some: RandomTheme":
    "layouts/masthead--v1" : "random-theme"
    "layouts/masthead--v1" : "random-theme"
    "layouts/footer__contact--v1": "random-theme"
    "layouts/footer__credits--v2": "random-theme"
    "layouts/footer__icons--v1": "random-theme"
    "layouts/browser-update-org--v2": "random-theme"

Radius <r:partial name="layouts/frontpage" theme="Code" />

<r:partial name="layouts/frontpage" theme="Some: RandomTheme" />

For the sake of the above example say for some reason you have the "Code" repo checked out twice locally. You renamed it locally on the second git clone to random-theme

git clone http://stash.development.wvu.edu/scm/cst/code.git random-theme

So now you have the same exact partials in two separate locations. As I explained above in the first mock_data.yml example the current syntax will not allow you to load anything from "random-theme" Hammer would always return the partial from "code" as its first in the mock_data.yml.

Now with this proposed new syntax in the 2nd example Hammer would first look for the key of the "theme" then look for "path" which is the intended loading scheme.

With this proposed fix you should note in the "new" syntax you have to use the actual path "layouts/masthead--v1" for the partial path surrounding it with double quotes. This fix also removes the old syntax of converting the "/" into a double underscore "__".

You will also be able to use special characters and spaces in the theme name from CleanSlate such as: "Some: RandomTheme" and in the local directory name such as: "random:theme-directory!", as long as you surround with double quotes. I

If you do not surround these with double quotes it will error.

As an example: Say you checked out the repo that on CleanSlate is named "Some: RandomTheme" and locally cloned it into a folder called "This: is a Crazy! Folder Name"

You would use the following mock_data syntax:

shared_themes:
  "Some: RandomTheme":
    "layouts/masthead--v1" : "This: is a Crazy! Folder Name"
    "layouts/masthead--v1" : "This: is a Crazy! Folder Name"
    "layouts/footer__contact--v1": "This: is a Crazy! Folder Name"
    "layouts/footer__credits--v2": "This: is a Crazy! Folder Name"
    "layouts/footer__icons--v1": "This: is a Crazy! Folder Name"
    "layouts/browser-update-org--v2": "This: is a Crazy! Folder Name"

I have the fix ready to go, however this is a breaking fix. That means if you update Hammer, and do not fix your syntax in your mock_data.yml you will receive errors and your partials will not load. I will be making an announcement when I push this fix live. Hammer at that point should let you know there is an update and at that point you should be aware of the changes you will have to make to your mock_data.yml file.

zeroedin commented 9 years ago

Fixed in wvuweb/hammer@6f0e518