Move Metadata load into NewMetadata function.

This commit is contained in:
Tobias Weingartner 2016-04-16 15:36:52 -07:00
parent b97a7909d8
commit e652d12cfc
6 changed files with 18 additions and 16 deletions

View file

@ -122,7 +122,9 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
// html, err = md.doTemplate(cfg, html, ctx) // TODO(weingart): move template execution here, something like:
//
// html, err = md.execTemplate(cfg, html, ctx)
// if err != nil { // if err != nil {
// return http.StatusInternalServerError, err // return http.StatusInternalServerError, err
// } // }

View file

@ -32,6 +32,17 @@ type Metadata struct {
Flags map[string]bool Flags map[string]bool
} }
// NewMetadata() returns a new Metadata struct, loaded with the given map
func NewMetadata(parsedMap map[string]interface{}) Metadata {
md := Metadata{
Variables: make(map[string]string),
Flags: make(map[string]bool),
}
md.load(parsedMap)
return md
}
// load loads parsed values in parsedMap into Metadata // load loads parsed values in parsedMap into Metadata
func (m *Metadata) load(parsedMap map[string]interface{}) { func (m *Metadata) load(parsedMap map[string]interface{}) {
@ -89,13 +100,6 @@ func GetParser(buf []byte) MetadataParser {
return nil return nil
} }
func NewMetadata() Metadata {
return Metadata{
Variables: make(map[string]string),
Flags: make(map[string]bool),
}
}
// parsers returns all available parsers // parsers returns all available parsers
func parsers() []MetadataParser { func parsers() []MetadataParser {
return []MetadataParser{ return []MetadataParser{

View file

@ -36,8 +36,7 @@ func (j *JSONMetadataParser) Init(b *bytes.Buffer) bool {
} }
} }
j.metadata = NewMetadata() j.metadata = NewMetadata(m)
j.metadata.load(m)
j.markdown = bytes.NewBuffer(b.Bytes()) j.markdown = bytes.NewBuffer(b.Bytes())
return true return true

View file

@ -17,8 +17,7 @@ func (n *NoneMetadataParser) Type() string {
// Parse metadata/markdown file // Parse metadata/markdown file
func (n *NoneMetadataParser) Init(b *bytes.Buffer) bool { func (n *NoneMetadataParser) Init(b *bytes.Buffer) bool {
m := make(map[string]interface{}) m := make(map[string]interface{})
n.metadata = NewMetadata() n.metadata = NewMetadata(m)
n.metadata.load(m)
n.markdown = bytes.NewBuffer(b.Bytes()) n.markdown = bytes.NewBuffer(b.Bytes())
return true return true

View file

@ -28,8 +28,7 @@ func (t *TOMLMetadataParser) Init(b *bytes.Buffer) bool {
if err := toml.Unmarshal(meta.Bytes(), &m); err != nil { if err := toml.Unmarshal(meta.Bytes(), &m); err != nil {
return false return false
} }
t.metadata = NewMetadata() t.metadata = NewMetadata(m)
t.metadata.load(m)
return true return true
} }

View file

@ -27,8 +27,7 @@ func (y *YAMLMetadataParser) Init(b *bytes.Buffer) bool {
if err := yaml.Unmarshal(meta.Bytes(), &m); err != nil { if err := yaml.Unmarshal(meta.Bytes(), &m); err != nil {
return false return false
} }
y.metadata = NewMetadata() y.metadata = NewMetadata(m)
y.metadata.load(m)
return true return true
} }