From 85b3840ebb0f4c0dcc3c997f6c9c5c55153fbd3d Mon Sep 17 00:00:00 2001 From: David Russell Date: Wed, 28 Sep 2016 19:59:46 +0700 Subject: [PATCH] Handle custom css overrides as external stylesheets on slideshow. --- .../gitpitch/controllers/PitchController.java | 21 +++++++++++++++++++ app/com/gitpitch/models/SlideshowModel.java | 11 ++++++++++ app/com/gitpitch/views/Slideshow.scala.html | 6 +----- conf/routes | 3 +++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/com/gitpitch/controllers/PitchController.java b/app/com/gitpitch/controllers/PitchController.java index c4c1d56..9af15fe 100644 --- a/app/com/gitpitch/controllers/PitchController.java +++ b/app/com/gitpitch/controllers/PitchController.java @@ -376,6 +376,24 @@ public class PitchController extends Controller { } // offline action + /* + * CustomCSS returns text/css overrides for a slideshow. + */ + public Result customCSS(String grs, + String user, + String repo, + String branch) { + + PitchParams pp = + PitchParams.build(grsOnCall(grs), user, repo, branch); + Optional ssmo = pitchService.cachedYAML(pp); + String customStyle = CUSTOM_CSS_NOT_FOUND; + if(ssmo.isPresent()) { + customStyle = ssmo.get().fetchThemeOverride(); + } + return ok(customStyle).as("text/css"); + } // customCss action + /* * Gist generates and renders GitHub-Gist HTML for * embedding within slideshows. @@ -395,4 +413,7 @@ public class PitchController extends Controller { "GitPitch Slideshow print service temporarily unavailable."; private static final String PITCHME_OFFLINE_ERROR = "GitPitch Slideshow offline service temporarily unavailable."; + + private static final String CUSTOM_CSS_NOT_FOUND = + "// Custom CSS not found."; } diff --git a/app/com/gitpitch/models/SlideshowModel.java b/app/com/gitpitch/models/SlideshowModel.java index 571c455..d55feef 100644 --- a/app/com/gitpitch/models/SlideshowModel.java +++ b/app/com/gitpitch/models/SlideshowModel.java @@ -185,6 +185,17 @@ public class SlideshowModel { return customCSS; } + /* + * Return theme override css for slideshow. + */ + public String fetchThemeOverrideCSS() { + + return com.gitpitch.controllers.routes.PitchController.customCSS(_pp.grs, + _pp.user, + _pp.repo, + _pp.branch).url(); + } + /* * Return active theme font for slideshow. */ diff --git a/app/com/gitpitch/views/Slideshow.scala.html b/app/com/gitpitch/views/Slideshow.scala.html index c671173..7e097ba 100755 --- a/app/com/gitpitch/views/Slideshow.scala.html +++ b/app/com/gitpitch/views/Slideshow.scala.html @@ -19,13 +19,9 @@ - @SlideshowStyle() - @if(ssm.hasThemeOverride()) { - + } diff --git a/conf/routes b/conf/routes index 52dbbad..485b1ff 100644 --- a/conf/routes +++ b/conf/routes @@ -20,6 +20,9 @@ GET /pitchme/offline/:grs/:user/:repo/:b/:t/PITCHME.zip com.gitpitch.cont # Handle GitHub OAuth Callback # GET /pitchme/authorized com.gitpitch.controllers.AuthController.authorized(code:String ?= null, state:String ?= null) +# Serve PITCHME.css custom theme styling. +GET /pitchme/custom-css/:grs/:user/:repo/:b/PITCHME.css com.gitpitch.controllers.PitchController.customCSS(grs:String, user:String, repo:String, b:String) + # Serve PITCHME.md markdown. GET /pitchme/markdown/:grs/:user/:repo/:b/PITCHME.md com.gitpitch.controllers.PitchController.markdown(grs:String, user:String, repo:String, b:String)