Building document with the Sphinx public edtion

52
Building document with the Sphinx 2013-09 Public edtion Wednesday, September 11, 13

description

某社で社内向けにsphinxを紹介した時のスライドです。

Transcript of Building document with the Sphinx public edtion

Page 1: Building document with the Sphinx public edtion

Building documentwith the Sphinx

2013-09Public edtion

Wednesday, September 11, 13

Page 2: Building document with the Sphinx public edtion

この資料?• チームでアプリケーションつくってます

• APIリファレンスを管理しやすく・見やすくしよう

• チームメンバ向けにSphinxを紹介した時のスライドです

• 公開向けに加工しました

• 画像のぼかし

• 字幕

2Wednesday, September 11, 13

Page 3: Building document with the Sphinx public edtion

2008 Word3

2008年、プロジェクトのドキュメントはWordで作られていましたこの方式の欠点はみなさんご存知のとおりでしょう

Wednesday, September 11, 13

Page 4: Building document with the Sphinx public edtion

2010 Dokuwiki4

2010年のプロジェクトではphpのアプリケーションを使いました。版の管理、手軽さは飛躍的に向上しました、環境の管理が必要でした。

Wednesday, September 11, 13

Page 5: Building document with the Sphinx public edtion

2012 markdown based5

2012年にはmarkdownを変換する自作のRubyアプリケーションでAPIリファレンスを提供しました。

Wednesday, September 11, 13

Page 6: Building document with the Sphinx public edtion

2013 Github pages ?6

そして2013年、GithubのWikiにリファレンスを書き始めましたが...

Wednesday, September 11, 13

Page 7: Building document with the Sphinx public edtion

Github Pages are...• Poor search

• Grow much bigger!!

• kindless to reading

• No indexing

• No relasionship

7

本当にそれでいいのでしょうか、いいえ

Wednesday, September 11, 13

Page 8: Building document with the Sphinx public edtion

Lighitweight Documentation

8

http://www.slideshare.net/shimizukawa/blockdiag-jus20116

もっとコラボレーションしやすいものがあるのでは?

Wednesday, September 11, 13

Page 9: Building document with the Sphinx public edtion

2013 Sphinx!!9

そうだ、Sphinxでいこうよ。これはGithub wikiのMarkdownを単純に変換したものです。

Wednesday, September 11, 13

Page 10: Building document with the Sphinx public edtion

The Sphinx

10

• Document Builder

• Python project

• install with pip, easy_install

• (But) Don’t need any knowledge of Python.

• Write once publish anywere.(with pahdoc)

• write reST (reStructuredText)or Markdown

• to html, epub, man, TeX, etc...

たぶんすばらしいSphinxの世界

Wednesday, September 11, 13

Page 11: Building document with the Sphinx public edtion

Tool: Pandocuniversal docoment converter

11

ありがとうPandoc

Wednesday, September 11, 13

Page 12: Building document with the Sphinx public edtion

Getting startedwith the Sphinx !!

今夜できる、Sphinx ドキュメンテーション

Wednesday, September 11, 13

Page 13: Building document with the Sphinx public edtion

sphinx-quickstart $ sphinx-quickstart

Welcome to the Sphinx 1.2b1 quickstart utility.

Please enter values for the following settings (just press Enter to

accept a default value, if one is given in brackets).

Enter the root path for documentation.

> Root path for the documentation [.]:

13

簡単スタートツール、sphinx-quickstartとの対話をフルコーラスでご覧ください

Wednesday, September 11, 13

Page 14: Building document with the Sphinx public edtion

You have two options for placing the build directory for Sphinx output.

Either, you use a directory "_build" within the root path, or you separate

"source" and "build" directories within the root path.

> Separate source and build directories (y/N) [n]: y

14

赤い所が入力箇所!といっても、ほとんど入力する必要は無いんだけどね。

Wednesday, September 11, 13

Page 15: Building document with the Sphinx public edtion

The project name will occur in several places in the built documentation.

> Project name: sphinx_sinatra_example

> Author name(s): sawanoboly

15

まだ対話が続くよ、あと6ページほどやる。

Wednesday, September 11, 13

Page 16: Building document with the Sphinx public edtion

Sphinx has the notion of a "version" and a "release" for the

software. Each version can have multiple releases. For example, for

Python the version is something like 2.5 or 3.0, while the release is

something like 2.5.1 or 3.0a1. If you don't need this dual structure,

just set both to the same value.

> Project version: 1.0

> Project release [1.0]:

16

まだ対話が続くよ、あと5ページほど。

Wednesday, September 11, 13

Page 17: Building document with the Sphinx public edtion

The file name suffix for source files. Commonly, this is either ".txt"

or ".rst". Only files with this suffix are considered documents.

> Source file suffix [.rst]:

