Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostCSS import theme plugin #24

Merged
merged 12 commits into from
May 22, 2018
Merged

Add PostCSS import theme plugin #24

merged 12 commits into from
May 22, 2018

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented May 16, 2018

This PR will add PostCSS import theme plugin. It recognizes @import 'theme'; rule in theme and could import the other plugin that is added to ThemeSet instance.

/* @theme base */
section {
  width: 960px;
  height: 720px;

  background: silver;
}
/* @theme wide */

@import 'base';

section {
  width: 1280px;
}

themeSet.pack('wide') returns the imported style when these themes are added to the ThemeSet instance. In this case, you can see the slide for widescreen.

We might prepare another syntax @import-theme to avoid preprocessing by Sass.

ToDo

  • Implement import logic
  • Support nested import
  • Raise error on detecting circular import
  • [ ] Fix section size plugin to recognize the slide size defined in a final section rule after imported
  • Fix ThemeSet#getThemeProp to fallback into imported themes
  • Add more test cases

@yhatt
Copy link
Member Author

yhatt commented May 16, 2018

According to the CSS specification, @import must precede all other types of rules, except @charset rules.

So we can parse @import rule(s) when the theme is added and use as fallback themes on calling ThemeSet#getThemeProp. I have thought its implementation is not too difficult.

@yhatt yhatt changed the title [Work in progress] Add PostCSS import theme plugin Add PostCSS import theme plugin May 21, 2018
@yhatt
Copy link
Member Author

yhatt commented May 21, 2018

OK, we are ready to use the theme import feature!

@import will replace from the definition into the specified theme contents. It could make a based theme customize easily.

To get along with CSS preprocessors like Sass, we provide alternative syntax @import-theme too.

/* @theme wide */

@import-theme 'base';

section {
  width: 1280px;
}

Sass's @import will resolve file path and remove the definition. Preprocessor's optimization about the order of @ rule might break the defined order. @marpit-theme can define theme(s) to add into the beginning of CSS.


We must write a section about @import on README.md

Remaining

  • Update README.md
  • Update CHANGELOG.md

@yhatt yhatt merged commit ff3b9d4 into master May 22, 2018
@yhatt yhatt deleted the import-theme branch May 22, 2018 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant