Example #1
0
// MarkFriday combines a fs.FilReader with a markdown processor which then pipes into a fs.FileWriter to save the output
func MarkFriday(m MarkConfig) flux.Reactor {
	if m.Ext == "" {
		m.Ext = ".md"
	}

	var markdown flux.Reactor

	if m.Sanitize {
		markdown = BlackMonday()
	} else {
		markdown = BlackFriday()
	}

	reader := fs.FileReader()

	// reader.React(flux.SimpleMuxer(func(root flux.Reactor, data interface{}) {
	// 	log.Printf("reader %s", data)
	// }), true)

	writer := fs.FileWriter(func(path string) string {
		var dir string

		if m.PathMux != nil {
			dir = m.PathMux(m, path)
		} else {
			//get the current directory of the path
			cdir := filepath.Dir(path)

			//if we have a preset folder replace it
			if m.SaveDir != "" {
				cdir = m.SaveDir
			}

			// strip out the directory from the path and only use the base name
			base := filepath.Base(path)

			//combine with the dir for the final path
			dir = filepath.Join(cdir, base)
		}

		//grab our own extension
		ext := strings.Replace(m.Ext, ".", "", -1)

		//strip off the extension and add ours
		return strings.Replace(dir, filepath.Ext(dir), fmt.Sprintf(".%s", ext), -1)
	})

	stack := flux.ReactStack(reader)
	stack.Bind(FileRead2RenderFile(), true)
	stack.Bind(markdown, true)
	stack.Bind(RenderFile2FileWrite(), true)
	stack.Bind(MutateFileWrite(m.BeforeWrite), true)
	stack.Bind(writer, true)

	return stack
}
Example #2
0
// JSLauncher returns a reactor that on receiving a signal builds the gopherjs package as giving in the config and writes it out using a FileWriter
func JSLauncher(config JSBuildConfig) flux.Reactor {
	stack := flux.ReactStack(JSBuildLauncher(config))
	stack.Bind(fs.FileWriter(nil), true)
	return stack
}