From 126dacef67e02655997ac85ca5c360b1608fd5aa Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Tue, 23 Jul 2019 13:02:40 +1200 Subject: [PATCH 1/3] Make sure the style guide is always accessible to all users --- app/_config/theme.yml | 10 ++++ .../SimpleStyleguideController.php | 49 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 app/src/Controllers/SimpleStyleguideController.php diff --git a/app/_config/theme.yml b/app/_config/theme.yml index faf46e3..5573c2f 100644 --- a/app/_config/theme.yml +++ b/app/_config/theme.yml @@ -26,3 +26,13 @@ SilverStripe\LoginForms\EnablerExtension: - '$default' - 'bambusa' - 'starter' + +--- +Name: bambusa-simplestyleguide +After: '#simplestyleguide' +--- +# Move the style guide on a different URL segment +SilverStripe\Control\Director: + rules: + '_styleguide': false + 'styleguide': SilverStripe\Controllers\SimpleStyleguideController diff --git a/app/src/Controllers/SimpleStyleguideController.php b/app/src/Controllers/SimpleStyleguideController.php new file mode 100644 index 0000000..ef083df --- /dev/null +++ b/app/src/Controllers/SimpleStyleguideController.php @@ -0,0 +1,49 @@ +update('SSViewer', 'theme', Subsite::currentSubsite()->Theme); + } + + $page = SiteTree::get()->first(); + $controller = ModelAsController::controller_for($page); + $controller->init(); + + // requirements + Requirements::css('benmanu/silverstripe-simple-styleguide: css/styleguide.css'); + Requirements::javascript('benmanu/silverstripe-simple-styleguide: js/styleguide.js'); + + return $controller + ->customise($this->getStyleGuideData()) + ->renderWith(['SimpleStyleguideController', 'Page']); + } +} From 7760ce9c044f3faabecd59250965c8694b89cd90 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Tue, 23 Jul 2019 14:18:28 +1200 Subject: [PATCH 2/3] Redirect _styleguide to styleguide Co-Authored-By: Andre Kiste --- app/_config/theme.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/_config/theme.yml b/app/_config/theme.yml index 5573c2f..47bd278 100644 --- a/app/_config/theme.yml +++ b/app/_config/theme.yml @@ -34,5 +34,5 @@ After: '#simplestyleguide' # Move the style guide on a different URL segment SilverStripe\Control\Director: rules: - '_styleguide': false + '_styleguide': '->styleguide' 'styleguide': SilverStripe\Controllers\SimpleStyleguideController From e5aa5f8e0c4d17cfc43e70c9afd82b5b42d07bb2 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Tue, 23 Jul 2019 14:25:07 +1200 Subject: [PATCH 3/3] Switch to using a singletong for our nested controller to avoid loading the homepage --- app/src/Controllers/SimpleStyleguideController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/Controllers/SimpleStyleguideController.php b/app/src/Controllers/SimpleStyleguideController.php index ef083df..63382f1 100644 --- a/app/src/Controllers/SimpleStyleguideController.php +++ b/app/src/Controllers/SimpleStyleguideController.php @@ -34,7 +34,7 @@ public function index() Config::inst()->update('SSViewer', 'theme', Subsite::currentSubsite()->Theme); } - $page = SiteTree::get()->first(); + $page = SiteTree::singleton(); $controller = ModelAsController::controller_for($page); $controller->init();