17

まだ対話が続くよ、あと4ページほど。 ああ、ここは好みで.txtに変えたりするね。

Wednesday, September 11, 13

Page 18: Building document with the Sphinx public edtion

One document is special in that it is considered the top node of the

"contents tree", that is, it is the root of the hierarchical structure

of the documents. Normally, this is "index", but if your "index"

document is a custom template, you can also set this to another filename.

> Name of your master document (without suffix) [index]:

18

まだ対話が続くよ、あと3ページほど。

Wednesday, September 11, 13

Page 19: Building document with the Sphinx public edtion

Sphinx can also add configuration for epub output:

> Do you want to use the epub builder (y/N) [n]:

19

まだ対話が続くよ、あと2ページほど。オマケでepub出力ができるよ。kindleに入れようぜ。

Wednesday, September 11, 13

Page 20: Building document with the Sphinx public edtion

Please indicate if you want to use one of the following Sphinx extensions:

> autodoc: automatically insert docstrings from modules (y/N) [n]: y

> doctest: automatically test code snippets in doctest blocks (y/N) [n]:

> intersphinx: link between Sphinx documentation of different projects (y/N) [n]:

> todo: write "todo" entries that can be shown or hidden on build (y/N) [n]:

> coverage: checks for documentation coverage (y/N) [n]:

> pngmath: include math, rendered as PNG images (y/N) [n]:

> mathjax: include math, rendered in the browser by MathJax (y/N) [n]:

> ifconfig: conditional inclusion of content based on config values (y/N) [n]:

> viewcode: include links to the source code of documented Python objects (y/N) [n]: Y

20

まだ対話が続くよ、あと1ページほど。いろんなモジュールあるけどスルーでOK、viewcodeはアリかな。

Wednesday, September 11, 13

Page 21: Building document with the Sphinx public edtion

A Makefile and a Windows command file can be generated for you so that you

