Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface change suggestion #55

Open
crantok opened this issue Jan 15, 2016 · 0 comments
Open

Interface change suggestion #55

crantok opened this issue Jan 15, 2016 · 0 comments

Comments

@crantok
Copy link

crantok commented Jan 15, 2016

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}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant