-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing single word resources to use templates #147
Changes from 2 commits
b4b63ec
9377652
27bf553
b0001a4
d6cc333
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,7 +414,7 @@ func (g *generator) renderStaticWebsite(providerName string, providerSchema *tfj | |
g.infof("rendering %q", rel) | ||
switch relDir { | ||
case "data-sources/": | ||
resName := shortName + "_" + removeAllExt(relFile) | ||
resName := resourceName(shortName, relFile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: isn't In the case of the HTTP provider (through which you identified the issue), I believe the I'll leave a comment in the unit test below. |
||
resSchema, ok := providerSchema.DataSourceSchemas[resName] | ||
if ok { | ||
tmpl := resourceTemplate(tmplData) | ||
|
@@ -429,7 +429,7 @@ func (g *generator) renderStaticWebsite(providerName string, providerSchema *tfj | |
return nil | ||
} | ||
case "resources/": | ||
resName := shortName + "_" + removeAllExt(relFile) | ||
resName := resourceName(shortName, relFile) | ||
resSchema, ok := providerSchema.ResourceSchemas[resName] | ||
if ok { | ||
tmpl := resourceTemplate(tmplData) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,18 @@ func removeAllExt(file string) string { | |
} | ||
} | ||
|
||
// resourceName determines whether the shortname and the relFile | ||
// are identical after file extensions have been stripped from the | ||
// latter. This allows single word resources (e.g., http) to use | ||
// templates (e.g., http.md.tmpl). | ||
func resourceName(shortName, relFile string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a quick unit test for this? |
||
if shortName == removeAllExt(relFile) { | ||
return shortName | ||
} | ||
|
||
return shortName + "_" + removeAllExt(relFile) | ||
} | ||
|
||
func writeFile(path string, data string) error { | ||
dir, _ := filepath.Split(path) | ||
err := os.MkdirAll(dir, 0755) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those are definitely typos I made 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. I like that we're keeping an eye out for each other 👍