Search in sources :

Example 1 with RmdTemplate

use of org.rstudio.studio.client.rmarkdown.model.RmdTemplate 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 RmdTemplate

use of org.rstudio.studio.client.rmarkdown.model.RmdTemplate in project rstudio by rstudio.

the class TextEditingTargetRMarkdownHelper method getTemplateFormat.

// Return the selected template and format given the YAML front matter
public RmdSelectedTemplate getTemplateFormat(String yaml) {
    // template here just turns off the template-specific UI format editor.
    try {
        YamlTree tree = new YamlTree(yaml);
        boolean isShiny = false;
        if (tree.getKeyValue(RmdFrontMatter.KNIT_KEY).length() > 0)
            return null;
        List<String> outFormats = getOutputFormats(tree);
        // Find the template appropriate to the first output format listed.
        // If no output format is present, assume HTML document (as the 
        // renderer does).
        String outFormat = outFormats == null ? RmdOutputFormat.OUTPUT_HTML_DOCUMENT : outFormats.get(0);
        RmdTemplate template = getTemplateForFormat(outFormat);
        if (template == null)
            return null;
        // a Shiny format
        if (template.getFormat(outFormat).getExtension().equals("html") && tree.getKeyValue(RmdFrontMatter.RUNTIME_KEY).equals(RmdFrontMatter.SHINY_RUNTIME)) {
            isShiny = true;
        }
        return new RmdSelectedTemplate(template, outFormat, isShiny);
    } catch (Exception e) {
        Debug.log("Warning: Exception thrown while parsing YAML:\n" + yaml);
    }
    return null;
}
Also used : RmdTemplate(org.rstudio.studio.client.rmarkdown.model.RmdTemplate) YamlTree(org.rstudio.studio.client.rmarkdown.model.YamlTree) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

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