Documents can now specify a content-type
This commit is contained in:
parent
b395963709
commit
abf3fc3ae3
@ -81,6 +81,10 @@ func (this *handler) serveFile (res http.ResponseWriter, req *http.Request, file
|
|||||||
this.serveError(res, req, http.StatusInternalServerError, err)
|
this.serveError(res, req, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if document.ContentType != "" {
|
||||||
|
log.Println(document.ContentType)
|
||||||
|
res.Header().Set("Content-Type", document.ContentType)
|
||||||
|
}
|
||||||
err = document.Execute(res, step.ExecutionData {
|
err = document.Execute(res, step.ExecutionData {
|
||||||
Data: req,
|
Data: req,
|
||||||
})
|
})
|
||||||
|
15
document.go
15
document.go
@ -7,9 +7,10 @@ import "html/template"
|
|||||||
|
|
||||||
// Document represents a STEP file.
|
// Document represents a STEP file.
|
||||||
type Document struct {
|
type Document struct {
|
||||||
Author string
|
Author string
|
||||||
Title string
|
Title string
|
||||||
Extends string
|
Extends string
|
||||||
|
ContentType string
|
||||||
|
|
||||||
// WORM:
|
// WORM:
|
||||||
environment *Environment
|
environment *Environment
|
||||||
@ -41,6 +42,7 @@ func (this *Document) Execute (output io.Writer, data ExecutionData) error {
|
|||||||
Author: this.Author,
|
Author: this.Author,
|
||||||
Title: this.Title,
|
Title: this.Title,
|
||||||
Extends: this.Extends,
|
Extends: this.Extends,
|
||||||
|
ContentType: this.ContentType,
|
||||||
FrontMatter: this.frontMatter,
|
FrontMatter: this.frontMatter,
|
||||||
Body: template.HTML(outputBuilder.String()),
|
Body: template.HTML(outputBuilder.String()),
|
||||||
},
|
},
|
||||||
@ -55,9 +57,10 @@ type ExecutionData struct {
|
|||||||
|
|
||||||
// ExecutionResult is the result of executing a document.
|
// ExecutionResult is the result of executing a document.
|
||||||
type ExecutionResult struct {
|
type ExecutionResult struct {
|
||||||
Author string
|
Author string
|
||||||
Title string
|
Title string
|
||||||
Extends string
|
Extends string
|
||||||
|
ContentType string
|
||||||
|
|
||||||
FrontMatter FrontMatter
|
FrontMatter FrontMatter
|
||||||
Body template.HTML
|
Body template.HTML
|
||||||
|
@ -106,6 +106,9 @@ func (this *Environment) parse (name string, modTime time.Time, input io.Reader)
|
|||||||
if extends, ok := frontMatter["extends"]; ok {
|
if extends, ok := frontMatter["extends"]; ok {
|
||||||
document.Extends = extends
|
document.Extends = extends
|
||||||
}
|
}
|
||||||
|
if contentType, ok := frontMatter["content-type"]; ok {
|
||||||
|
document.ContentType = contentType
|
||||||
|
}
|
||||||
|
|
||||||
// parse template from the body
|
// parse template from the body
|
||||||
document.template.Funcs(this.funcMap)
|
document.template.Funcs(this.funcMap)
|
||||||
|
Loading…
Reference in New Issue
Block a user