Making site page initialization a bit more granular and accessible

This commit is contained in:
spf13 2014-05-01 13:20:58 -04:00
parent cbd9506c29
commit 1302ef9f63
2 changed files with 15 additions and 5 deletions

View file

@ -138,8 +138,6 @@ func renderBytes(content []byte, pagefmt string) []byte {
} }
} }
// TODO abstract further to support loading from more
// than just files on disk. Should load reader (file, []byte)
func newPage(filename string) *Page { func newPage(filename string) *Page {
page := Page{contentType: "", page := Page{contentType: "",
File: File{FileName: filename, Extension: "html"}, File: File{FileName: filename, Extension: "html"},
@ -207,7 +205,7 @@ func layouts(types string, layout string) (layouts []string) {
return return
} }
func ReadFrom(buf io.Reader, name string) (page *Page, err error) { func NewPage(name string) (page *Page, err error) {
if len(name) == 0 { if len(name) == 0 {
return nil, errors.New("Zero length page name") return nil, errors.New("Zero length page name")
} }
@ -215,6 +213,10 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
// Create new page // Create new page
p := newPage(name) p := newPage(name)
return p, nil
}
func (p *Page) ReadFrom(buf io.Reader) (err error) {
// Parse for metadata & body // Parse for metadata & body
if err = p.parse(buf); err != nil { if err = p.parse(buf); err != nil {
jww.ERROR.Print(err) jww.ERROR.Print(err)
@ -224,7 +226,7 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
//analyze for raw stats //analyze for raw stats
p.analyzePage() p.analyzePage()
return p, nil return nil
} }
func (p *Page) analyzePage() { func (p *Page) analyzePage() {

View file

@ -231,6 +231,10 @@ func (s *Site) checkDescriptions() {
} }
} }
func (s *Site) Initialise() (err error) {
return s.initialize()
}
func (s *Site) initialize() (err error) { func (s *Site) initialize() (err error) {
if err = s.checkDirectories(); err != nil { if err = s.checkDirectories(); err != nil {
return err return err
@ -317,7 +321,11 @@ func (s *Site) CreatePages() (err error) {
go func(file *source.File) (err error) { go func(file *source.File) (err error) {
defer wg.Done() defer wg.Done()
page, err := ReadFrom(file.Contents, file.LogicalName) page, err := NewPage(file.LogicalName)
if err != nil {
return err
}
err = page.ReadFrom(file.Contents)
if err != nil { if err != nil {
return err return err
} }