예제 #1
0
func Test_WriteHtmlFile(t *testing.T) {
	realisticdate1999, _ := article.ParseDateUnix("1999/03/21 17:00:00")
	realisticdate2012, _ := article.ParseDateUnix("2012/03/19 06:51:15")
	article.SetPathForContent("/am-a-path")

	// Produce output case.
	ms := &mockSystem{test_header_2,
		make([]*mockReadCloser, 0, 4),
		make([]*mockWriteCloser, 0, 4),
		time.Time{},
		make([]string, 0, 4)}

	md := article.NewArticleTest("one.md", realisticdate1999, realisticdate2012, "What I want", true)
	WriteHtmlFile(ms, md)

	testhelpers.AssertInt(t, 1, len(ms.writefiles))
	testhelpers.AssertInt(t, 1, len(ms.readfiles))
	testhelpers.AssertInt(t, 1, int(ms.writefiles[0].closedCount))
	testhelpers.AssertInt(t, 1, int(ms.readfiles[0].closedCount))

	testhelpers.AssertString(t, "one.md", ms.readfiles[0].name)
	testhelpers.AssertString(t, "one.html", ms.writefiles[0].name)
	testhelpers.AssertString(t, "one.html", ms.timedfiles[0])

	// TODO(rjkroege): might want to diff the stirngs?
	testhelpers.AssertString(t, generated_output_2, ms.writefiles[0].String())

	// Output production skipped by date comparison.
	ms = &mockSystem{test_header_2,
		make([]*mockReadCloser, 0, 4),
		make([]*mockWriteCloser, 0, 4),
		realisticdate2012,
		make([]string, 0, 4)}

	md = article.NewArticleTest("one.md", realisticdate1999, realisticdate2012, "What I want", true)
	WriteHtmlFile(ms, md)

	testhelpers.AssertInt(t, 0, len(ms.writefiles))
	testhelpers.AssertInt(t, 1, len(ms.readfiles))
	testhelpers.AssertInt(t, 1, int(ms.readfiles[0].closedCount))

	testhelpers.AssertString(t, "one.md", ms.readfiles[0].name)
	testhelpers.AssertString(t, "one.html", ms.timedfiles[0])

	// TODO(rjkroege): Add additional tests to support validating error handling, etc.
}
예제 #2
0
func Test_WriteTimeline(t *testing.T) {
	/* General idea: create a constant string. Read from it., validate the resulting output. */
	statdate, _ := article.ParseDateUnix("1999/03/21 17:00:00")
	tagdate, _ := article.ParseDateUnix("2012/03/19 06:51:15")
	article.SetPathForContent("/foo")

	metadatas := []*article.MetaData{
		article.NewArticleTest("bar0.md", statdate, tagdate, "What I want 0", false),
		article.NewArticleTest("bar1.md", statdate, statdate, "What I want 1", false),
		article.NewArticleTest("bar2.md", statdate, tagdate, "What I want 2", false)}

	buffy := make([]byte, 0, 5000)
	fd := bytes.NewBuffer(buffy)

	WriteTimeline(fd, metadatas)

	testhelpers.AssertString(t, expected, fd.String())

	//    t.Errorf("output: {%s}", fd.String())
}
예제 #3
0
// TODO(rjkroege): must read the directory from the command line?
func main() {
	pwd, _ := os.Getwd()
	article.SetPathForContent(pwd)

	// get a directory listing
	fd, _ := os.OpenFile(".", os.O_RDONLY, 0)
	dirs, _ := fd.Readdir(-1) // < 0 means get all of them

	e := make([]*article.MetaData, len(dirs))
	i := 0

	// Can finess the "template" here.

	for _, d := range dirs {
		if strings.HasSuffix(d.Name(), ".md") {
			e[i] = article.NewMetaData(d.Name(), d.ModTime())
			fd, _ := os.OpenFile(e[i].Name, os.O_RDONLY, 0)
			e[i].RootThroughFileForMetadata(io.Reader(fd))
			fd.Close()
			i++
		}
	}
	e = e[0:i] // fix up the slice

	// Generate the timeline datafile.
	ofd, err := os.OpenFile("note_list.js", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		fmt.Print(err)
	} else {
		// fmt.Print("attempt to print out the metadata\n")
		generate.WriteTimeline(ofd, e)
	}

	// Generate articles here so that we can inline the JavaScript data if
	// that would prove desirable.
	for _, d := range e {
		// fmt.Print("running WriteHtmlFile\n")
		generate.WriteHtmlFile(SystemImpl(0), d)
	}

}