Exemple #1
0
func revel_view(project string, template_dir string, modules []string, theme string, force bool) error {
	root_dir, err := gopath_src_dir()
	if err != nil {
		return err
	}
	project_dir := path.Join(root_dir, project)
	revel.ConfPaths = append(revel.ConfPaths, path.Join(project_dir, "conf"))

	db, err := revel_db(project_dir)
	if err != nil {
		return err
	}
	defer db.Close()

	for _, name := range modules {
		tables := []*symbol.Table{}
		if name == "*" {
			tbs, err := symbol.GetAllTables(db)
			if err != nil {
				return err
			}
			tables = append(tables, tbs...)
		} else {
			tb, err := symbol.GetTable(db, name)
			if err != nil {
				return err
			}
			tables = append(tables, tb)
		}

		for _, table := range tables {
			data := map[string]interface{}{
				"project": project,
				"table":   table,
			}

			var scan = func(fn string, fileInfo os.FileInfo, inpErr error) (err error) {
				if !fileInfo.IsDir() {
					return symbol.RenderTemplate(fn,
						path.Join(project_dir, "app", "views", symbol.ModuleName(table.Name()), fileInfo.Name()),
						data, force)
				}
				return nil
			}
			if err := filepath.Walk(path.Join(template_dir, "revel", "views", theme, "crud"), scan); err != nil {
				return err
			}
		}
	}

	return nil
}
Exemple #2
0
func revel_model(project string, template_dir string, moduels []string, force bool) error {
	root_dir, err := gopath_src_dir()
	if err != nil {
		return err
	}
	project_dir := path.Join(root_dir, project)
	revel.ConfPaths = append(revel.ConfPaths, path.Join(project_dir, "conf"))

	db, err := revel_db(project_dir)
	if err != nil {
		return err
	}
	defer db.Close()

	for _, name := range moduels {
		tables := []*symbol.Table{}
		if name == "*" {
			tbs, err := symbol.GetAllTables(db)
			if err != nil {
				return err
			}
			tables = append(tables, tbs...)
		} else {
			tb, err := symbol.GetTable(db, name)
			if err != nil {
				return err
			}
			tables = append(tables, tb)
		}

		for _, table := range tables {
			data := map[string]interface{}{
				"project": project,
				"table":   table,
			}

			if err := symbol.RenderTemplate(path.Join(template_dir, "revel", "models", "model.crud.go.t"),
				path.Join(project_dir, "app", "models", fmt.Sprintf("model.%s.go", symbol.ModuleName(table.Name()))),
				data, force); err != nil {
				return err
			}
		}
	}

	return nil
}
Exemple #3
0
func revel_view(project string, template_dir string, modules []string, theme string, force bool) error {
	root_dir, err := gopath_src_dir()
	if err != nil {
		return err
	}
	project_dir := path.Join(root_dir, project)
	revel.ConfPaths = append(revel.ConfPaths, path.Join(project_dir, "conf"))

	db, err := revel_db(project_dir)
	if err != nil {
		return err
	}
	defer db.Close()

	for _, name := range modules {
		tables := []*symbol.Table{}
		if name == "*" {
			tbs, err := symbol.GetAllTables(db)
			if err != nil {
				return err
			}
			tables = append(tables, tbs...)
		} else {
			tb, err := symbol.GetTable(db, name)
			if err != nil {
				return err
			}
			tables = append(tables, tb)
		}

		for _, table := range tables {
			data := map[string]interface{}{
				"project": project,
				"table":   table,
			}

			if err := symbol.RenderTemplate(path.Join(template_dir, "revel", "views", theme, "crud/create.html"),
				path.Join(project_dir, "app", "views", symbol.ModuleName(table.Name()), "create.html"),
				data, force); err != nil {
				return err
			}

			if err := symbol.RenderTemplate(path.Join(template_dir, "revel", "views", theme, "crud/detail.html"),
				path.Join(project_dir, "app", "views", symbol.ModuleName(table.Name()), "detail.html"),
				data, force); err != nil {
				return err
			}

			if err := symbol.RenderTemplate(path.Join(template_dir, "revel", "views", theme, "crud/index.html"),
				path.Join(project_dir, "app", "views", symbol.ModuleName(table.Name()), "index.html"),
				data, force); err != nil {
				return err
			}

			if err := symbol.RenderTemplate(path.Join(template_dir, "revel", "views", theme, "crud/query.html"),
				path.Join(project_dir, "app", "views", symbol.ModuleName(table.Name()), "query.html"),
				data, force); err != nil {
				return err
			}

			if err := symbol.RenderTemplate(path.Join(template_dir, "revel", "views", theme, "crud/update.html"),
				path.Join(project_dir, "app", "views", symbol.ModuleName(table.Name()), "update.html"),
				data, force); err != nil {
				return err
			}
		}
	}

	return nil
}