diff --git a/main.go b/main.go index 690fea6..7d2bd83 100644 --- a/main.go +++ b/main.go @@ -6,12 +6,14 @@ package main import ( "flag" - . "github.com/cmars/represent/pkg/represent" "log" + + . "github.com/cmars/represent/pkg/represent" ) var src *string = flag.String("src", "", "Source path containing Present files and referenced content") var publish *string = flag.String("publish", "", "Publish path to create static HTML pages and assets") +var base *string = flag.String("base", "", "Base path for slide template and static resources") func die(err error, v ...interface{}) { log.Println(append(v, err)...) @@ -19,7 +21,7 @@ func die(err error, v ...interface{}) { func main() { flag.Parse() - represent, err := NewRepresent(*src, *publish) + represent, err := NewRepresent(*src, *publish, *base) if err != nil { die(err) } diff --git a/pkg/represent/dir.go b/pkg/represent/dir.go index 5d73fc6..39281ff 100644 --- a/pkg/represent/dir.go +++ b/pkg/represent/dir.go @@ -26,6 +26,11 @@ func isDoc(path string) bool { return ok } +// since we're writing static html nothing will be playable. +func playable(c present.Code) bool { + return false +} + // parse reads the given file path and parses into a Present document structure. func parse(name string, mode present.ParseMode) (*present.Doc, error) { f, err := os.Open(name) @@ -59,6 +64,12 @@ func renderDoc(w io.Writer, base, docFile string) error { // Read and parse the input. tmpl := present.Template() + + funcmap := make(map[string]interface{}, 1) + funcmap["playable"] = playable + + tmpl = tmpl.Funcs(funcmap) + if _, err := tmpl.ParseFiles(actionTmpl, contentTmpl); err != nil { return err } diff --git a/pkg/represent/represent.go b/pkg/represent/represent.go index bbb5470..489d312 100644 --- a/pkg/represent/represent.go +++ b/pkg/represent/represent.go @@ -14,7 +14,6 @@ import ( ) const REPRESENT_PKG = "github.com/cmars/represent" -const PRESENT_PKG = "golang.org/x/tools/present" // Represent provides functions to publish a directory tree of files // in the Present format. @@ -28,13 +27,17 @@ type Represent struct { // for processing the given base directory. If srcDir is // the empty string, base directory is assumed to be the // current working directory. -func NewRepresent(srcDir, publishDir string) (*Represent, error) { +func NewRepresent(srcDir, publishDir, baseDir string) (*Represent, error) { // Discern where the represent package source is, so we can // locate the static files. - p, err := build.Default.Import(REPRESENT_PKG, "", build.FindOnly) - if err != nil { - return nil, err + if baseDir == "" { + p, err := build.Default.Import(REPRESENT_PKG, "", build.FindOnly) + if err != nil { + return nil, err + } + baseDir = p.Dir } + var err error // Resolve default source directory if srcDir == "" { srcDir, err = os.Getwd() @@ -48,7 +51,7 @@ func NewRepresent(srcDir, publishDir string) (*Represent, error) { } r := &Represent{srcDir: srcDir, publishDir: publishDir, - presentPkgDir: p.Dir} + presentPkgDir: baseDir} err = r.requirePublishDir() return r, err }