Skip to content

Instantly share code, notes, and snippets.

@salaros
Last active November 13, 2017 00:27
Show Gist options
  • Save salaros/fb851bcd8c3bd5ef1262995246a74df8 to your computer and use it in GitHub Desktop.
Save salaros/fb851bcd8c3bd5ef1262995246a74df8 to your computer and use it in GitHub Desktop.
Add Sphinx -> HTML document generation to a PHP project
#!/bin/bash
mkdir -p ./docs/_static
touch ./docs/_static/.gitkeep
mkdir -p ./docs/_build
touch ./docs/_build/.gitkeep
echo "/docs export-ignore" >> .gitattributes
echo "/docs/_*" >> .gitignore
wget -O ./docs/config.py https://gist.github.com/salaros/fb851bcd8c3bd5ef1262995246a74df8/raw/config.py
wget -O ./docs/Makefile https://gist.github.com/salaros/fb851bcd8c3bd5ef1262995246a74df8/raw/Makefile
wget -O ./docs/pip-requirements.txt https://gist.github.com/salaros/fb851bcd8c3bd5ef1262995246a74df8/raw/pip-requirements.txt
composer require --dev "sphpdox/sphpdox:dev-master@dev"
# -*- coding: utf-8 -*-
# General information about the project.
project = u'<project name>'
copyright = u'<year>, <author / company>'
author = u'<author>'
# Output file base name for HTML help builder.
htmlhelp_basename = '<projectNamePascalCase>'
# The version info for the project you're documenting.
#
# The short X.Y version.
version = u'<version>'
# The full version, including alpha/beta/rc tags.
release = u'<version>'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinxcontrib.phpdomain']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
]
}
# -- Options for HTMLHelp output ------------------------------------------
# Set up PHP syntax highlights
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer
lexers["php"] = PhpLexer(startinline=True, linenos=1)
lexers["php-annotations"] = PhpLexer(startinline=True, linenos=1)
primary_domain = "php"
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
BUILDDIR = _build
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
PHP = php
PHPSRC = ../src
NAMESPACE = Salaros\\Vtiger\\VTWSCLib
NAMESPACEPATH = Salaros/Vtiger/VTWSCLib
VENDORDIR := $(abspath ../vendor )
SPHPDOX = $(VENDORDIR)/sphpdox/sphpdox
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: sphpdox Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
sphpdox:
@ln -sfv $(VENDORDIR)/ $(SPHPDOX)/
@$(PHP) -f $(SPHPDOX)/sphpdox.php process $(NAMESPACE) $(PHPSRC) -o $(BUILDDIR)
@mv -v $(BUILDDIR)/$(NAMESPACEPATH)/* ./
@rm -rf $(BUILDDIR)/./*
sphinx-autobuild
sphinx_rtd_theme
sphinxcontrib-phpdomain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment