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 option to select CSS framework, add Foundation as an option #1813

Merged
merged 5 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### 9.0.0-beta.2: TBD
* Add option to select CSS framework, add Foundation as an option ([#1813](https://github.com/roots/sage/pull/1813))
* Add option to add Font Awesome ([#1812](https://github.com/roots/sage/pull/1812))
* Add option to change theme file headers ([#1811](https://github.com/roots/sage/pull/1811))
* Add option to remove Bootstrap ([#1810](https://github.com/roots/sage/pull/1810))
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ Sage is a WordPress starter theme with a modern development workflow.
* ES6 for JavaScript
* [Webpack](https://webpack.github.io/) for compiling assets, optimizing images, and concatenating and minifying files
* [Browsersync](http://www.browsersync.io/) for synchronized browser testing
* [Bootstrap 4](http://getbootstrap.com/) for a front-end framework (option to remove during installation)
* [Laravel's Blade](https://laravel.com/docs/5.3/blade) as a templating engine
* CSS framework options:
* [Bootstrap 4](http://getbootstrap.com/)
* [Foundation](http://foundation.zurb.com/)
* None (blank slate)


See a working example at [roots-example-project.com](https://roots-example-project.com/).

Expand All @@ -39,7 +43,8 @@ $ composer create-project roots/sage your-theme-name dev-master
During theme installation you will have the options to:

* Update theme headers (theme name, description, author, etc.)
* Remove Bootstrap
* Select a CSS framework (Bootstrap, Foundation, none)
* Add Font Awesome

## Theme structure

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
],
"post-create-project-cmd": [
"Roots\\Sage\\PostCreateProject::updateHeaders",
"Roots\\Sage\\PostCreateProject::removeBootstrap",
"Roots\\Sage\\PostCreateProject::selectFramework",
"Roots\\Sage\\PostCreateProject::addFontAwesome"
]
}
Expand Down
38 changes: 29 additions & 9 deletions src/lib/Sage/PostCreateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,39 @@ public static function updateHeaders(Event $event)
}
}

public static function removeBootstrap(Event $event)
public static function selectFramework(Event $event)
{
$io = $event->getIO();

if ($io->isInteractive()) {
if ($io->askConfirmation('<info>Remove Bootstrap?</info> [<comment>y,N</comment>]? ', false)) {
file_put_contents('package.json', str_replace(' "bootstrap": "^4.0.0-alpha.6",' . "\n", '', file_get_contents('package.json')));
file_put_contents('assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '', file_get_contents('assets/styles/main.scss')));
file_put_contents('assets/scripts/main.js', str_replace('import \'bootstrap/dist/js/bootstrap\';' . "\n", '', file_get_contents('assets/scripts/main.js')));
file_put_contents('assets/styles/components/_comments.scss', '');
file_put_contents('assets/styles/components/_forms.scss', '');
file_put_contents('assets/styles/components/_wp-classes.scss', '');
file_put_contents('assets/styles/layouts/_header.scss', '');
$frameworks = [
'Bootstrap',
'Foundation',
'None'
];
$framework = $io->select('<info>Select a CSS framework</info> <comment>(Default: Bootstrap)</comment>', $frameworks, 0);

switch($framework) {
case 0:
break;
case 1:
file_put_contents('package.json', str_replace(' "bootstrap": "^4.0.0-alpha.6",' . "\n", ' "foundation-sites": "6.3.0",' . "\n", file_get_contents('package.json')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should turn this into a preg_replace to so we aren't specific versions in here as much as possible.

Something like:

$default_framework_pattern = '/"bootstrap": ".*"/';
file_put_contents('package.json', preg_replace($default_framework_pattern, '"foundation-sites": "6.3.0"', file_get_contents('package.json')));

Also notice that this eliminates specifying whitespace

file_put_contents('assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '@import "~foundation-sites/scss/foundation";' . "\n" . '@include foundation-everything;' . "\n", file_get_contents('assets/styles/main.scss')));
file_put_contents('assets/scripts/main.js', str_replace('import \'bootstrap/dist/js/bootstrap\';' . "\n", 'import \'foundation-sites/dist/js/foundation\';' . "\n", file_get_contents('assets/scripts/main.js')));
file_put_contents('assets/styles/components/_comments.scss', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just have an array of file names to clear?

$files_to_clear = [
  'assets/styles/components/_comments.scss',
  'assets/styles/components/_forms.scss',
  'assets/styles/components/_wp-classes.scss',
  'assets/styles/layouts/_header.scss',
];

// etc
foreach($files_to_clear as $file) {
  file_put_contents($file, '');
}

file_put_contents('assets/styles/components/_forms.scss', '');
file_put_contents('assets/styles/components/_wp-classes.scss', '');
file_put_contents('assets/styles/layouts/_header.scss', '');
break;
case 2:
file_put_contents('package.json', str_replace(' "bootstrap": "^4.0.0-alpha.6",' . "\n", '', file_get_contents('package.json')));
file_put_contents('assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '', file_get_contents('assets/styles/main.scss')));
file_put_contents('assets/scripts/main.js', str_replace('import \'bootstrap/dist/js/bootstrap\';' . "\n", '', file_get_contents('assets/scripts/main.js')));
file_put_contents('assets/styles/components/_comments.scss', '');
file_put_contents('assets/styles/components/_forms.scss', '');
file_put_contents('assets/styles/components/_wp-classes.scss', '');
file_put_contents('assets/styles/layouts/_header.scss', '');
break;
}
}
}
Expand Down