Skip to content

Commit

Permalink
examples munger allows any file extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
erictune committed Dec 7, 2015
1 parent ec1ba74 commit 21f8193
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/mungedocs/example_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/mungedocs/example_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ spec:
image: nginx
ports:
- containerPort: 80
`
var textExample = `some text
`
var cases = []struct {
in string
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/mungedocs/testdata/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some text

0 comments on commit 21f8193

Please sign in to comment.