Skip to content

Instantly share code, notes, and snippets.

@wynemo
Last active December 22, 2015 00:09
Show Gist options
  • Save wynemo/6387421 to your computer and use it in GitHub Desktop.
Save wynemo/6387421 to your computer and use it in GitHub Desktop.
using sphinx to generate documents

install sphinx

$ pip install sphinx

use this python script to create a sphinx project

from sphinx import quickstart as qs

d = dict(
    path = '.',
    sep  = True,
    dot  = '_',
    project = 'project_name',
    author = 'author_name',
    version = '',
    release = '',
    suffix = '.rst',
    master = 'index',
    epub = True,
    ext_autodoc = False,
    ext_viewcode = False,
    makefile = True,
    batchfile = True,
    mastertocmaxdepth = 1,
)

qs.generate(d, silent=True, overwrite=False)

now let's see files in this directory

$ tree
.
|-- build
|-- create_project.py
|-- make.bat
|-- Makefile
`-- source
    |-- _static
    |-- _templates
    |-- conf.py
    `-- index.rst

4 directories, 5 files

partial contents of source/index.rst

$ cat source/index.rst    

Welcome to project's documentation!
===================================

Contents:

.. toctree::
   :maxdepth: 1

   linux/index
   golang/index
   node/index

create the subdirectories and files

$ tree
.
|-- build
|-- create_project.py
|-- make.bat
|-- Makefile
`-- source
    |-- _static
    |-- _templates
    |-- conf.py
    |-- golang
    |   |-- build.rst
    |   `-- index.rst
    |-- index.rst
    |-- linux
    |   `-- index.rst
    `-- node
        |-- helloworld.rst
        |-- index.rst
        `-- wisp
            |-- hellonode.rst
            `-- index.rst

8 directories, 12 files

build

make html

clean

make clean

rst files contents:

$ cat source/linux/index.rst
Linux
=====

Linux (Listeni/藞l瑟n蓹ks/ LIN-蓹ks[6][7] or /藞li藧n蕣ks/ LEE-nuuks)[8][9][10]
is a Unix-like computer operating system assembled under the model of free and o
pen source software development and distribution. The defining component of Linu
x is the Linux kernel,[11] an operating system kernel first released on 5 Octobe
r 1991, by Linus Torvalds.[12][13] Since the C compiler that builds Linux and th
e main supporting user space system tools and libraries originated in the GNU Pr
oject, initiated in 1983 by Richard Stallman, the Free Software Foundation prefe
rs the name GNU/Linux when these tools and libraries are used.


$ cat source/golang/index.rst
golang introduction
===================

.. toctree::

    build

$ cat source/golang/build.rst
golang build source
===================

it's very simple::

    go build src_file.go
    


$ cat source/node/index.rst
nodejs introduction
===================

.. toctree::

    helloworld
    wisp/index

$ cat source/node/helloworld.rst
nodejs hellowrold
=================

code::

    // Load the http module to create an http server.
    var http = require('http');

    // Configure our HTTP server to respond with Hello World to all requests.
    var server = http.createServer(function (request, response) {
      //response.writeHead(200, {"Content-Type": "text/plain"});
      response.end("Hello World\n");
    });

    // Listen on port 8000, IP defaults to 127.0.0.1
    server.listen(8000);

    // Put a friendly message on the terminal
    console.log("Server running at http://127.0.0.1:8000/");  


$ cat source/node/wisp/index.rst
using wisp to write node
========================

.. toctree::

    hellonode    
    
$ cat source/node/wisp/hellonode.rst
node helloworld from wisp
=========================

let's see the code::

    (def http (require "http"))

    (def server
      (.createServer http
                     (fn [request response]
                       (.writeHead response {"Content-Type" "text/plain"})
                       (.end response "hello world\n"))))

    (.listen server 8000)

    (.log console "Server running at http://127.0.0.1:8000/")    
@ldong
Copy link

ldong commented Jul 14, 2014

謝!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment