Пример #1
0
// New builder with option
func New(opt *BuildOption) *Builder {
	if !com.IsDir(opt.SrcDir) {
		return &Builder{Error: ErrSrcDirMissing}
	}
	if !com.IsDir(opt.TplDir) {
		return &Builder{Error: ErrTplDirMissing}
	}
	builder := &Builder{
		parsers: []parser.Parser{
			parser.NewCommonParser(),
			parser.NewMdParser(),
		},
		Version: builderVersion{
			Num:  opt.Version,
			Date: opt.VerDate,
		},
		opt: opt,
	}
	builder.render = render.New(builder.opt.TplDir)
	builder.tasks = []*BuildTask{
		&BuildTask{"Data", builder.ReadData, nil},
		&BuildTask{"Copy", builder.CopyAssets, nil},
		&BuildTask{"Compile", builder.Compile, nil},
		&BuildTask{"Feed", builder.WriteFeed, nil},
	}
	log15.Debug("Build.Source." + opt.SrcDir)
	log15.Debug("Build.Template." + opt.TplDir)
	log15.Debug("Build.Theme." + opt.Theme)
	return builder
}
Пример #2
0
	"testing"

	"github.com/go-xiaohei/pugo-static/model"
	"github.com/go-xiaohei/pugo-static/parser"
	. "github.com/smartystreets/goconvey/convey"
)

type demoData struct {
	Name     string
	Age      int
	IsFemale bool
}

var (
	p  = parser.NewCommonParser()
	p2 = parser.NewMdParser()
)

func TestIniBlock(t *testing.T) {
	Convey("test ini block", t, func() {
		Convey("test ini empty data", func() {
			ib := new(parser.IniBlock)
			ib.Write(nil)
			demo := new(demoData)
			err := ib.MapTo("", demo)
			So(err, ShouldBeNil)
			So(demo.Name, ShouldBeEmpty)

			ib.Write(nil)
			data := ib.MapHash("")
			So(data, ShouldBeEmpty)