URI: 
       Expand the ShowPlan functionality - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit cb00917af69bfd6fbe79dcf094956b6af33669e5
   DIR parent 4004687fb2da9228203fec39b914ba534c934966
  HTML Author: Noah Campbell <noahcampbell@gmail.com>
       Date:   Tue,  3 Sep 2013 20:52:50 -0700
       
       Expand the ShowPlan functionality
       
       Diffstat:
         M hugolib/planner.go                  |      11 ++++++++++-
         M hugolib/site.go                     |      16 ++++++++++------
         M hugolib/site_show_plan_test.go      |      25 ++++++++++++++++++++++++-
         M hugolib/site_url_test.go            |       4 ++++
         M target/file.go                      |      17 ++++++++++++++---
       
       5 files changed, 62 insertions(+), 11 deletions(-)
       ---
   DIR diff --git a/hugolib/planner.go b/hugolib/planner.go
       @@ -12,10 +12,19 @@ func (s *Site) ShowPlan(out io.Writer) (err error) {
        
                for _, file := range s.Files {
                        fmt.Fprintf(out, "%s\n", file)
       +                fmt.Fprintf(out, " canonical => ")
                        if s.Target == nil {
       -                        fmt.Fprintf(out, " *implicit* => %s\n", "!no target specified!")
       +                        fmt.Fprintf(out, "%s\n", "!no target specified!")
                                continue
                        }
       +
       +                trns, err := s.Target.Translate(file)
       +                if err != nil {
       +                        return err
       +                }
       +
       +                fmt.Fprintf(out, "%s\n", trns)
       +
                }
                return
        }
   DIR diff --git a/hugolib/site.go b/hugolib/site.go
       @@ -74,7 +74,7 @@ type Site struct {
                Info       SiteInfo
                Shortcodes map[string]ShortcodeFunc
                timer      *nitro.B
       -        Target     target.Publisher
       +        Target     target.Output
        }
        
        type SiteInfo struct {
       @@ -114,7 +114,8 @@ func (s *Site) Build() (err error) {
        
        func (s *Site) Analyze() {
                s.Process()
       -        s.checkDescriptions()
       +        s.initTarget()
       +        s.ShowPlan(os.Stdout)
        }
        
        func (s *Site) prepTemplates() {
       @@ -173,7 +174,7 @@ func (s *Site) Write() {
        func (s *Site) checkDescriptions() {
                for _, p := range s.Pages {
                        if len(p.Description) < 60 {
       -                        fmt.Print(p.FileName + " ")
       +                        fmt.Println(p.FileName + " ")
                        }
                }
        }
       @@ -543,7 +544,7 @@ func (s *Site) RenderLists() error {
        
                        if a := s.Tmpl.Lookup("rss.xml"); a != nil {
                                // XML Feed
       -                        n.Url = Urlize(section + ".xml")
       +                        n.Url = helpers.Urlize(section + ".xml")
                                n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
                                y := s.NewXMLBuffer()
                                s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
       @@ -647,14 +648,17 @@ func (s *Site) NewXMLBuffer() *bytes.Buffer {
                return bytes.NewBufferString(header)
        }
        
       -func (s *Site) WritePublic(path string, content []byte) (err error) {
       -
       +func (s *Site) initTarget() {
                if s.Target == nil {
                        s.Target = &target.Filesystem{
                                PublishDir: s.absPublishDir(),
                                UglyUrls:   s.Config.UglyUrls,
                        }
                }
       +}
       +
       +func (s *Site) WritePublic(path string, content []byte) (err error) {
       +        s.initTarget()
        
                if s.Config.Verbose {
                        fmt.Println(path)
   DIR diff --git a/hugolib/site_show_plan_test.go b/hugolib/site_show_plan_test.go
       @@ -3,6 +3,7 @@ package hugolib
        import (
                "bytes"
                "testing"
       +        "github.com/spf13/hugo/target"
        )
        
        func checkShowPlanExpected(t *testing.T, expected, got string) {
       @@ -30,6 +31,28 @@ func TestDegenerateNoTarget(t *testing.T) {
                        t.Errorf("ShowPlan unexpectedly returned an error: %s", err)
                }
        
       -        expected := "foo/bar/file.md\n *implicit* => !no target specified!\n"
       +        expected := "foo/bar/file.md\n canonical => !no target specified!\n"
                checkShowPlanExpected(t, expected, out.String())
        }
       +
       +func TestFileTarget(t *testing.T) {
       +        s := &Site{Target: new(target.Filesystem)}
       +        s.Files = append(s.Files, "foo/bar/file.md")
       +        out := new(bytes.Buffer)
       +        s.ShowPlan(out)
       +
       +        expected := "foo/bar/file.md\n canonical => foo/bar/file/index.html\n"
       +        checkShowPlanExpected(t, expected, out.String())
       +}
       +
       +func TestFileTargetUgly(t *testing.T) {
       +        s := &Site{Target: &target.Filesystem{UglyUrls: true}}
       +        s.Files = append(s.Files, "foo/bar/file.md")
       +        out := new(bytes.Buffer)
       +        s.ShowPlan(out)
       +
       +        expected := "foo/bar/file.md\n canonical => foo/bar/file.html\n"
       +        checkShowPlanExpected(t, expected, out.String())
       +}
       +
       +
   DIR diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go
       @@ -40,6 +40,10 @@ func (t *InMemoryTarget) Publish(label string, reader io.Reader) (err error) {
                return
        }
        
       +func (t *InMemoryTarget) Translate(label string) (dest string, err error) {
       +        return label, nil
       +}
       +
        func TestPageCount(t *testing.T) {
                target := new(InMemoryTarget)
                s := &Site{Target: target}
   DIR diff --git a/target/file.go b/target/file.go
       @@ -16,6 +16,11 @@ type Translator interface {
                Translate(string) (string, error)
        }
        
       +type Output interface {
       +        Publisher
       +        Translator
       +}
       +
        type Filesystem struct {
                UglyUrls         bool
                DefaultExtension string
       @@ -52,18 +57,24 @@ func (fs *Filesystem) Translate(src string) (dest string, err error) {
                if src == "/" {
                        return "index.html", nil
                }
       -        if fs.UglyUrls {
       -                return src, nil
       -        }
        
                dir, file := path.Split(src)
                ext := fs.extension(path.Ext(file))
                name := filename(file)
        
       +        if fs.UglyUrls {
       +                return path.Join(dir, fmt.Sprintf("%s%s", name, ext)), nil
       +        }
       +
                return path.Join(dir, name, fmt.Sprintf("index%s", ext)), nil
        }
        
        func (fs *Filesystem) extension(ext string) string {
       +        switch ext {
       +        case ".md", ".rst": // TODO make this list configurable.  page.go has the list of markup types.
       +                return ".html"
       +        }
       +
                if ext != "" {
                        return ext
                }