Welcome to Plate Internal documentation!

Contents:

Plate

Introduce

Plate is API Documentations Tool based on Markdown(md) . Convert Slate based on Ruby-Middleman to Python-Flask based. And add some different functions for usages.

https://farm6.staticflickr.com/5820/21503977290_41beb38dcd_b.jpg

Example site is plate-project.github.io.

Features

Plate is very easy for any developers. First of all, follow below Getting Start. And then you have any problems, immediately notify(email, issue board, anything). Always, plate is ready for you.

Getting Start

Support Python Version

  • Python, version 2.7 ~ 3.4

Prerequisites

  • requirements.txt have all libraries for running plate
  • If you install using quick-start.py, automatically install all libraries.
  • manually, install all libraries:
pip install -r requirements.txt

Quick Start with Server

  1. Clone plate to your hard drive with git clone https://github.com/Plate-Project/plate.git

  2. cd plate

  3. Install your API document web pages using quick-start.py .

  4. Start with server: python plate.py

    git clone https://github.com/Plate-Project/plate.git
    cd plate
    python install.py
    ...
    
    Welcome plate v0.2.6
    Start your API Document system.
    
    Typing API document name :<Typing your project>
    what is API document name? is "<your project>"
    
    Rename plate to  "<your project>" ...
    Complete. Enjoy developing.
    
    cd ../<your project>
    python plate.py
    

Quick Start with Static HTML

Start with static html:python pst.py -f <conf file>

python pst.py -f config.json

Config

  • Configuration file for Plate
  • path : ./config.json
KEY DESCRIPTION
PORT Server Port
TITLE <head><title>Title String</title></head>
LOGO_IMG Image path, Display at left top
LOGO_TITLE Logo Title, Display at left top, If you set LOGO_IMG, do not display LOGO_TITLE.
SEARCH_ON true or false, if true available searching
SUPPORT_LANG List Type, Programming Language to display example tabs
API_DOC_PATH Directory Path include markdown API document files.
API_DOC_INDEX_PATH JSON format have Markdown file list.
COPYRIGHT copy right string
FAVICON favicon file name in /static/images
CLIPBOARD Display copy button below codes
STATIC Making Static HTML Section
DIR Directory Path for saving static html.
HTML Static html file name.

Usage

Table of Contents

  • TOC file for setting documents order and file name.
  • Set API_DOC_INDEX_PATH in config.json.
  • path : ./document/index.json

TOC(Table of content) appears as written order. If index.json path is not equal API document file(md) path, must write file path.

https://farm1.staticflickr.com/597/21701121331_01a93bcce4.jpg

Logo and Title

  • You can select the logo image or title text. not BOTH .
  • If set LOGO_IMG in config.json, display specific logo image at left-top.
  • If set LOGO_TITLE in config.json, display specific title text at left-top.
https://farm6.staticflickr.com/5834/22006576161_b2824c99f7_o.png https://farm1.staticflickr.com/563/21996746525_91c7ff8ea2_o.png

If you set both, LOGO_IMG only display.

{
    "LOGO_TITLE"         : "Management API",
    "LOGO_IMG"           : "logo.png"
}

Emphasis Syntax

  • You can the emphasis syntax for using <aside class="CLASSNAME">.
  • CLASSNAME is success or notice or warning.
<aside class="warning">
    Must encrypt password using a key.
</aside>
https://farm1.staticflickr.com/752/23746756075_beff560049.jpg
<aside class="notice">
    No mandatory parameter, return 400 Invalid Parameter
</aside>
https://farm6.staticflickr.com/5623/23450886360_6b8b556766.jpg
<aside class="success">
    Success, return HTTP Status code 200 OK.
</aside>
https://farm6.staticflickr.com/5835/23378773719_56684cabe6.jpg

Internal

Basic Structure

https://farm6.staticflickr.com/5775/22399136477_19138464b0_b.jpg

Internally, Plate have 3 steps :

  • Get API Document
  • Convert markdown to HTML
  • Highlight code according to programming languages

1. Get API Document

  • Read markdown from API Document based on markdown format using API_DOC_PATH and API_DOC_INDEX_PATH in config.json.
  • Sort by index.json of API_DOC_INDEX_PATH.

2. Convert markdown to HTML

  • Convert markdown to HTML using markdown python module
  • Use markdown extensions : - fence_codes : markdown code block to html pre tag - tables : markdown table syntax to html table tag
def conv_md_to_html(md_text):
    import markdown
    return markdown.markdown(md_text, extensions=["fenced_code", "tables"])

