Skip to content

Support for current file macro

Compare
Choose a tag to compare
@mariotoffia mariotoffia released this 21 Mar 15:06
· 113 commits to master since this release

It is now possible to use the ${gad:current:fq} macro of which will be substituted to the fully qualified filepath to the source file being parsed.

This may be useful to include source code segments from and annotate documentation, e.g.

// ParseConfig to use when invoking ParseAny, ParseSingleFileWalker, and
// ParseSinglePackageWalker.
//
// .ParserConfig
// [source,go]
// ----
// include::${gad:current:fq}[tag=parse-config,indent=0]
// ----
// <1> These are usually excluded since many testcases is not documented anyhow
// <2> As of _go 1.16_ it is recommended to *only* use module based parsing
// tag::parse-config[]
type ParseConfig struct {
	// Test denotes if test files (ending with _test.go) should be included or not
	// (default not included)
	Test bool // <1>
	// Internal determines if internal folders are included or not (default not)
	Internal bool
	// UnderScore, when set to true it will include directories beginning with _
	UnderScore bool
	// Optional module to resolve fully qualified package paths
	Module *GoModule // <2>
}

// end::parse-config[]

The above sample will render the struct as go source and is annotated with two bullets.

Cheers,
Mario :)