Search in sources :

Example 1 with RmdFrontMatterOutputOptions

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);
}
Also used : RmdTemplate(org.rstudio.studio.client.rmarkdown.model.RmdTemplate) RmdFrontMatterOutputOptions(org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)

Example 2 with RmdFrontMatterOutputOptions

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);
                }
            }
        }
    }
}
Also used : RmdTemplateFormatOption(org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) RmdFrontMatterOutputOptions(org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)

Example 3 with RmdFrontMatterOutputOptions

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;
}
Also used : RmdTemplateFormatOption(org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption) RmdFrontMatterOutputOptions(org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

RmdFrontMatterOutputOptions (org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)3 JsArrayString (com.google.gwt.core.client.JsArrayString)2 RmdTemplateFormatOption (org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption)2 RmdTemplate (org.rstudio.studio.client.rmarkdown.model.RmdTemplate)1