コード例 #1
0
ファイル: builder_test.go プロジェクト: jazzsun/pugo-static
func TestBuilderErrors(t *testing.T) {
	Convey("Build Errors", t, func() {
		opt.SrcDir = "../xxxx"
		b2 := builder.New(opt)
		So(b2.Error, ShouldEqual, builder.ErrSrcDirMissing)

		opt.SrcDir = "../source"
		opt.TplDir = "../xxx"
		b2 = builder.New(opt)
		So(b2.Error, ShouldEqual, builder.ErrTplDirMissing)

	})

	Convey("Build Fail", t, func() {
		opt.TplDir = "../template"
		opt.SrcDir = "./testdata"

		b := builder.New(opt)
		So(b.Error, ShouldBeNil)

		b.Build("testdata_dest")
		So(b.Context().Error, ShouldNotBeNil)

		removeDirectory("testdata_dest")
	})
}
コード例 #2
0
ファイル: build.go プロジェクト: jazzsun/pugo-static
// build site function
func buildSite(opt *builder.BuildOption) func(ctx *cli.Context) {
	return func(ctx *cli.Context) {
		// ctrl+C capture
		signalChan := make(chan os.Signal)
		signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

		opt.Theme = ctx.String("theme")

		b := builder.New(opt)
		if b.Error != nil {
			log15.Crit("Builder.Fail", "error", b.Error.Error())
		}

		targetDir := ctx.String("dest")
		log15.Info("Dest." + targetDir)
		if com.IsDir(targetDir) {
			log15.Warn("Dest." + targetDir + ".Existed")
		}

		// auto watching
		b.Build(targetDir)
		if err := b.Context().Error; err != nil {
			log15.Crit("Build.Fail", "error", err.Error())
		}

		if !ctx.Bool("nowatch") {
			b.Watch(targetDir)
			<-signalChan
		}
		log15.Info("Build.Close")
	}
}
コード例 #3
0
ファイル: builder_test.go プロジェクト: jazzsun/pugo-static
func TestBuildWatch(t *testing.T) {
	Convey("Build Watch", t, func() {
		opt.TplDir = "../template"
		opt.SrcDir = "./testdata"
		b := builder.New(opt)
		So(b.Error, ShouldBeNil)
		So(b.Context(), ShouldBeNil)

		b.Watch("testdata_dest")
		file := path.Join(opt.SrcDir, "test.md")
		ioutil.WriteFile(file, []byte("```ini"), os.ModePerm)

		time.Sleep(5 * time.Second)
		So(b.Context(), ShouldNotBeNil)
		So(b.Context().Error, ShouldNotBeNil)
	})
}
コード例 #4
0
ファイル: builder_test.go プロジェクト: jazzsun/pugo-static
	"path"
	"testing"
	"time"
)

var (
	opt = &builder.BuildOption{
		SrcDir:    "../source",
		TplDir:    "../template",
		UploadDir: "../upload",
		Version:   "0.0.0",
		VerDate:   "2015-11-11",
		Theme:     "default",
	}
	target          = "../dest"
	b               = builder.New(opt)
	shoudlExistDirs = []string{
		"tags",
		"posts",
		"static",
	}
	shouldExistFiles = []string{
		"index.html",
		"archive.html",
		"about.html",
		"feed.xml",
		"sitemap.xml",
		"favicon.ico",
		"tags/pugo.html",
		"posts/1.html",
	}