All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.reprezen.genflow.openapi3.doc.DocHelper Maven / Gradle / Ivy

/**
 * Copyright © 2013, 2016 Modelsolv, Inc.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is, and remains the property
 * of ModelSolv, Inc. See the file license.html in the root directory of
 * this project for further information.
 */
package com.reprezen.genflow.openapi3.doc;

import com.reprezen.genflow.openapi3.doc.Helper;
import com.reprezen.genflow.openapi3.doc.HelperHelper;
import com.reprezen.genflow.openapi3.doc.HtmlHelper;
import java.util.Collections;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.IntegerRange;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.pegdown.Extensions;
import org.pegdown.PegDownProcessor;

@SuppressWarnings("all")
public class DocHelper implements Helper {
  @Extension
  private HtmlHelper htmlHelper;
  
  @Override
  public void init() {
    this.htmlHelper = HelperHelper.getHtmlHelper();
  }
  
  private static int extensions = ((((((Extensions.SMARTS + Extensions.QUOTES) + Extensions.AUTOLINKS) + Extensions.TABLES) + 
    Extensions.FENCED_CODE_BLOCKS) + Extensions.STRIKETHROUGH) + Extensions.ATXHEADERSPACE);
  
  @Extension
  private PegDownProcessor _pegDownProcessor = new PegDownProcessor(DocHelper.extensions);
  
  public String getDocHtml(final String doc) {
    String _nonEmpty = null;
    if (doc!=null) {
      _nonEmpty=this.nonEmpty(doc);
    }
    String _string = null;
    if (_nonEmpty!=null) {
      _string=_nonEmpty.toString();
    }
    String _processMarkdown = null;
    if (_string!=null) {
      _processMarkdown=this.processMarkdown(_string);
    }
    return this.wrap(_processMarkdown);
  }
  
  public String getDocHtml(final String summary, final String doc) {
    String _join = IterableExtensions.join(IterableExtensions.filterNull(Collections.unmodifiableList(CollectionLiterals.newArrayList(summary, doc))), "\n\n");
    String _processMarkdown = null;
    if (_join!=null) {
      _processMarkdown=this.processMarkdown(_join);
    }
    return this.wrap(_processMarkdown);
  }
  
  public String nonEmpty(final String text) {
    String _xifexpression = null;
    boolean _isEmpty = text.trim().isEmpty();
    if (_isEmpty) {
      _xifexpression = null;
    } else {
      _xifexpression = text;
    }
    return _xifexpression;
  }
  
  private String wrap(final String doc) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("
"); _builder.append(doc); _builder.append("
"); return _builder.toString(); } private String processMarkdown(final String md) { IntegerRange _upTo = new IntegerRange(1, 3); for (final Integer i : _upTo) { try { return this._pegDownProcessor.markdownToHtml(md); } catch (final Throwable _t) { if (_t instanceof Exception) { } else { throw Exceptions.sneakyThrow(_t); } } } StringConcatenation _builder = new StringConcatenation(); _builder.append("Markdown processing error; raw documentation:
"); String _htmlEscape = this.htmlHelper.htmlEscape(md); _builder.append(_htmlEscape); _builder.append("
"); return _builder.toString(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy