Documentation
¶
Overview ¶
Package strlang provides a string builder with indentation support, it allows you to generate code using a fluent string builder interface.
Index ¶
- type Builder
- func (b *Builder) Block(start string, f func(), end string, ln ...int)
- func (b *Builder) Indent(nb ...int)
- func (b *Builder) SetIndentChar(s string)
- func (b *Builder) String() string
- func (b *Builder) StripIndent(nb ...int)
- func (b *Builder) TrimLeft(cutset string)
- func (b *Builder) TrimRight(cutset string)
- func (b *Builder) Write(p []byte)
- func (b *Builder) WriteNoIdentString(s string)
- func (b *Builder) WriteString(s string)
- func (b *Builder) WriteStringln(s string, nb ...int)
- type Golang
- func (b *Golang) AddImports(imports ...string)
- func (b *Golang) Else(inside func(), ln ...int)
- func (b *Golang) ElseIf(statement string, inside func(), ln ...int)
- func (b *Golang) Func(fromStruct, name, parameters, output string, inside func())
- func (b *Golang) If(statement string, inside func(), ln ...int)
- func (b *Golang) String() string
- func (b *Golang) Struct(name string, inside func())
- func (b *Golang) StructField(name, goType string, docs ...map[string]string)
- type Javascript
- type PHP
- func (b *PHP) Class(name string, inside func())
- func (b *PHP) ClassFunc(modifiers, name, parameters, output string, inside func())
- func (b *PHP) Else(inside func())
- func (b *PHP) ElseIf(statement string, inside func())
- func (b *PHP) If(statement string, inside func(), ln ...int)
- func (b *PHP) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is the base builder of the strlang package
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder returns a new instance of Builder with default settings: an empty strings.Builder and an indentation character of two spaces.
func (*Builder) Block ¶
Block writes the start string, indents the builder, calls the provided function f, strips the indent, and writes the end string with a newline character. Optionally, it can write additional newline characters with the ln argument.
func (*Builder) Indent ¶
Indent increases the current indentation level by the number of spaces passed as an optional argument. The default indentation increase is two spaces.
func (*Builder) SetIndentChar ¶
SetIndentChar sets the indentation character for the builder. The default indentation character is one tab.
func (*Builder) StripIndent ¶
StripIndent decreases the current indentation level by the number of spaces passed as an optional argument. The default indentation decrease is two spaces.
func (*Builder) TrimLeft ¶
TrimLeft trims the resulting string from the builder by removing characters from the left side of the string that are contained in the provided cutset string.
func (*Builder) TrimRight ¶
TrimRight trims the resulting string from the builder by removing characters from the right side of the string that are contained in the provided cutset string.
func (*Builder) Write ¶
Write writes a byte slice to the builder with indentation. It adds the current indentation characters before the provided byte slice.
func (*Builder) WriteNoIdentString ¶
WriteNoIdentString writes a string to the builder without indentation.
func (*Builder) WriteString ¶
WriteString writes a string to the builder without adding a newline character.
func (*Builder) WriteStringln ¶
WriteStringln writes a string with a newline character to the builder. Optionally, it can write multiple newline characters by passing an integer argument.
type Golang ¶
type Golang struct {
// Builder is an embedded struct that represents
// the base builder for generating the Go code.
*Builder
// contains filtered or unexported fields
}
Golang represents a Golang code generator that extends the Builder struct.
func (*Golang) AddImports ¶
AddImports adds import statements to the generated code.
type Javascript ¶
type Javascript struct {
// Builder is an embedded struct that represents
// the base builder for generating the Javascript code.
*Builder
}
Javascript represents a JavaScript code generator that extends the Builder struct.
func NewJavascript ¶
func NewJavascript() *Javascript
NewJavascript returns a new instance of Javascript code builder.
func (*Javascript) Else ¶
func (b *Javascript) Else(inside func())
Else generates an else statement in the generated code.
func (*Javascript) ElseIf ¶
func (b *Javascript) ElseIf(statement string, inside func())
ElseIf generates an else if statement in the generated code.
func (*Javascript) Export ¶
func (b *Javascript) Export() *Javascript
Export appends the "export" keyword and allows to define an exportable object or variable.
func (*Javascript) If ¶
func (b *Javascript) If(statement string, inside func())
If generates an if statement in the generated code.
func (*Javascript) Object ¶
func (b *Javascript) Object(varType, name string, inside func())
Object generates an object block with the provided variable type, name, and inside function.
type PHP ¶
type PHP struct {
// Builder is an embedded struct that represents
// the base builder for generating the PHP code.
*Builder
// contains filtered or unexported fields
}
PHP represents a PHP code generator that extends the Builder struct.
func (*PHP) Else ¶
func (b *PHP) Else(inside func())
Else generates an else statement in the generated code.