providers/mime: use Document.Rel
This commit is contained in:
		
							parent
							
								
									52b8b5a347
								
							
						
					
					
						commit
						860d083c11
					
				@ -15,12 +15,26 @@ type Provider struct {
 | 
			
		||||
 | 
			
		||||
// FuncMap fulfills the step.FuncProvider interface.
 | 
			
		||||
func (this *Provider) FuncMap () template.FuncMap {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FuncMapFor fulfills the step.FuncProviderFor interface.
 | 
			
		||||
func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap {
 | 
			
		||||
	stat := &state {
 | 
			
		||||
		document: document,
 | 
			
		||||
	}
 | 
			
		||||
	return template.FuncMap {
 | 
			
		||||
		"fileContentType": funcFileContentType,
 | 
			
		||||
		"fileContentType": stat.funcFileContentType,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func funcFileContentType (name string) (string, error) {
 | 
			
		||||
type state struct {
 | 
			
		||||
	document *step.Document
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *state) funcFileContentType (name string) (string, error) {
 | 
			
		||||
	name, err := this.document.Rel(name)
 | 
			
		||||
	if err != nil { return "", err }
 | 
			
		||||
	typ, err := mimetype.DetectFile(name)
 | 
			
		||||
	if err != nil { return "", err }
 | 
			
		||||
	return typ.String(), err
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user