use of com.twosigma.beakerx.mimetype.MIMEContainer in project beakerx by twosigma.
the class HtmlMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String commandCodeBlock = param.getCommandCodeBlock();
if (commandCodeBlock == null) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, String.format(USAGE_ERROR_MSG, HTML));
}
MIMEContainer html = HTML("<html>" + commandCodeBlock + "</html>");
return new MagicCommandResult(MagicCommandOutcomeItem.Status.OK, html);
}
use of com.twosigma.beakerx.mimetype.MIMEContainer in project beakerx by twosigma.
the class MIMEContainerFactory method createMIMEContainersFromObject.
private static List<MIMEContainer> createMIMEContainersFromObject(final Object data) {
Object input = DisplayerDataMapper.convert(data);
if (input instanceof DisplayableWidget) {
((DisplayableWidget) input).display();
return HIDDEN_MIME;
}
TableDisplay table = getTableDisplay(input);
if (table != null) {
table.display();
return HIDDEN_MIME;
}
if (input instanceof Collection) {
return singletonList(MIMEContainer.Text(collectionToString((Collection<?>) input)));
}
if (input instanceof XYGraphics) {
new Plot().add((XYGraphics) input).display();
return HIDDEN_MIME;
}
if (input instanceof MIMEContainer) {
return singletonList((MIMEContainer) input);
}
return Displayers.display(input).entrySet().stream().map(item -> new MIMEContainer(item.getKey(), item.getValue())).collect(Collectors.toList());
}
use of com.twosigma.beakerx.mimetype.MIMEContainer in project beakerx by twosigma.
the class MagicCommandExecutor method publishOutcome.
private static void publishOutcome(KernelFunctionality kernel, Message message, int executionCount, MagicCommandOutcomeItem item, boolean hasError) {
if (item.getMIMEContainer().isPresent()) {
if (item.getOutcome().equals(MagicCommandOutcomeItem.Outcome.OUTPUT)) {
kernel.publish(Collections.singletonList(MessageCreator.buildOutputMessage(message, (String) item.getMIMEContainer().get().getData(), hasError)));
} else {
MIMEContainer mimeContainer = item.getMIMEContainer().get();
kernel.publish(Collections.singletonList(MessageCreator.buildMessage(message, singletonList(mimeContainer), executionCount)));
}
}
}
use of com.twosigma.beakerx.mimetype.MIMEContainer in project beakerx by twosigma.
the class JavaScriptMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String commandCodeBlock = param.getCommandCodeBlock();
MIMEContainer result = JavaScript(commandCodeBlock);
return new MagicCommandResult(MagicCommandOutcomeItem.Status.OK, result);
}
use of com.twosigma.beakerx.mimetype.MIMEContainer in project beakerx by twosigma.
the class MIMEContainerFactoryTest method integerAsTextHtml.
@Test
public void integerAsTextHtml() throws Exception {
// given
Displayers.register(Integer.class, new Displayer<Integer>() {
@Override
public Map<String, String> display(Integer value) {
return new HashMap<String, String>() {
{
put(TEXT_HTML, "<div><h1>" + value + "</h1></div>");
}
};
}
});
// when
List<MIMEContainer> result = MIMEContainerFactory.createMIMEContainers(2);
// then
assertThat(result.get(0)).isEqualTo(new MIMEContainer(TEXT_HTML, "<div><h1>" + 2 + "</h1></div>"));
}
Aggregations