2 Copyright 2017 Rene Rivera
3 Distributed under the Boost Software License, Version 1.0. (See
4 accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
11 The asciidoctor tool converts the ascidoc documentation format to various
12 backend formats for either viewing or further processing by documentation
13 tools. This tool supports the baseline asciidoctor distribution (i.e. the
21 import "class" : new ;
23 feature.feature asciidoctor : : implicit propagated symmetric ;
27 == Feature: `asciidoctor-attribute`
29 Defines arbitrary asciidoctor attributes. The value of the feature should be
30 specified with the CLI syntax for attributes.
31 For example to use as a target requirement:
34 html example : example.adoc :
35 <asciidoctor-attribute>idprefix=ex ;
38 This is a `free` feature and is not `propagated`. I.e. it applies only to the
39 target it's specified on.
43 feature.subfeature asciidoctor : attribute : : free ;
47 == Feature: `asciidoctor-doctype`
49 Specifies the `doctype` to use for generating the output format. Allowed
50 `doctype` values are: `article`, `book`, `manpage`, and `inline`.
54 feature.subfeature asciidoctor : doctype
55 : article book manpage inline
56 : optional propagated ;
60 == Feature: `asciidoctor-backend`
62 Specifies the `backend` to use to produce output from the source asciidoc.
63 This feature is automatically applied to fit the build target type. For
64 example, when specifying an `html` target for an `asciidoc` source:
67 html example : example.adoc ;
70 The target will by default acquire the `<asciidoctor-backend>html5`
71 requirement. The default for each target type are:
73 * `html`: `<asciidoctor-backend>html5`
74 * `docbook`: `<asciidoctor-backend>docbook45`
75 * `man`: `<asciidoctor-backend>manpage`
76 * `pdf`: `<asciidoctor-backend>pdf`
78 To override the defaults you specify it as a requirement on the target:
81 docbook example : example.adoc :
82 <asciidoctor-backend>docbook5 ;
85 Allowed `backend` values are: `html5`, `docbook45`, `docbook5`, `pdf`.
89 feature.subfeature asciidoctor : backend
90 : html5 docbook5 docbook45 manpage pdf
91 : propagated symmetric composite ;
97 To use the `asciidoctor` tool you need to declare it in a configuration file
98 with the `using` rule. The initialiation takes the following arguments:
100 * `command`: The command, with any extra arguments, to execute.
102 For example you could insert the following in your `user-config.jam`:
105 using asciidoctor : "/usr/local/bin/asciidoctor" ;
108 If no `command` is given it defaults to just `asciidoctor` with assumption
109 that the `asciidoctor` is available in the search `PATH`.
113 rule init ( command * )
117 # Setup only if we were called via "using .. ;"
118 .initialized = true ;
120 # Register generators.
121 for local target-type in HTML MANPAGE PDF DOCBOOK
124 [ new asciidoctor-generator asciidoctor.convert
125 : ASCIIDOC : $(target-type) ] ;
128 # Seriously bad kludge to prevent docbook generators from being
129 # considered when we are generating html directly.
130 # TODO: Design and implement a mechanism to resolve generator conflicts.
131 generators.override asciidoctor.convert : boostbook.docbook-to-onehtml ;
134 # The command.. Default is bare asciidoctor.
135 command ?= asciidoctor ;
136 # We attempt to resolve each component of the command to account for
137 # script interpreter wrappers.
139 for local c in $(command)
141 local t = [ common.find-tool $(c) ] ;
143 ASCIIDOCTOR += $(t) ;
147 class asciidoctor-generator : generator
149 import property-set ;
151 rule run ( project name ? : property-set : sources + )
153 # ECHO *** asciidoctor-generator.run $(project) $(name) :: [ $(property-set).raw ] :: $(sources) ;
155 # We set a default backend based on the target type.
156 local backend = [ $(property-set).get <asciidoctor-backend> ] ;
158 # For now, we only accept a single adoc source.
159 if ( ! $(sources[2]) ) && ( [ $(sources[1]).type ] = ASCIIDOC )
161 # If no output name is specified, guess it from sources.
162 # NOTE: For some reason the "?=" conditional assign op doesn't
163 # work here. It assigns the value regardless, so work around it.
164 # TODO: Look into why that happens.
167 name = [ generator.determine-output-name $(sources) ] ;
170 # Depending on the kind of target we set up the backend, and
171 # and any other options.
174 switch [ $(property-set).get <main-target-type> ]
176 case HTML : backend = html5 ;
177 case DOCBOOK : backend = docbook45 ;
178 case MANPAGE : backend = manpage ;
179 case PDF : backend = pdf ;
184 # We build a reduced property set so that we are not toolset dependent.
185 local raw-set = <asciidoctor-backend>$(backend) ;
186 for local p in [ $(property-set).raw ]
188 if $(p:G) in <asciidoctor-attribute> <asciidoctor-doctype>
194 raw-set = [ feature.expand-composites $(raw-set) ] ;
195 raw-set += [ $(property-set).incidental ] ;
196 property-set = [ property-set.create $(raw-set) ] ;
197 return [ generator.run $(project) $(name) : $(property-set) : $(sources) ] ;
202 toolset.flags asciidoctor ATTRIBUTE : <asciidoctor-attribute> ;
203 toolset.flags asciidoctor DOCTYPE : <asciidoctor-doctype> ;
204 toolset.flags asciidoctor INCLUDES : <include> ;
205 toolset.flags asciidoctor BACKEND : <asciidoctor-backend> ;
206 toolset.flags asciidoctor FLAGS : <flags> ;
208 feature.compose <asciidoctor-backend>pdf : <flags>"-r asciidoctor-pdf" ;
212 "$(ASCIIDOCTOR)" -o$(_)"$(<:D=)" -D$(_)"$(<:D)" -b$(_)"$(BACKEND)" -a$(_)"$(ATTRIBUTE)" -d$(_)"$(DOCTYPE)" -I$(_)"$(INCLUDES)" $(FLAGS) "$(>)"