Browse Source

change package name to static

reduce overhead of tests for cmd main
cdelorme 7 years ago
parent
commit
7bfbd197ce
9 changed files with 27 additions and 72 deletions
  1. 6 12
      cmd/staticmd/main.go
  2. 4 43
      cmd/staticmd/main_test.go
  3. 10 10
      generator.go
  4. 1 1
      generator_test.go
  5. 1 1
      navigation.go
  6. 1 1
      page.go
  7. 2 2
      readme.md
  8. 1 1
      staticmd.go
  9. 1 1
      staticmd_test.go

+ 6 - 12
cmd/staticmd/main.go

@@ -6,17 +6,16 @@ import (
 
 	"github.com/cdelorme/glog"
 	"github.com/cdelorme/gonf"
-	"github.com/cdelorme/staticmd"
+	"github.com/cdelorme/static"
+
+	"github.com/russross/blackfriday"
 )
 
 var exit = os.Exit
 var getwd = os.Getwd
+var operate = blackfriday.MarkdownCommon
 
-type generator interface {
-	Generate() error
-}
-
-func configure() generator {
+func main() {
 	cwd, _ := getwd()
 
 	smd := &staticmd.Generator{
@@ -37,12 +36,7 @@ func configure() generator {
 	g.Example("-t template.tmpl -i src/ -o out/ -r")
 	g.Load()
 
-	return smd
-}
-
-func main() {
-	smd := configure()
-	if err := smd.Generate(); err != nil {
+	if err := smd.Generate(operate); err != nil {
 		exit(1)
 	}
 }

+ 4 - 43
cmd/staticmd/main_test.go

@@ -1,49 +1,10 @@
 package main
 
-import (
-	"os"
-	"testing"
+import "testing"
 
-	"github.com/cdelorme/staticmd"
-)
-
-func init() {
-	exit = func(_ int) {}
+func TestMain(t *testing.T) {
+	exit = func(int) {}
 	getwd = func() (string, error) { return "", nil }
-}
-
-var mockError error
-
-type mockGenerator struct{}
-
-func (self *mockGenerator) Generate() error { return mockError }
-
-func TestPlacebo(_ *testing.T) {}
-
-func TestMain(_ *testing.T) {
-	os.Args = []string{}
+	operate = func([]byte) []byte { return []byte{} }
 	main()
 }
-
-func TestConfigure(t *testing.T) {
-
-	// set a value on all parameters
-	os.Args = []string{"-t", "afile", "-i", "/in/", "-o", "/out/", "-b", "-r"}
-
-	// run configure & check results
-	s := configure()
-	if s == nil {
-		t.FailNow()
-	}
-
-	// cast and check values on s
-	g, e := s.(*staticmd.Generator)
-	if !e {
-		t.FailNow()
-	}
-
-	// check values on generator match cli parameters
-	if g.Input != "/in/" || g.Output != "/out/" || !g.Relative || !g.Book || g.TemplateFile != "afile" {
-		t.FailNow()
-	}
-}

+ 10 - 10
generator.go

@@ -1,4 +1,4 @@
-package staticmd
+package static
 
 import (
 	"bufio"
@@ -8,8 +8,6 @@ import (
 	"os"
 	"path/filepath"
 	"strings"
-
-	"github.com/russross/blackfriday"
 )
 
 var readfile = ioutil.ReadFile
@@ -22,6 +20,8 @@ type executor interface {
 	Execute(io.Writer, interface{}) error
 }
 
+type operation func([]byte) []byte
+
 type Generator struct {
 	Book         bool   `json:"book,omitempty"`
 	Input        string `json:"input,omitempty"`
@@ -56,7 +56,7 @@ func (g *Generator) walk(path string, file os.FileInfo, err error) error {
 	return err
 }
 
-func (g *Generator) multi() error {
+func (g *Generator) multi(run operation) error {
 	navi := make(map[string][]navigation)
 	var err error
 
@@ -119,7 +119,7 @@ func (g *Generator) multi() error {
 			markdown = append([]byte(toc), markdown...)
 		}
 
-		page.Content = template.HTML(blackfriday.MarkdownCommon(markdown))
+		page.Content = template.HTML(run(markdown))
 
 		var f *os.File
 		if f, err = create(out); err != nil {
@@ -139,7 +139,7 @@ func (g *Generator) multi() error {
 	return err
 }
 
-func (g *Generator) single() error {
+func (g *Generator) single(run operation) error {
 	content := make([]byte, 0)
 	toc := "\n"
 	previous_depth := 0
@@ -177,7 +177,7 @@ func (g *Generator) single() error {
 
 	page := page{
 		Version: g.version,
-		Content: template.HTML(blackfriday.MarkdownCommon(content)),
+		Content: template.HTML(run(content)),
 	}
 	out := filepath.Join(g.Output, "index.html")
 
@@ -198,7 +198,7 @@ func (g *Generator) single() error {
 	return err
 }
 
-func (g *Generator) Generate() error {
+func (g *Generator) Generate(run operation) error {
 	var err error
 	if g.template, err = parseFiles(g.TemplateFile); err != nil {
 		g.L.Error("%s\n", err)
@@ -218,7 +218,7 @@ func (g *Generator) Generate() error {
 	g.L.Debug("generator state: %+v", g)
 
 	if g.Book {
-		return g.single()
+		return g.single(run)
 	}
-	return g.multi()
+	return g.multi(run)
 }

+ 1 - 1
generator_test.go

@@ -1,4 +1,4 @@
-package staticmd
+package static
 
 import (
 	"html/template"

+ 1 - 1
navigation.go

@@ -1,4 +1,4 @@
-package staticmd
+package static
 
 type navigation struct {
 	Link  string

+ 1 - 1
page.go

@@ -1,4 +1,4 @@
-package staticmd
+package static
 
 import "html/template"
 

+ 2 - 2
readme.md

@@ -1,11 +1,11 @@
 
-# staticmd
+# [static](https://github.com/cdelorme/static)
 
 This is a go library written to provide static generation of html from markdown with a template.
 
 The intended function is to make it easy to convert large folders of documentation in bulk to explorable web content or a single-page document for printing as a PDF and redistributing.
 
-_This project was used as a means of self-education for learning the go programming language and tooling._
+_The original goal of the project was to learn more about the programming language and tooling._
 
 
 ## design

+ 1 - 1
staticmd.go

@@ -1,4 +1,4 @@
-package staticmd
+package static
 
 import (
 	"os"

+ 1 - 1
staticmd_test.go

@@ -1,4 +1,4 @@
-package staticmd
+package static
 
 import (
 	"errors"