示例#1
0
文件: main.go 项目: watilde/gcss
func main() {
	v := flag.Bool("v", false, "Print the version and exit.")

	flag.Parse()

	if *v {
		writeTo(os.Stdout, gcss.Version)
		exit(0)
		return
	}

	args := flag.Args()
	argsL := len(args)

	if argsL > validArgsLen {
		writeTo(os.Stderr, "The number of the command line args should be 1.")
		exit(1)
		return
	}

	if argsL == 0 {
		if _, err := gcss.Compile(os.Stdout, stdin); err != nil {
			writeTo(os.Stderr, err.Error())
			exit(1)
			return
		}
	} else {
		pathc, errc := gcss.CompileFile(args[0])

		select {
		case path := <-pathc:
			writeTo(os.Stdout, "compiled "+path)
		case err := <-errc:
			writeTo(os.Stderr, err.Error())
			exit(1)
			return
		}
	}
}
示例#2
0
文件: expose.go 项目: Moter8/expose
func main() {

	file, readErr := ioutil.ReadFile("config.yaml")
	if readErr != nil {
		log.Fatalf("Could not %s", readErr)
	}

	yamlConfig := string(file)

	cfg, cfgErr := config.ParseYaml(yamlConfig)
	if cfgErr != nil {
		log.Fatalf("Please verify the config file's syntax at http://yamllint.com/ %s", cfgErr)
	}

	_, gcssErr := gcss.CompileFile("expose.gcss")
	if gcssErr != nil {
		log.Fatal("Unable to compile gcss file")
	}
	fmt.Println("CSS compiled succesfully")

	imgBaseURL, cfgErr := cfg.String("imgBaseURL")
	if cfgErr != nil {
		log.Fatal(cfgErr)
	}

	jsonData, jsonErr := os.Open("object.json")
	if jsonErr != nil {
		log.Fatal(jsonErr)
	}

	defer jsonData.Close()

	object, decodeErr := decodeObject(jsonData)
	if decodeErr != nil {
		log.Fatal(decodeErr)
	}
	fmt.Println("JSON decoded succesfully")

	objectMap, makeMapError := createMap(object, imgBaseURL)
	if makeMapError != nil {
		log.Fatal(makeMapError)
	}

	//fmt.Println("Object Map:", &objectMap)

	tpl, aceErr := ace.Load("expose", "", nil)
	if aceErr != nil {
		log.Fatal(aceErr)
	}

	// Need a buffer for the template function
	buf := new(bytes.Buffer)

	templateErr := tpl.Execute(buf, objectMap)
	if templateErr != nil {
		log.Fatal("Unable to execute template", templateErr)
	} else {
		fmt.Println("Template executed succesfully")
	}

	// Write html buffer to file
	fileErr := ioutil.WriteFile("expose.html", []byte(buf.String()), 0644)
	if fileErr != nil {
		log.Panic(fileErr)
	}
	fmt.Println("HTML written succesfully")

	// with wrapper
	result, gopdfErr := gopdf.Url2pdf("expose.html")
	fmt.Println(gopdfErr)

	_ = ioutil.WriteFile("expose.pdf", result, 0644)

	// without wrapper, takes less time

	/*
		_, wkErr := exec.Command("wkhtmltopdf", "expose.html", "expose.pdf").Output()
		if wkErr != nil {
			log.Fatal(wkErr)
		}
	*/

	fmt.Println("PDF written succesfully")

	fmt.Println("Success!")
}