Skip to content

Interface change suggestion #55

@crantok

Description

@crantok

This would mean that a literal template and a layout file (or vice versa) could be mixed in the same call. What do you think? If I implemented this would you merge it? The original API would still work.

In client code:

// Order of arguments is irrelevant
output := mustache.Render(
        mustache.Literal( "Here's my data: {{myData}}" ),
        mustache.LayoutFilename("./defaultlayout.mustache"),
        map[string]string{"myData":"Yes, this is my data"} )

In mustache.go:

type dataType int

const (
    uninitialisedDataType dataType = iota
    templateLiteral
    templateFilename
    layoutLiteral
    layoutFilename
)

type templateDescription struct {
    dataType
    data string
}

func Render(args ...interface{}) string {
    // If the first argument is a string then behave as original API
    // If using new API then only use the first occurrences of template and layout
    // ...
}

func Literal(template string) templateDescription {
    return templateDescription{templateLiteral, template}
}

func Filename(filename string) templateDescription {
    return templateDescription{templateFilename, filename}
}

func LayoutLiteral(template string) templateDescription {
    return templateDescription{layoutLiteral, template}
}

func LayoutFilename(filename string) templateDescription {
    return templateDescription{layoutFilename, filename}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions