Added new (bg) color slide delim, plus color arg support on code and gist delims.

This commit is contained in:
David Russell 2018-03-10 11:01:51 +07:00
parent dff755f869
commit de375fbd66
2 changed files with 75 additions and 27 deletions

View File

@ -30,6 +30,7 @@ import com.gitpitch.services.VideoService;
import com.gitpitch.services.GISTService; import com.gitpitch.services.GISTService;
import com.gitpitch.services.CodeService; import com.gitpitch.services.CodeService;
import com.gitpitch.services.ShortcutsService; import com.gitpitch.services.ShortcutsService;
import com.gitpitch.services.SlideService;
import com.gitpitch.git.GRSManager; import com.gitpitch.git.GRSManager;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
@ -57,6 +58,7 @@ public class MarkdownModel implements Markdown {
private final GISTService gistService; private final GISTService gistService;
private final CodeService codeService; private final CodeService codeService;
private final ShortcutsService shortcutsService; private final ShortcutsService shortcutsService;
private final SlideService slideService;
private final GRSManager grsManager; private final GRSManager grsManager;
private final MarkdownRenderer mrndr; private final MarkdownRenderer mrndr;
private final String markdown; private final String markdown;
@ -69,6 +71,7 @@ public class MarkdownModel implements Markdown {
GISTService gistService, GISTService gistService,
CodeService codeService, CodeService codeService,
ShortcutsService shortcutsService, ShortcutsService shortcutsService,
SlideService slideService,
GRSManager grsManager, GRSManager grsManager,
@Nullable @Assisted MarkdownRenderer mrndr) { @Nullable @Assisted MarkdownRenderer mrndr) {
@ -77,6 +80,7 @@ public class MarkdownModel implements Markdown {
this.gistService = gistService; this.gistService = gistService;
this.codeService = codeService; this.codeService = codeService;
this.shortcutsService = shortcutsService; this.shortcutsService = shortcutsService;
this.slideService = slideService;
this.grsManager = grsManager; this.grsManager = grsManager;
this.mrndr = mrndr; this.mrndr = mrndr;
@ -185,6 +189,8 @@ public class MarkdownModel implements Markdown {
return gistService.build(md, dp, pp, yOpts, this); return gistService.build(md, dp, pp, yOpts, this);
} else if(codeDelimFound(dp)) { } else if(codeDelimFound(dp)) {
return codeService.build(md, dp, pp, yOpts, this); return codeService.build(md, dp, pp, yOpts, this);
} else if(colorDelimFound(dp)) {
return slideService.buildColorBackground(md, dp, pp, yOpts, this);
} }
if (yOpts != null && yOpts.hasImageBg()) { if (yOpts != null && yOpts.hasImageBg()) {
@ -415,6 +421,10 @@ public class MarkdownModel implements Markdown {
return dp.get(DELIM_QUERY_CODE) != null; return dp.get(DELIM_QUERY_CODE) != null;
} }
private boolean colorDelimFound(DelimParams dp) {
return dp.get(DELIM_QUERY_COLOR) != null;
}
private String delimiter(String md) { private String delimiter(String md) {
return (md.startsWith(hSlideDelim)) ? horizDelim() : vertDelim(); return (md.startsWith(hSlideDelim)) ? horizDelim() : vertDelim();
} }
@ -652,6 +662,8 @@ public class MarkdownModel implements Markdown {
"\" data-background-size=\""; "\" data-background-size=\"";
public static final String MD_IMAGE_COLOR = public static final String MD_IMAGE_COLOR =
"\" data-background-color=\""; "\" data-background-color=\"";
public static final String MD_BG_COLOR =
"<!-- .slide: data-background=\"";
public static final String MD_CLOSER = "\" -->"; public static final String MD_CLOSER = "\" -->";
public static final String MD_SPACER = "\n"; public static final String MD_SPACER = "\n";
public static final String DATA_IMAGE_ATTR = "data-background-image="; public static final String DATA_IMAGE_ATTR = "data-background-image=";

View File

@ -48,39 +48,75 @@ public class SlideService {
this.imageService = imageService; this.imageService = imageService;
} }
/* /*
* Build basic slide structure including: * Build basic slide structure including:
* *
* 1. Clean delimiter and * 1. Clean delimiter and
* 2. Optionally slide bg-image based on YAMLOptions.hasImageBg. * 2. Optionally slide bg-image based on YAMLOptions.hasImageBg.
*/ * 3. Or slide color delimiter.
public String build(String md, */
DelimParams dp, public String build(String md,
PitchParams pp, DelimParams dp,
YAMLOptions yOpts, PitchParams pp,
MarkdownModel mdm) { YAMLOptions yOpts,
MarkdownModel mdm) {
StringBuffer structure = new StringBuffer(mdm.extractDelim(md)); StringBuffer structure = new StringBuffer(mdm.extractDelim(md));
try {
String slideType = mdm.isHorizontal(md) ? try {
mdm.horizDelim() : mdm.vertDelim();
structure = new StringBuffer(mdm.extractDelim(md)) structure = new StringBuffer(mdm.extractDelim(md))
.append(MarkdownModel.MD_SPACER); .append(MarkdownModel.MD_SPACER);
String yamlBg = null; if (yOpts != null && yOpts.hasImageBg()) {
if (yOpts != null && yOpts.hasImageBg()) { String yamlBg = imageService.buildBackground(pp, yOpts);
yamlBg = imageService.buildBackground(pp, yOpts); structure.append(yamlBg).append(MarkdownModel.MD_SPACER);
} else {
String cbg = buildColorMarkdown(dp);
if(cbg != null) {
structure.append(cbg).append(MarkdownModel.MD_SPACER);
}
}
} catch(Exception ex) {
log.warn("build: ex={}", ex);
} }
if (yamlBg != null) { log.debug("build: returning structure={}", structure.toString());
structure.append(yamlBg).append(MarkdownModel.MD_SPACER);
} return structure.toString();
} catch(Exception ex) { }
log.warn("build: ex={}", ex);
public String buildColorBackground(String md,
DelimParams dp,
PitchParams pp,
YAMLOptions yOpts,
MarkdownModel mdm) {
StringBuffer structure = new StringBuffer(mdm.extractDelim(md));
try {
structure = new StringBuffer(mdm.extractDelim(md))
.append(MarkdownModel.MD_SPACER);
String bg = buildColorMarkdown(dp);
if(bg != null) {
structure.append(bg).append(MarkdownModel.MD_SPACER);
}
} catch(Exception ex) {
log.warn("buildColorDelim: ex={}", ex);
}
log.debug("buildColorDelim: returning structure={}", structure.toString());
return structure.toString();
}
private String buildColorMarkdown(DelimParams dp) {
String bgColor = dp.get(MarkdownModel.DELIM_QUERY_COLOR, null);
String bg = MarkdownModel.MD_BG_COLOR + bgColor + MarkdownModel.MD_CLOSER;
return bgColor != null ? bg : null;
} }
return structure.toString();
}
} }