def get_library_keywords(library):

    kwdb = current_app.kwdb
    query_pattern = flask.request.args.get('pattern', "*").strip().lower()
    keywords = kwdb.get_keywords(query_pattern)
    result = []
    library = library.strip().lower()
    for (keyword_library, keyword_name, keyword_doc, keyword_args) in keywords:
        if library == "" or library == keyword_library.strip().lower():
            api_kw_url = flask.url_for(".get_library_keyword", 
                                       library=keyword_library, 
                                       keyword=keyword_name)
            api_lib_url = flask.url_for(".get_library_keywords",
                                        library=keyword_library)
            try:
                htmldoc = DocToHtml("ROBOT")(keyword_doc)
            except Exception, e:
                htmldoc = "bummer"

            result.append({"library": keyword_library, 
                           "name": keyword_name, 
                           "synopsis": keyword_doc.strip().split("\n")[0],
                           "doc": keyword_doc,
                           "htmldoc": htmldoc,
                           "args": keyword_args,
                           "api_keyword_url": api_kw_url,
                           "api_library_url": api_lib_url})
Example #2
0
    def get_library_keywords(self, collection_id):

        query_pattern = flask.request.args.get('pattern', "*").strip().lower()
        keywords = current_app.kwdb.get_keywords(query_pattern)

        req_fields = flask.request.args.get('fields', "*").strip().lower()
        if (req_fields == "*"):
            fields = ("collection_id", "library", "name", "synopsis", "doc",
                      "htmldoc", "args", "doc_keyword_url", "api_keyword_url",
                      "api_library_url")
        else:
            fields = [x.strip() for x in req_fields.split(",")]

        result = []
        for (keyword_collection_id, keyword_collection_name, keyword_name,
             keyword_doc, keyword_args) in keywords:
            if collection_id == "" or int(
                    collection_id) == keyword_collection_id:
                data = {}
                if ("collection_id" in fields):
                    data["collection_id"] = keyword_collection_id
                if ("library" in fields):
                    data["library"] = keyword_collection_name
                if ("name" in fields): data["name"] = keyword_name
                if ("synopsis" in fields):
                    data["synopsis"] = keyword_doc.strip().split("\n")[0]
                if ("doc" in fields): data["doc"] = keyword_doc
                if ("args" in fields): data["args"] = keyword_args

                if ("doc_keyword_url" in fields):
                    data["doc_keyword_url"] = flask.url_for(
                        "doc.doc_for_library",
                        collection_id=keyword_collection_id,
                        keyword=keyword_name)
                if ("api_keyword_url" in fields):
                    data["api_keyword_url"] = flask.url_for(
                        ".get_library_keyword",
                        collection_id=keyword_collection_id,
                        keyword=keyword_name)

                if ("api_library_url" in fields):
                    data["api_library_url"] = flask.url_for(
                        ".get_library_keywords",
                        collection_id=keyword_collection_id)
                if ("htmldoc" in fields):
                    try:
                        data["htmldoc"] = DocToHtml("ROBOT")(keyword_doc)
                    except Exception as e:
                        data["htmldoc"] = ""
                        htmldoc = "bummer", e

                result.append(data)

        return flask.jsonify(keywords=result)
def get_keyword_doc(keyword):
    title = keyword.name.strip("*").strip()
    title_html = f"<strong>{title}</strong>"
    if keyword.args:
        title += " " + ", ".join(keyword.args)
        title_html += " " + ", ".join(keyword.args)

    body = ""
    if keyword.doc:
        body = "\n\n" + keyword.doc

    return {
        "text/plain":
        title + "\n\n" + body,
        "text/html":
        f"<p>{title_html}</p>" +
        NAME_REGEXP.sub(lambda m: f"<code>{m.group(1)}</code>",
                        DocToHtml(keyword.doc_format)(body)),
    }
Example #4
0
def get_keyword_doc(keyword):
    title = keyword.name.strip('*').strip()
    title_html = f'<strong>{title}</strong>'
    if keyword.args:
        title += ' ' + ', '.join(keyword.args)
        title_html += ' ' + ', '.join(keyword.args)
    body = ''
    if keyword.doc:
        if isinstance(keyword.doc, Documentation):
            body = '\n\n' + keyword.doc.value.replace('\\n', '\n')
        else:
            body = '\n\n' + keyword.doc
    return {
        'text/plain': title + '\n\n' + body,
        'text/html': f'<p>{title_html}</p>' + NAME_REGEXP.sub(
            lambda m: f'<code>{m.group(1)}</code>',
            DocToHtml(keyword.doc_format)(body),
        ),
    }
Example #5
0
def create_html_doc(doc, format):
    from robot.libdocpkg.htmlwriter import DocToHtml

    formatter = DocToHtml(format)
    return formatter(doc)
Example #6
0
def doc_to_html(doc, doc_format="ROBOT"):
    """Convert documentation to HTML"""
    from robot.libdocpkg.htmlwriter import DocToHtml
    return DocToHtml(doc_format)(doc)
Example #7
0
 def html_doc(self, doc_format: str = "ROBOT") -> str:
     return DocToHtml(doc_format)(self.doc) if self.doc else ""
Example #8
0
 def html_doc(self) -> str:
     return DocToHtml("ROBOT")(self.doc) if self.doc else ""