only have to run e.g. `make html' instead of invoking sphinx-build

directly.

> Create Makefile? (Y/n) [y]: y

> Create Windows command file? (Y/n) [y]: n

21

Makefileを作って終わりですいざSphinx!

Wednesday, September 11, 13

Page 22: Building document with the Sphinx public edtion

$ tree

├── Makefile # document build tasks

├── build # output directory

└── source # reST files directory

├── _static

├── _templates

├── conf.py # Configration of sphinx for build

└── index.rst # TopPage

22

初期のファイル構成こんな感じです。すごい、もうビルドできるんだって!

Wednesday, September 11, 13

Page 23: Building document with the Sphinx public edtion

$ make htmlsphinx-build -b html -d build/doctrees source build/html

Making output directory...

Running Sphinx v1.2b1

loading pickled environment... not yet created

building [html]: targets for 1 source files that are out of date

updating environment: 1 added, 0 changed, 0 removed

reading sources... [100%] index

looking for now-outdated files... none foundpickling environment... done

checking consistency... done

preparing documents... done

writing output... [100%] index

writing additional files... genindex search

copying static files... done

dumping search index... done

dumping object inventory... donebuild succeeded.

23

make html

早速ビルドだ、やったぜ!

Wednesday, September 11, 13

Page 24: Building document with the Sphinx public edtion

$ tree build/html/

build/html/

├── _sources

│ └── index.txt

├── _static

│ ├── ajax-loader.gif

│ ├── basic.css

│ ├── comment-bright.png

│ ├── comment-close.png

│ ├── comment.png

│ ├── default.css

│ ├── doctools.js

│ ├── down-pressed.png

│ ├── down.png

│ ├── file.png

│ ├── jquery.js

│ ├── minus.png

│ ├── plus.png

│ ├── pygments.css

│ ├── searchtools.js

│ ├── sidebar.js

│ ├── underscore.js

│ ├── up-pressed.png

│ ├── up.png

│ └── websupport.js

├── genindex.html

├── index.html

├── objects.inv

├── search.html

└── searchindex.js

2 directories, 26 files

24

build/htmlの下にファイルが現れた!よし、開いてみよう

Wednesday, September 11, 13

Page 25: Building document with the Sphinx public edtion

25

open build/html/index.html私のドキュメントにようこそ

すでにカッコイイじゃないですかー

Wednesday, September 11, 13

Page 26: Building document with the Sphinx public edtion

write first page

では書きたいことを書きたいように書いていこう

Wednesday, September 11, 13

Page 27: Building document with the Sphinx public edtion

add name to index.rstContents:

.. toctree::

:maxdepth: 2

27

Contents:

.. toctree::

:maxdepth: 2

public

APIリソースのpublicについて書いていくよ準備はindex.rstに一行追加するだけでいいんだ。

Wednesday, September 11, 13

Page 28: Building document with the Sphinx public edtion

write source/public.rst

28

※ convert from markdown by pandocmarkdown版がもうあるので、pandocで変換してみたのがこちらです

Wednesday, September 11, 13

Page 29: Building document with the Sphinx public edtion

Rebuild$ make html

-- snip --

reading sources... [100%] public

-- snip --

writing output... [100%] public

-- snip --

Build finished. The HTML pages are in build/html.

29

さあ、もう一度ビルド!

Wednesday, September 11, 13

Page 30: Building document with the Sphinx public edtion

open index.html30

見出しが! 見出しが並んだよ!ああ、そうだねぼうや。

Wednesday, September 11, 13

Page 31: Building document with the Sphinx public edtion

mark upto index

索引があったらいいのに本みたいに

Wednesday, September 11, 13

Page 32: Building document with the Sphinx public edtion

add index before contentPOST /v1/public/*****************

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Resets the hogehoge

32

.. index::

single: public/reset

POST /v1/public/******************

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Resets the hogehoge

そんなときは索引から飛びたい見出しの前にすこしおまじないをかけばうまくいくんだ。

Wednesday, September 11, 13

Page 33: Building document with the Sphinx public edtion

build and opengenindex.html

33

自動でリンク付きの索引を?なんて素晴らしいんだ。

Wednesday, September 11, 13

Page 34: Building document with the Sphinx public edtion

Search!

検索機能もついてくるといっても、必要な手続きやコツがあるんじゃないのかい?

Wednesday, September 11, 13

Page 35: Building document with the Sphinx public edtion

Nothing to do

いいえ、みなさんは何もする必要がありません。

Wednesday, September 11, 13

Page 36: Building document with the Sphinx public edtion

search for all documents36

ドキュメントはビルドするだけで、searchの対象なんだ。※日本語対応してるかを見てない

Wednesday, September 11, 13

Page 37: Building document with the Sphinx public edtion

Show raw reST file

少しの修正を施したいけど、reSTの書き方をど忘れしたって?

Wednesday, September 11, 13

Page 38: Building document with the Sphinx public edtion

38

きっとshow source リンクをクリックするんだ。

Wednesday, September 11, 13

Page 39: Building document with the Sphinx public edtion

View reST on web browser

39

ほら、reSTファイルだ。※コンフィグで有効/無効

Wednesday, September 11, 13

Page 40: Building document with the Sphinx public edtion

DocumentVersioning

アプリケーションのバージョンごとに別のドキュメントにする必要が求められることがある。

Wednesday, September 11, 13

Page 41: Building document with the Sphinx public edtion

sphinx-build(Modify Makefile)

Makefileで、ちょちょいのちょいなんだけど

Wednesday, September 11, 13

Page 42: Building document with the Sphinx public edtion

Modify BUILDDIRBUILDDIR = build

42

BUILDDIR = build/1.0

他に良いやり方知ってる人教えてください

Wednesday, September 11, 13

Page 43: Building document with the Sphinx public edtion

$ make html

sphinx-build -b html -d build/1.0/doctrees source build/1.0/html

-- snip --

Build finished. The HTML pages are in build/1.0/html.

43

一応べつのディレクトリとして出力できるんだけど

Wednesday, September 11, 13

Page 44: Building document with the Sphinx public edtion

upgrademejour version

このやり方があんまりスマートにも思えないんだ

Wednesday, September 11, 13

Page 45: Building document with the Sphinx public edtion

conf.py and Makefile## conf.py

version = '1.1'

release = '1.1'

## Makefile

BUILDDIR = build/1.1

45

conf.pyはいいとしてもね

Wednesday, September 11, 13

Page 46: Building document with the Sphinx public edtion

example of version selection!but modify template manually maybe...

46

Pythonの公式サイトみたいにしたいね

Wednesday, September 11, 13

Page 47: Building document with the Sphinx public edtion

Appendix.1Dash.app

知ってるかい Dash.app

Wednesday, September 11, 13

Page 48: Building document with the Sphinx public edtion

Dash.app48

ローカル本棚だよ

Wednesday, September 11, 13

Page 49: Building document with the Sphinx public edtion

import from sphinx49

doc2dashでググれ

Wednesday, September 11, 13

Page 50: Building document with the Sphinx public edtion

Appendix.2Publish to heroku

htmlにしたら何処かでホスト必要がある、herokuに置いてしまう方法を紹介しよう。

Wednesday, September 11, 13

Page 51: Building document with the Sphinx public edtion

static html publishing with sinatrahttp://qiita.com/sawanoboly@github/items/be1dbc9f19e93e4b62cf

51

今じゃないけど。

Wednesday, September 11, 13

Page 52: Building document with the Sphinx public edtion

Thanks

ありがとう

Wednesday, September 11, 13