Update formatting in doc comments
This commit is contained in:
parent
b72767868f
commit
73cb38fdcf
11
doc.go
11
doc.go
|
@ -5,14 +5,14 @@ Stick executes Twig templates and allows users to define custom Functions,
|
|||
Filters, and Tests. The parser allows parse-time node inspection with
|
||||
NodeVisitors, and a template Loader to load named templates from any source.
|
||||
|
||||
Twig compatibility
|
||||
# Twig compatibility
|
||||
|
||||
Stick itself is a parser and template executor. If you're looking for Twig
|
||||
compatibility, check out package https://pkg.go.dev/github.com/tyler-sommer/stick/twig
|
||||
|
||||
For additional information on Twig, check http://twig.sensiolabs.org/
|
||||
|
||||
Basic usage
|
||||
# Basic usage
|
||||
|
||||
Obligatory "Hello, World!" example:
|
||||
|
||||
|
@ -38,8 +38,7 @@ Another example, using a FilesystemLoader and responding to an HTTP request:
|
|||
})
|
||||
http.ListenAndServe(":80", nil)
|
||||
|
||||
|
||||
Types and values
|
||||
# Types and values
|
||||
|
||||
Any user value in Stick is represented by a stick.Value. There are three main types
|
||||
in Stick when it comes to built-in operations: strings, numbers, and booleans. Of note,
|
||||
|
@ -81,8 +80,7 @@ number, or boolean, respectively.
|
|||
// Coerce any vale to a boolean
|
||||
b := stick.CoerceBool(anything)
|
||||
|
||||
|
||||
User defined helpers
|
||||
# User defined helpers
|
||||
|
||||
It is possible to define custom Filters, Functions, and boolean Tests available to
|
||||
your Stick templates. Each user-defined type is simply a function with a specific
|
||||
|
@ -125,6 +123,5 @@ User-defined types are added to an Env after it is created. For example:
|
|||
// Probably not that useful.
|
||||
return stick.CoerceBool(val) == false
|
||||
}
|
||||
|
||||
*/
|
||||
package stick
|
||||
|
|
|
@ -64,7 +64,7 @@ func ExampleCoerceBool() {
|
|||
// This demonstrates how a type can be coerced to a number.
|
||||
// The struct in this example has the Number method implemented.
|
||||
//
|
||||
// func (e exampleType) Number() float64 {
|
||||
// func (e exampleType) Number() float64 {
|
||||
// return 3.14
|
||||
// }
|
||||
func ExampleNumber() {
|
||||
|
|
2
exec.go
2
exec.go
|
@ -165,7 +165,7 @@ func (s *scopeStack) Set(name string, val Value) {
|
|||
// without destroying the value in the parent scope.
|
||||
//
|
||||
// fnParam := // an function argument's name
|
||||
// s.scope.push()
|
||||
// s.scope.push()
|
||||
// defer s.scope.pop()
|
||||
// s.scope.setLocal(fnParam, "some value")
|
||||
func (s *scopeStack) setLocal(name string, val Value) {
|
||||
|
|
|
@ -280,6 +280,7 @@ func (t *EmbedNode) All() []Node {
|
|||
|
||||
// A UseNode represents the inclusion of blocks from another template.
|
||||
// It is also possible to specify aliases for the imported blocks to avoid naming conflicts.
|
||||
//
|
||||
// {% use '::blocks.html.twig' with main as base_main, left as base_left %}
|
||||
type UseNode struct {
|
||||
Pos
|
||||
|
|
|
@ -155,6 +155,7 @@ func (t *Tree) parseOuterExpr(expr Expr) (Expr, error) {
|
|||
|
||||
// parseIsRightOperand handles "is" and "is not" tests, which can
|
||||
// themselves be two words, such as "divisible by":
|
||||
//
|
||||
// {% if 10 is divisible by(3) %}
|
||||
func (t *Tree) parseRightTestOperand(prev *NameExpr) (*TestExpr, error) {
|
||||
right, err := t.parseInnerExpr()
|
||||
|
|
|
@ -108,7 +108,7 @@ func (t *Tree) parseUntilTag(start Pos, names ...string) (*BodyNode, error) {
|
|||
|
||||
// parseExtends parses an extends tag.
|
||||
//
|
||||
// {% extends <expr> %}
|
||||
// {% extends <expr> %}
|
||||
func parseExtends(t *Tree, start Pos) (Node, error) {
|
||||
if t.Root().Parent != nil {
|
||||
return nil, newMultipleExtendsError(start)
|
||||
|
@ -129,8 +129,8 @@ func parseExtends(t *Tree, start Pos) (Node, error) {
|
|||
// parseBlock parses a block and any body it may contain.
|
||||
// TODO: {% endblock <name> %} support
|
||||
//
|
||||
// {% block <name> %}
|
||||
// {% endblock %}
|
||||
// {% block <name> %}
|
||||
// {% endblock %}
|
||||
func parseBlock(t *Tree, start Pos) (Node, error) {
|
||||
blockName, err := t.expect(tokenName)
|
||||
if err != nil {
|
||||
|
@ -152,8 +152,8 @@ func parseBlock(t *Tree, start Pos) (Node, error) {
|
|||
|
||||
// parseIf parses the opening tag and conditional expression in an if-statement.
|
||||
//
|
||||
// {% if <expr> %}
|
||||
// {% elseif <expr> %}
|
||||
// {% if <expr> %}
|
||||
// {% elseif <expr> %}
|
||||
func parseIf(t *Tree, start Pos) (Node, error) {
|
||||
cond, err := t.parseExpr()
|
||||
if err != nil {
|
||||
|
@ -172,8 +172,8 @@ func parseIf(t *Tree, start Pos) (Node, error) {
|
|||
|
||||
// parseIfBody parses the body of an if statement.
|
||||
//
|
||||
// {% else %}
|
||||
// {% endif %}
|
||||
// {% else %}
|
||||
// {% endif %}
|
||||
func parseIfBody(t *Tree, start Pos) (body *BodyNode, els *BodyNode, err error) {
|
||||
body = NewBodyNode(start)
|
||||
for {
|
||||
|
@ -235,10 +235,10 @@ func parseIfBody(t *Tree, start Pos) (body *BodyNode, els *BodyNode, err error)
|
|||
// parseFor parses a for loop construct.
|
||||
// TODO: This needs proper error reporting.
|
||||
//
|
||||
// {% for <name, [name]> in <expr> %}
|
||||
// {% for <name, [name]> in <expr> if <expr> %}
|
||||
// {% else %}
|
||||
// {% endfor %}
|
||||
// {% for <name, [name]> in <expr> %}
|
||||
// {% for <name, [name]> in <expr> if <expr> %}
|
||||
// {% else %}
|
||||
// {% endfor %}
|
||||
func parseFor(t *Tree, start Pos) (*ForNode, error) {
|
||||
var kn, vn string
|
||||
nam, err := t.parseInnerExpr()
|
||||
|
@ -370,10 +370,10 @@ func parseEmbed(t *Tree, start Pos) (Node, error) {
|
|||
// parseIncludeOrEmbed parses an include or embed tag's parameters.
|
||||
// TODO: Implement "ignore missing" support
|
||||
//
|
||||
// {% include <expr> %}
|
||||
// {% include <expr> with <expr> %}
|
||||
// {% include <expr> with <expr> only %}
|
||||
// {% include <expr> only %}
|
||||
// {% include <expr> %}
|
||||
// {% include <expr> with <expr> %}
|
||||
// {% include <expr> with <expr> only %}
|
||||
// {% include <expr> only %}
|
||||
func parseIncludeOrEmbed(t *Tree) (expr Expr, with Expr, only bool, err error) {
|
||||
expr, err = t.parseExpr()
|
||||
if err != nil {
|
||||
|
@ -475,7 +475,7 @@ func parseUse(t *Tree, start Pos) (Node, error) {
|
|||
|
||||
// parseSet parses a set statement.
|
||||
//
|
||||
// {% set <var> = <expr> %}
|
||||
// {% set <var> = <expr> %}
|
||||
func parseSet(t *Tree, start Pos) (Node, error) {
|
||||
tok, err := t.expect(tokenName)
|
||||
if err != nil {
|
||||
|
@ -498,7 +498,7 @@ func parseSet(t *Tree, start Pos) (Node, error) {
|
|||
|
||||
// parseDo parses a do statement.
|
||||
//
|
||||
// {% do <expr> %}
|
||||
// {% do <expr> %}
|
||||
func parseDo(t *Tree, start Pos) (Node, error) {
|
||||
expr, err := t.parseExpr()
|
||||
if err != nil {
|
||||
|
@ -513,11 +513,11 @@ func parseDo(t *Tree, start Pos) (Node, error) {
|
|||
|
||||
// parseFilter parses a filter statement.
|
||||
//
|
||||
// {% filter <name> %}
|
||||
// {% filter <name> %}
|
||||
//
|
||||
// Multiple filters can be applied to a block:
|
||||
//
|
||||
// {% filter <name>|<name>|<name> %}
|
||||
// {% filter <name>|<name>|<name> %}
|
||||
func parseFilter(t *Tree, start Pos) (Node, error) {
|
||||
var filters []string
|
||||
for {
|
||||
|
@ -550,7 +550,7 @@ body:
|
|||
|
||||
// parseMacro parses a macro definition.
|
||||
//
|
||||
// {% macro <name>([ arg [ , arg]) %}
|
||||
// {% macro <name>([ arg [ , arg]) %}
|
||||
// Macro body
|
||||
// {% endmacro %}
|
||||
func parseMacro(t *Tree, start Pos) (Node, error) {
|
||||
|
@ -598,7 +598,7 @@ body:
|
|||
|
||||
// parseImport parses an import statement.
|
||||
//
|
||||
// {% import <name> as <alias> %}
|
||||
// {% import <name> as <alias> %}
|
||||
func parseImport(t *Tree, start Pos) (Node, error) {
|
||||
name, err := t.parseExpr()
|
||||
if err != nil {
|
||||
|
@ -621,7 +621,7 @@ func parseImport(t *Tree, start Pos) (Node, error) {
|
|||
|
||||
// parseImport parses an import statement.
|
||||
//
|
||||
// {% from <name> import <name>[ as <alias>[ , <name... ] ] %}
|
||||
// {% from <name> import <name>[ as <alias>[ , <name... ] ] %}
|
||||
func parseFrom(t *Tree, start Pos) (Node, error) {
|
||||
name, err := t.parseExpr()
|
||||
if err != nil {
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
//
|
||||
// A simple example might look like:
|
||||
//
|
||||
// env := twig.New(nil); // A nil loader means stick will execute
|
||||
// // the string passed into env.Execute.
|
||||
// env := twig.New(nil); // A nil loader means stick will execute
|
||||
// // the string passed into env.Execute.
|
||||
//
|
||||
// // Templates receive a map of string to any value.
|
||||
// p := map[string]stick.Value{"name": "World"}
|
||||
// // Templates receive a map of string to any value.
|
||||
// p := map[string]stick.Value{"name": "World"}
|
||||
//
|
||||
// // Substitute os.Stdout with any io.Writer.
|
||||
// env.Execute("Hello, {{ name }}!", os.Stdout, p)
|
||||
// // Substitute os.Stdout with any io.Writer.
|
||||
// env.Execute("Hello, {{ name }}!", os.Stdout, p)
|
||||
//
|
||||
// Check the main package https://pkg.go.dev/github.com/tyler-sommer/stick for
|
||||
// more information on general functionality and usage.
|
||||
|
|
Reference in a new issue