codegen

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderStringFromGenerator

func RenderStringFromGenerator(s string, g Generator) (string, error)

RenderStringFromGenerator receives a Generator that is used to render the received template string.

func RenderTemplate added in v0.3.0

func RenderTemplate(templateName string, templateString string, data interface{}) (string, error)

RenderTemplate parses and returns the rendered string of the provided template. The template is also assigned the provided name for reference.

TODO: How can we compose a template of embedded templates to help scale?

Templates are stored as map[string]*Template - ("someName": *Template).
https://stackoverflow.com/questions/41176355/go-template-name

Types

type CodeGen

type CodeGen struct {
	TemplateDir     string
	TemplateName    string
	DestinationDir  string
	DestinationFile string
	Source          Path
	Destination     Path
}

func (*CodeGen) WriteFile

func (c *CodeGen) WriteFile(g Generator) error

WriteFile creates a new file, where the output from rendering template using the received Generator will be stored.

func (*CodeGen) WriteFileFromTemplateString added in v0.3.0

func (c *CodeGen) WriteFileFromTemplateString(g Generator, templateString string) error

type Generator

type Generator interface {
	Generate(*schema.Schema, *config.GeneratorConfig, *config.PackageConfig) error
	Execute(*config.GeneratorConfig, *config.PackageConfig) error
}

Generator aspires to implement the interface between a NerdGraph schema and generated code for another project.

type Path

type Path struct {
	// Directory is the path to directory that will store the file, eg: pkg/nerdgraph
	Directory string
	// File is the name of the file within the directory
	File string
}

Jump to

Keyboard shortcuts

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