1# Copyright David Abrahams 2004. Distributed under the Boost 2# Software License, Version 1.0. (See accompanying 3# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 5# Support for docutils ReStructuredText processing. 6 7import type ; 8import scanner ; 9import generators ; 10import os ; 11import common ; 12import toolset ; 13import path ; 14import feature : feature ; 15import property ; 16import errors ; 17 18.initialized = ; 19 20type.register ReST : rst ; 21 22class rst-scanner : common-scanner 23{ 24 rule __init__ ( paths * ) 25 { 26 common-scanner.__init__ . $(paths) ; 27 } 28 29 rule pattern ( ) 30 { 31 return "^[ ]*\\.\\.[ ]+include::[ ]+([^ 32]+)" 33 "^[ ]*\\.\\.[ ]+image::[ ]+([^ 34]+)" 35 "^[ ]*\\.\\.[ ]+figure::[ ]+([^ 36]+)" 37 ; 38 } 39} 40 41scanner.register rst-scanner : include ; 42type.set-scanner ReST : rst-scanner ; 43 44generators.register-standard docutils.html : ReST : HTML ; 45 46rule init ( docutils-dir ? : tools-dir ? ) 47{ 48 docutils-dir ?= [ modules.peek : DOCUTILS_DIR ] ; 49 tools-dir ?= $(docutils-dir)/tools ; 50 51 if ! $(.initialized) 52 { 53 .initialized = true ; 54 .docutils-dir = $(docutils-dir) ; 55 .tools-dir = $(tools-dir:R="") ; 56 57 .setup = [ 58 common.prepend-path-variable-command PYTHONPATH 59 : $(.docutils-dir) $(.docutils-dir)/extras ] ; 60 RST2XXX = [ common.find-tool rst2html ] ; 61 } 62} 63 64rule html ( target : source : properties * ) 65{ 66 if ! [ on $(target) return $(RST2XXX) ] 67 { 68 local python-cmd = [ property.select <python.interpreter> : $(properties) ] ; 69 if ! $(.tools-dir) { 70 errors.user-error 71 "The docutils module is used, but not configured. " 72 : "" 73 : "Please modify your user-config.jam or project-config.jam to contain:" 74 : "" 75 : " using docutils : <docutils-dir> ;" 76 : "" 77 : "On Ubuntu, 'docutils-common' package will create /usr/share/docutils." 78 : "Other flavours of Linux likely have docutils as package as well." 79 : "On Windows, you can install from http://docutils.sourceforge.net/." 80 ; 81 } 82 RST2XXX on $(target) = $(python-cmd:G=:E="python") $(.tools-dir)/rst2html.py ; 83 } 84} 85 86 87feature docutils : : free ; 88feature docutils-html : : free ; 89feature docutils-cmd : : free ; 90toolset.flags docutils COMMON-FLAGS : <docutils> ; 91toolset.flags docutils HTML-FLAGS : <docutils-html> ; 92toolset.flags docutils RST2XXX : <docutils-cmd> ; 93 94actions html 95{ 96 $(.setup) 97 "$(RST2XXX)" $(COMMON-FLAGS) $(HTML-FLAGS) $(>) $(<) 98} 99 100