示例#1
0
func DoThings(cfg *config.Config) error {

	r, err := os.Open(filepath.Join(cfg.Basedir(), "doc", "commands-xml", "commands.xml"))
	if err != nil {
		return err
	}
	c, err := commandsxml.ReadCommandsFile(r)
	if err != nil {
		return err
	}
	manualpath = filepath.Join(cfg.Builddir, "manual")

	for _, lang := range []string{"de", "en"} {
		docbase := filepath.Join(cfg.Builddir, "speedatapublisher-"+lang+".docset")
		destpath = filepath.Join(docbase, "Contents", "Resources", "Documents")
		plistpath := filepath.Join(docbase, "Contents", "info.plist")

		err = os.RemoveAll(docbase)
		if err != nil {
			return err
		}

		err = os.MkdirAll(destpath, 0755)
		if err != nil {
			return err
		}

		filepath.Walk(manualpath, cp)

		err = ioutil.WriteFile(plistpath, []byte(plist(lang)), 0644)
		if err != nil {
			return err
		}

		db, err := sql.Open("sqlite3", filepath.Join(docbase, "Contents", "Resources", "docSet.dsidx"))
		if err != nil {
			return err
		}
		defer db.Close()

		_, err = db.Exec(`CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);`)
		if err != nil {
			return err
		}

		for _, v := range c.CommandsEn {
			_, err = db.Exec(`INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?, ?, ?);`, v.NameEn, "Command", filepath.Join("commands-"+lang, v.Htmllink()))
			if err != nil {
				return err
			}
			for _, attr := range v.Attributes() {
				_, err = db.Exec(`INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?, ?, ?);`, attr.NameEn, "Function", filepath.Join("commands-"+lang, v.Htmllink()+"#"+attr.HTMLFragment()))
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
示例#2
0
func DoThings(cfg *config.Config) error {
	r, err := os.Open(filepath.Join(cfg.Basedir(), "doc", "commands-xml", "commands.xml"))
	if err != nil {
		return err
	}
	c, err := commandsxml.ReadCommandsFile(r)
	if err != nil {
		return err
	}
	for _, cmd := range c.CommandsEn {
		cmd.Childelements("en")
	}
	outdir := filepath.Join(cfg.Builddir, "manual")
	err = os.MkdirAll(outdir, 0755)
	if err != nil {
		return err
	}

	funcMap := template.FuncMap{
		"translate":      translate,
		"attributes":     attributes,
		"childelements":  childelements,
		"parentelements": parentelements,
		"sortedcommands": sortedcommands,
		"footer":         footer,
		"atttypeinfo":    atttypeinfo,
	}
	templates, err = template.New("").Funcs(funcMap).ParseFiles(filepath.Join(cfg.Basedir(), "doc", "manual", "templates", "command.html"))
	if err != nil {
		return err
	}
	os.MkdirAll(filepath.Join(outdir, "commands-en"), 0755)
	os.MkdirAll(filepath.Join(outdir, "commands-de"), 0755)

	version := cfg.Publisherversion.String()
	for _, lang := range []string{"de", "en"} {
		for _, v := range c.CommandsEn {
			fullpath := filepath.Join(outdir, "commands-"+lang, v.Htmllink())
			wg.Add(1)
			go builddoc(c, v, version, lang, fullpath)
		}
	}
	wg.Wait()
	return nil
}