examples munger allows any file extension.

This commit is contained in:
Eric Tune 2015-12-07 14:16:51 -08:00
parent ec1ba7438f
commit 21f81935e2
3 changed files with 16 additions and 2 deletions

View File

@ -27,7 +27,7 @@ const exampleToken = "EXAMPLE"
const exampleLineStart = "<!-- BEGIN MUNGE: EXAMPLE"
var exampleMungeTagRE = regexp.MustCompile(beginMungeTag(fmt.Sprintf("%s %s", exampleToken, `(([^ ])*.(yaml|json))`)))
var exampleMungeTagRE = regexp.MustCompile(beginMungeTag(fmt.Sprintf("%s %s", exampleToken, `(([^ ])*[.]([^.]*))`)))
// syncExamples updates all examples in markdown file.
//
@ -77,7 +77,14 @@ func syncExamples(filePath string, mlines mungeLines) (mungeLines, error) {
}
// update all example Tags
for _, tag := range exampleTags {
example, err := exampleContent(filePath, tag.linkText, tag.fileType)
ft := ""
if tag.fileType == "json" {
ft = "json"
}
if tag.fileType == "yaml" {
ft = "yaml"
}
example, err := exampleContent(filePath, tag.linkText, ft)
if err != nil {
return mlines, err
}

View File

@ -33,6 +33,8 @@ spec:
image: nginx
ports:
- containerPort: 80
`
var textExample = `some text
`
var cases = []struct {
in string
@ -47,6 +49,10 @@ spec:
"<!-- BEGIN MUNGE: EXAMPLE ../mungedocs/testdata/pod.yaml -->\n<!-- END MUNGE: EXAMPLE ../mungedocs/testdata/pod.yaml -->\n",
"<!-- BEGIN MUNGE: EXAMPLE ../mungedocs/testdata/pod.yaml -->\n\n```yaml\n" + podExample + "```\n\n[Download example](../mungedocs/testdata/pod.yaml?raw=true)\n<!-- END MUNGE: EXAMPLE ../mungedocs/testdata/pod.yaml -->\n",
},
{
"<!-- BEGIN MUNGE: EXAMPLE testdata/example.txt -->\n<!-- END MUNGE: EXAMPLE testdata/example.txt -->\n",
"<!-- BEGIN MUNGE: EXAMPLE testdata/example.txt -->\n\n```\n" + textExample + "```\n\n[Download example](testdata/example.txt?raw=true)\n<!-- END MUNGE: EXAMPLE testdata/example.txt -->\n",
},
}
repoRoot = ""
for _, c := range cases {

1
cmd/mungedocs/testdata/example.txt vendored Normal file
View File

@ -0,0 +1 @@
some text