generate

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActionCmd = &cobra.Command{
	Use:     "action [name] [actionName...]",
	Aliases: []string{"a", "actions"},
	Short:   "Generates new action(s)",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) < 2 {
			return errors.New("you should provide action name and handler name at least")
		}

		if _, err := os.Stat("actions"); err != nil {
			return errors.New("actions directory not found, ensure you're inside your buffalo folder")
		}

		name := args[0]
		actions := args[1:]

		data := gentronics.Data{
			"filename":  inflect.Underscore(name),
			"namespace": inflect.Camelize(name),
		}

		filePath := filepath.Join("actions", fmt.Sprintf("%v.go", data["filename"]))
		actionsTemplate := buildActionsTemplate(filePath)
		testFilePath := filepath.Join("actions", fmt.Sprintf("%v_test.go", data["filename"]))
		testsTemplate := buildTestsTemplate(testFilePath)
		actionsToAdd := findActionsToAdd(name, filePath, actions)
		testsToAdd := findTestsToAdd(name, testFilePath, actions)

		data["actions"] = actionsToAdd
		data["tests"] = testsToAdd

		g := gentronics.New()
		g.Add(gentronics.NewFile(filepath.Join("actions", fmt.Sprintf("%s.go", data["filename"])), actionsTemplate))
		g.Add(gentronics.NewFile(filepath.Join("actions", fmt.Sprintf("%s_test.go", data["filename"])), testsTemplate))
		g.Add(&gentronics.Func{
			Should: func(data gentronics.Data) bool { return true },
			Runner: func(root string, data gentronics.Data) error {
				routes := []string{}
				for _, a := range actions {
					routes = append(routes, fmt.Sprintf("app.GET(\"/%s/%s\", %s)", name, a, data["namespace"].(string)+inflect.Camelize(a)))
				}
				return addInsideAppBlock(routes...)
			},
		})
		addTemplateFiles(actionsToAdd, data)

		if !runningTests {
			g.Add(Fmt)
		}

		return g.Run(".", data)
	},
}

ActionCmd is the cmd that generates actions.

Fmt is command that will use `goimports` if available, or fail back to `gofmt` otherwise.

View Source
var GothCmd = &cobra.Command{
	Use:   "goth [provider provider...]",
	Short: "Generates a actions/goth.go file configured to the specified providers.",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("you must specify at least one provider")
		}
		return NewGothGenerator().Run(".", gentronics.Data{
			"providers": args,
		})
	},
}

GothCmd generates a actions/goth.go file configured to the specified providers.

View Source
var ResourceCmd = &cobra.Command{
	Use:     "resource [name]",
	Aliases: []string{"r"},
	Short:   "Generates a new actions/resource file",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("you must specify a resource name")
		}
		name := args[0]
		data := gentronics.Data{
			"name":         name,
			"singular":     inflect.Singularize(name),
			"plural":       inflect.Pluralize(name),
			"camel":        inflect.Camelize(name),
			"under":        inflect.Underscore(name),
			"downFirstCap": inflect.CamelizeDownFirst(name),
			"actions":      []string{"List", "Show", "New", "Create", "Edit", "Update", "Destroy"},
		}
		return NewResourceGenerator(data).Run(".", data)
	},
}

ResourceCmd generates a new actions/resource file and a stub test.

View Source
var WebpackCmd = &cobra.Command{
	Use:   "webpack",
	Short: "Generates a webpack asset pipeline.",
	RunE: func(cmd *cobra.Command, args []string) error {
		data := gentronics.Data{
			"withWebpack": true,
		}
		return NewWebpackGenerator(data).Run(".", data)
	},
}

WebpackCmd generates a new actions/resource file and a stub test.

View Source
var WebpackPath = filepath.Join("node_modules", ".bin", "webpack")

WebpackPath is the path to the local install of webpack

Functions

func GoGet added in v0.7.0

func GoGet(pkg string) *exec.Cmd

GoGet downloads and installs packages and dependencies

func GoInstall added in v0.7.0

func GoInstall(pkg string) *exec.Cmd

GoInstall compiles and installs packages and dependencies

func NewGothGenerator added in v0.4.7

func NewGothGenerator() *gentronics.Generator

NewGothGenerator a actions/goth.go file configured to the specified providers.

func NewResourceGenerator

func NewResourceGenerator(data gentronics.Data) *gentronics.Generator

NewResourceGenerator generates a new actions/resource file and a stub test.

func NewWebpackGenerator added in v0.5.0

func NewWebpackGenerator(data gentronics.Data) *gentronics.Generator

NewWebpackGenerator generates a new actions/resource file and a stub test.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL