Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ 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)...)
}

func main() {
flag.Parse()
represent, err := NewRepresent(*src, *publish)
represent, err := NewRepresent(*src, *publish, *base)
if err != nil {
die(err)
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/represent/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/represent/represent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand All @@ -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
}
Expand Down