3. Highlight code according to programming languages

  • Use pygemnts for highlighting codes
  • Support various programming languages and markup.
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.lexers import JavaLexer
from pygments.formatters import HtmlFormatter

highlighted = highlight(code, PythonLexer(), HtmlFormatter())
highlighted = highlight(code, JavaLexer(), HtmlFormatter())

Realtime monitoring API Document

https://farm6.staticflickr.com/5740/22089514844_4088d51454_o.png

For monitoring the modification of API Documents, use wachdog . After the server start, the watchdog start and monitor all documents in API_DOC_PATH of config.json . When the server stop, also the watchdog stop. In this process, use method watchdocs.watch_api_doc.start_watch and watchdocs.watch_api_doc.stop_watch .

If raise any modification fo files, run watchdocs.document_trace_handler.on_modified method. In this method, enqueue a event about the modification of any file to document_trace_queue . It is a instance of DocumentTraceQueue singleton class.

And then, receive new request from user, Plate check document_trace_queue whether a event exist or not. If any event in queue, Plate load all API Documents and convert to html.

Advanced

Use postman collection json

If use postman2md library, easily convert postman collection json for testing API to markdown. And then you can use converted markdown files as API Documents of Plate. Now must use markdown converting by postman2md, future we will support postman collection json as the subject of plate. Have any interest of postman2md, see https://github.com/Plate-Project/postman2md and welcome your contributions at any time, with issues.

import postman2md
# create multi markdown file in the directory.
postman2md.convert(postman_file="example.json.postman_collection")

# create merged markdown file in the directory.
postman2md.convert(postman_file="example.json.postman_collection", multi_file=False)

Modules

Common

class plate.common.config.Config(result)

Read JSON Format config file.

static load_conf(conf_file_path)

Read .json file

Parameters:conf_file_path.json file path
Returns:conf instance
plate.common.convmd2html.convert_md_to_html(md_text)

Convert markdown text to HTML

Parameters:md_text – markdown text
Returns:html
class plate.common.singleton_meta.SingletonMeta

Singleton Base Class

Example:

class DocumentTraceQueue(object):
    from common import Singleton
    __metaclass__ = Singleton
plate.common.syntax_highlighting.syntax_highlight(lang, code)

code highlighting HTML Format

Parameters:
  • lang – programming language
  • code – code(not html)
Returns:

highlighted code(html format)

API Document

class plate.api_document.APIDocument(config=None)

Making API Document

create_api_docs()

Convert API Document to HTML.

Returns:OrderedDict instance.
highlight_syntax(soup)

Highlight code syntax.

Parameters:soup – bs4 instance
Returns:bs4 instance
modify_html(soup)

Modify HTML

Parameters:soup – bs4 instance
Returns:HTML
read_index(index_file_path)

Read API Document index file such as index.json.

Parameters:index_file_path – index file path
Returns:JSON of index file(index.json)
total_reload_docs()

Reload all API Document files.

Watchdocs

class plate.watchdocs.document_trace_handler.DocumentTraceHandler(tracing_files=None)

DocumentTraceHandler is event handler for API Document files.

on_modified(event)

Event handler about modified. If raise modify on api document file or index file such as index.json, enqueue event to DocumentTraceQueue.

Parameters:event – the event about event handler
class plate.watchdocs.document_trace_queue.DocumentTraceQueue

Queue of modification, inserted, deleted document.

clear()

Remove all trace_queue

count()

Count of trace_queue

Returns:count
dequeue()

Dequeue event Return the copy of top event in trace_queue

Returns:event
enqueue(event, is_index_file)

Enqueue event to trace_queue

Parameters:
  • event – insert/update/del event
  • is_index_file – True or False
is_empty()

Is empty trace_queue?

Returns:True or False
class plate.watchdocs.api_document_observer.APIDocumentObserver(doc_path=None, doc_index_path=None, doc_file_path_list=None)

APIDocumentObserver is observer of API Documents.

is_started

After run start_watch(), is_started is True, or False.

Returns:True | False
start_watch()

Start watch docs

stop_watch()

Stop watch docs

class plate.watchdocs.document_trace_file.DocumentTraceFile(tracing_file_path, is_index_file=False)

Contributing

Any suggestions Submit a issue. Show me the pull requests.

Version

Release : 0.2

Version : 0.2.6

Change Log

  • V0.2.6
    • Add Test Cases.
  • V0.2.5
    • Change basic structures.
    • Add unit testing.
  • v0.2.4
    • Apply Sphinx

License

Copyright 2015 Plate

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Indices and tables