use of org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions in project rstudio by rstudio.
the class TextEditingTargetRMarkdownHelper method setOutputFormat.
private void setOutputFormat(RmdFrontMatter frontMatter, String format, final CommandWithArg<String> onCompleted) {
// to the list and transfer any applicable options
if (!JsArrayUtil.jsArrayStringContains(frontMatter.getFormatList(), format)) {
RmdTemplate template = getTemplateForFormat(format);
RmdFrontMatterOutputOptions opts = RmdFrontMatterOutputOptions.create();
if (template != null) {
opts = transferOptions(frontMatter, template, format);
}
frontMatter.setOutputOption(format, opts);
}
frontMatterToYAML(frontMatter, format, onCompleted);
}
use of org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions in project rstudio by rstudio.
the class RmdTemplateOptionsWidget method applyFrontMatter.
private void applyFrontMatter(RmdFrontMatter frontMatter) {
frontMatter_ = frontMatter;
frontMatterCache_ = new HashMap<String, String>();
ensureOptionsCache();
JsArrayString formats = frontMatter.getFormatList();
for (int i = 0; i < formats.length(); i++) {
String format = formats.get(i);
RmdFrontMatterOutputOptions options = frontMatter.getOutputOption(format);
JsArrayString optionList = options.getOptionList();
for (int j = 0; j < optionList.length(); j++) {
String option = optionList.get(j);
String value = options.getOptionValue(option);
frontMatterCache_.put(format + ":" + option, value);
if (optionCache_.containsKey(option)) {
// If the option is specifically labeled as transferable
// between formats, add a generic key to be applied to other
// formats
RmdTemplateFormatOption formatOption = optionCache_.get(option);
if (formatOption.isTransferable()) {
frontMatterCache_.put(option, value);
}
}
}
}
}
use of org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions in project rstudio by rstudio.
the class TextEditingTargetRMarkdownHelper method transferOptions.
private RmdFrontMatterOutputOptions transferOptions(RmdFrontMatter frontMatter, RmdTemplate template, String format) {
RmdFrontMatterOutputOptions result = RmdFrontMatterOutputOptions.create();
// loop over each option applicable to the new format; if it's
// transferable, try to find it in one of the other formats
JsArrayString options = template.getFormat(format).getOptions();
for (int i = 0; i < options.length(); i++) {
String optionName = options.get(i);
RmdTemplateFormatOption option = template.getOption(optionName);
if (!option.isTransferable())
continue;
// option is transferable, is it present in another front matter entry?
JsArrayString formats = frontMatter.getFormatList();
for (int j = 0; j < formats.length(); j++) {
RmdFrontMatterOutputOptions outOptions = frontMatter.getOutputOption(formats.get(j));
if (outOptions == null)
continue;
String val = outOptions.getOptionValue(optionName);
if (val != null)
result.setOptionValue(option, val);
}
}
return result;
}
Aggregations