Search in sources :

Example 1 with RmdOutputInfo

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

the class RSConnectPublishButton method renderThenPublish.

// for static content only: perform a just-in-time render if necessary and
// then publish the content
private void renderThenPublish(final String target, final RSConnectDeploymentRecord previous) {
    // prevent re-entrancy
    if (rmdInfoPending_)
        return;
    final Command renderCommand = new Command() {

        @Override
        public void execute() {
            publishAfterRmdRender_ = previous;
            rmdRenderPending_ = true;
            anyRmdRenderPending_ = true;
            if (commands_.knitDocument().isEnabled())
                commands_.knitDocument().execute();
            else if (commands_.previewHTML().isEnabled())
                commands_.previewHTML().execute();
            else
                display_.showErrorMessage("Can't Render Document", "RStudio cannot render " + target + " for publishing.");
        }
    };
    rmdInfoPending_ = true;
    rmdServer_.getRmdOutputInfo(target, new ServerRequestCallback<RmdOutputInfo>() {

        @Override
        public void onResponseReceived(RmdOutputInfo response) {
            if (response.isCurrent()) {
                RenderedDocPreview preview = new RenderedDocPreview(target, response.getOutputFile(), true);
                events_.fireEvent(RSConnectActionEvent.DeployDocEvent(preview, RSConnect.CONTENT_TYPE_DOCUMENT, previous));
            } else {
                renderCommand.execute();
            }
            rmdInfoPending_ = false;
        }

        @Override
        public void onError(ServerError error) {
            // if we failed to figure out whether we need to do a re-render, 
            // assume one is necessary
            Debug.logError(error);
            renderCommand.execute();
            rmdInfoPending_ = false;
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) RmdOutputInfo(org.rstudio.studio.client.rmarkdown.model.RmdOutputInfo) RenderedDocPreview(org.rstudio.studio.client.rsconnect.model.RenderedDocPreview)

Aggregations

Command (com.google.gwt.user.client.Command)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 RmdOutputInfo (org.rstudio.studio.client.rmarkdown.model.RmdOutputInfo)1 RenderedDocPreview (org.rstudio.studio.client.rsconnect.model.RenderedDocPreview)1 ServerError (org.rstudio.studio.client.server.ServerError)1