1515# You should have received a copy of the GNU General Public License
1616# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717# -----------------------------------------------------------------------------
18- '''An extension providing pygments lexers for the Cylc flow.cylc language.
18+ from pathlib import Path
19+ from cylc .sphinx_ext .cylc_lang .autodocumenters import (
20+ CylcAutoDirective ,
21+ CylcAutoTypeDirective ,
22+ CylcMetadataDirective
23+ )
24+ from cylc .sphinx_ext .cylc_lang .domains import (
25+ ParsecDomain ,
26+ CylcDomain ,
27+ CylcScopeDirective
28+ )
29+ from cylc .sphinx_ext .cylc_lang .lexers import CylcLexer , CylcGraphLexer
30+
31+
32+ rawdoc1 = '''An extension providing pygments lexers for the Cylc flow.cylc
33+ language.
1934
2035
2136Pygments Lexers
157172 cylc.flow.parsec.validate.ParsecValidator.V_TYPE_HELP
158173 cylc.flow.parsec.validate.CylcConfigValidator.V_TYPE_HELP
159174
175+ '''
160176
177+ rawdoc3 = '''
161178Directives
162179----------
163180
181198
182199 This resets it to the hardcoded default which is ``flow.cylc``.
183200
201+
202+
184203'''
185204
186- from cylc .sphinx_ext .cylc_lang .autodocumenters import (
187- CylcAutoDirective ,
188- CylcAutoTypeDirective
189- )
190- from cylc .sphinx_ext .cylc_lang .domains import (
191- ParsecDomain ,
192- CylcDomain ,
193- CylcScopeDirective
194- )
195- from cylc .sphinx_ext .cylc_lang .lexers import CylcLexer , CylcGraphLexer
205+ rawdoc2 = """
206+ .. rst:directive:: cylc-metadata
207+
208+ Get a Cylc Configuration and render metadata fields.
209+
210+ .. rst:directive:option:: source
211+ :type: string
212+
213+ If set, renders the metadata of a workflow, otherwise the global
214+ config.
215+
216+ .. rst:directive:option:: global
217+ :type: string
218+
219+ Set CYLC_SITE_CONF_PATH to this value.
220+
221+ .. note::
222+
223+ If you have a user config this will still override the site
224+ config!
225+
226+ ----
227+
228+ Workflow Config
229+ ^^^^^^^^^^^^^^^
196230
231+ .. rst-example::
232+
233+ .. cylc-metadata::
234+ :source: {workflow_path}
235+
236+ ----
237+
238+ Global Config
239+ ^^^^^^^^^^^^^
240+
241+ .. rst-example::
242+
243+ .. cylc-metadata::
244+ :global: {workflow_path}
245+
246+ """
247+
248+ workflow_path = Path (__file__ ).parent .parent .parent .parent / 'etc'
249+ __doc__ = (
250+ rawdoc1
251+ + rawdoc2 .format (workflow_path = workflow_path )
252+ + rawdoc3
253+ )
197254
198255__all__ = [
199256 'CylcAutoDirective' ,
@@ -214,5 +271,6 @@ def setup(app):
214271 app .add_domain (ParsecDomain )
215272 app .add_directive ('auto-cylc-conf' , CylcAutoDirective )
216273 app .add_directive ('auto-cylc-type' , CylcAutoTypeDirective )
274+ app .add_directive ('cylc-metadata' , CylcMetadataDirective )
217275 app .add_directive ('cylc-scope' , CylcScopeDirective )
218276 return {'version' : __version__ , 'parallel_read_safe' : True }
0 commit comments