From aa6050b3e05426a247e98347d6de4f4cf08ac101 Mon Sep 17 00:00:00 2001 From: James Roper Date: Thu, 29 Sep 2016 11:57:57 +1000 Subject: [PATCH] Added background-size configuration option --- app/com/gitpitch/models/MarkdownModel.java | 5 +++-- app/com/gitpitch/services/ImageService.java | 7 ++++--- app/com/gitpitch/utils/YAMLOptions.java | 12 ++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/com/gitpitch/models/MarkdownModel.java b/app/com/gitpitch/models/MarkdownModel.java index 31569e4..1865bac 100644 --- a/app/com/gitpitch/models/MarkdownModel.java +++ b/app/com/gitpitch/models/MarkdownModel.java @@ -152,7 +152,8 @@ public class MarkdownModel implements Markdown { imageService.extractBgUrl(md, gitRawBase, this); return new StringBuffer(delimiter(md)) - .append(imageService.buildBackground(pp, imageBgUrl)) + .append(imageService.buildBackground(pp, imageBgUrl, + yOpts.fetchImageBgSize(pp))) .toString(); } else if (gistDelimFound(md)) { @@ -542,7 +543,7 @@ public class MarkdownModel implements Markdown { public static final String MD_IFRAME_OPEN = ""; public static final String MD_SPACER = "\n"; public static final String DATA_IMAGE_ATTR = "data-background-image="; diff --git a/app/com/gitpitch/services/ImageService.java b/app/com/gitpitch/services/ImageService.java index 7f9443f..1c5918a 100644 --- a/app/com/gitpitch/services/ImageService.java +++ b/app/com/gitpitch/services/ImageService.java @@ -43,16 +43,17 @@ public class ImageService { public String buildBackground(PitchParams pp, YAMLOptions yOpts) { - return buildBackground(pp, yOpts.fetchImageBg(pp)); + return buildBackground(pp, yOpts.fetchImageBg(pp), yOpts.fetchImageBgSize(pp)); } public String buildBackground(PitchParams pp, - String imageBgUrl) { + String imageBgUrl, String imageBgSize) { return new StringBuffer(MarkdownModel.MD_SPACER) .append(MarkdownModel.MD_IMAGE_OPEN) .append(imageBgUrl) .append(MarkdownModel.MD_IMAGE_SIZE) + .append(imageBgSize) .append(MarkdownModel.MD_CLOSER) .append(MarkdownModel.MD_SPACER) .toString(); @@ -66,8 +67,8 @@ public class ImageService { String fragUrl = frag.substring(0, frag.indexOf("\"")); String imageName = FilenameUtils.getName(fragUrl); String imageUrl = IMG_OFFLINE_DIR + imageName; - return buildBackground(null, imageUrl); + return md.replace(fragUrl, imageUrl); } catch (Exception bex) { } diff --git a/app/com/gitpitch/utils/YAMLOptions.java b/app/com/gitpitch/utils/YAMLOptions.java index 0b49419..8744c4c 100644 --- a/app/com/gitpitch/utils/YAMLOptions.java +++ b/app/com/gitpitch/utils/YAMLOptions.java @@ -164,6 +164,16 @@ public final class YAMLOptions { } } + public String fetchImageBgSize(PitchParams pp) { + String bgSize = _yProps.get(IMAGE_BG_SIZE_OPTION); + if (bgSize == null) { + return DEFAULT_BG_SIZE; + } else { + return bgSize; + } + } + + public String fetchTransition(PitchParams pp) { String transition = _yProps.get(TRANSITION_OPTION); @@ -316,6 +326,7 @@ public final class YAMLOptions { } public static final String PITCHME_YAML = "PITCHME.yaml"; + public static final String DEFAULT_BG_SIZE = "100% 100%"; public static final String DEFAULT_TRANSITION = "slide"; public static final String MATHJAX_DEFAULT = "TeX-MML-AM_CHTML"; public static final String HIGHLIGHT_DARK_DEFAULT = "github-gist.css"; @@ -328,6 +339,7 @@ public final class YAMLOptions { private static final String VERTICAL_CENTER = "vertical-center"; private static final String LOGO_OPTION = "logo"; private static final String IMAGE_BG_OPTION = "background"; + private static final String IMAGE_BG_SIZE_OPTION = "background-size"; private static final String TRANSITION_OPTION = "transition"; private static final String AUTOSLIDE_OPTION = "autoslide"; private static final String LOOP_OPTION = "loop";