{"id":15369982,"url":"https://github.com/alexkappa/mustache","last_synced_at":"2025-06-26T06:34:20.147Z","repository":{"id":22453779,"uuid":"25792243","full_name":"alexkappa/mustache","owner":"alexkappa","description":"Mustache templating language in Go","archived":false,"fork":false,"pushed_at":"2024-08-07T03:06:55.000Z","size":41,"stargazers_count":73,"open_issues_count":5,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T22:17:02.149Z","etag":null,"topics":["go","mustache","parsing"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"koreatech/JudgeOnline","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexkappa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-26T21:43:44.000Z","updated_at":"2024-08-08T22:59:13.000Z","dependencies_parsed_at":"2024-06-18T18:35:38.378Z","dependency_job_id":"1bcd8cd9-7380-4d59-aff7-e2a54893b530","html_url":"https://github.com/alexkappa/mustache","commit_stats":{"total_commits":61,"total_committers":5,"mean_commits":12.2,"dds":"0.14754098360655743","last_synced_commit":"4281da416fc5f5e8c5b138c1d926cc0d3032fc11"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexkappa%2Fmustache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexkappa%2Fmustache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexkappa%2Fmustache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexkappa%2Fmustache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexkappa","download_url":"https://codeload.github.com/alexkappa/mustache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237320552,"owners_count":19290738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","mustache","parsing"],"created_at":"2024-10-01T13:39:29.918Z","updated_at":"2025-02-05T15:08:32.653Z","avatar_url":"https://github.com/alexkappa.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mustache\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/alexkappa/mustache.svg)](https://pkg.go.dev/github.com/alexkappa/mustache)\n[![Go Build](https://github.com/alexkappa/mustache/actions/workflows/go.yml/badge.svg)](https://github.com/alexkappa/mustache/actions/workflows/go.yml)\n\nThis is an implementation of the mustache templating language in Go.\n\nIt is inspired by [hoisie/mustache](https://github.com/hoisie/mustache) however\nit's not a fork, but rather a re-implementation with improved spec conformance,\nand a more flexible API (e.g. support for `io.Writer` and `io.Reader`).\n\nIt is built using lexing techniques described in the slides on [lexical scanning\nin Go](https://talks.golang.org/2011/lex.slide), and functional options as\ndescribed in the blog post on [self-referential functions and the design of\noptions](http://commandcenter.blogspot.nl/2014/01/self-referential-functions-and-design.html).\n\nThis package aims to cover 100% of the mustache specification tests, however, by\nthe time of this writing, it is not complete.\n\nFor more information on mustache check the [official\ndocumentation](http://mustache.github.io/) and the [mustache\nspec](http://github.com/mustache/spec).\n\n# Installation\n\nInstall with `go get github.com/alexkappa/mustache`.\n\n# Documentation\n\nThe API documentation is available at\n[godoc.org](https://pkg.go.dev/github.com/alexkappa/mustache).\n\n# Usage\n\nThe core of this package is the `Template`, and its `Parse` and `Render`\nfunctions.\n\n```Go\ntemplate := mustache.New()\ntemplate.Parse(strings.NewReader(\"Hello, {{subject}}!\"))\ntemplate.Render(os.Stdout, map[string]string{\"subject\": \"world\"})\n```\n\n## Helpers\n\nThere are additional `Parse` and `Render` helpers to deal with different kinds\nof input or output, such as `string`, `[]byte` or `io.Writer`/`io.Reader`.\n\n```Go\nParse(r io.Reader) error\nParseString(s string) error\nParseBytes(b []byte) error\n```\n\n```Go\nRender(w io.Writer, context interface{}) error\nRenderString(context interface{}) (string, error)\nRenderBytes(context interface{}) ([]byte, error)\n```\n\n### Reader/Writer\n\n```Go\nf, err := os.Open(\"template.mustache\")\nif err != nil {\n    fmt.Fprintf(os.Stderr, \"failed to open file: %s\\n\", err)\n}\nt, err := Parse(f)\nif err != nil {\n    fmt.Fprintf(os.Stderr, \"failed to parse template: %s\\n\", err)\n}\nt.Render(os.Stdout, nil)\n```\n\n**Note:** in the example above, we used\n[Parse](https://pkg.go.dev/github.com/alexkappa/mustache#Parse) which wraps the\n`t := New()` and `t.Parse()` functions for conciseness.\n\n### String\n\n```Go\nt := mustache.New()\nerr := t.ParseString(\"Hello, {{subject}}!\")\nif err != nil {\n    // handle error\n}\ns, _ := t.RenderString(map[string]string{\"subject\": \"world\"})\nif err != nil {\n    // handle error\n}\nfmt.Println(s)\n```\n\n## Options\n\nIt is possible to define some options on the template, which will alter the way\nthe template will parse, render or fail.\n\nThe options are:\n\n- `Name(n string) Option` sets the name of the template. This option is useful\n  when using the template as a partial to another template.\n- `Delimiters(start, end string) Option` sets the start and end delimiters of\n  the template.\n- `Partial(p *Template) Option` sets p as a partial to the template. It is\n  important to set the name of p so that it may be looked up by the parent\n  template.\n- `SilentMiss(silent bool) Option` sets missing variable lookup behavior.\n\nOptions can be defined either as arguments to\n[New](https://pkg.go.dev/github.com/alexkappa/mustache#New) or using the\n[Option](https://pkg.go.dev/github.com/alexkappa/mustache#Template.Option)\nfunction.\n\n## Partials\n\nPartials are templates themselves and can be defined using the\n[Partial](https://pkg.go.dev/github.com/alexkappa/mustache#Partial) option.\n\n**Note:** It is important to name the partial using the\n[Name](https://pkg.go.dev/github.com/alexkappa/mustache#Name) option which should\nmatch the mustache partial tag `{{\u003ename}}` in the parent template.\n\n```Go\ntitle := New(\n    Name(\"header\")        // instantiate and name the template\n    Delimiters(\"|\", \"|\")) // set the mustache delimiters to | instead of {{\n\ntitle.ParseString(\"|title|\") // parse a template string\n\nbody := New()\nbody.Option(Name(\"body\"))\nbody.ParseString(\"{{content}}\")\n\ntemplate := New(\n    SilentMiss(false), // return an error if a variable lookup fails\n    Partial(title),    // register a partial\n    Partial(body))     // and another one...\n\ntemplate.ParseString(\"{{\u003eheader}}\\n{{\u003ebody}}\")\n\ncontext := map[string]interface{}{\n    \"title\":   \"Mustache\",\n    \"content\": \"Logic less templates with Mustache!\",\n}\n\ntemplate.Render(os.Stdout, context)\n```\n\n## Context\n\nWhen rendering, context can be either a `map` or a `struct`. Following are some\nexamples of valid context arguments.\n\n```Go\nctx := map[string]interface{}{\n    \"foo\": \"Hello\",\n    \"bar\": map[string]string{\n        \"baz\": \"World\",\n    }\n}\nmustache.Render(\"{{foo}} {{bar.baz}}\", ctx) // Hello World\n```\n\n```Go\ntype Foo struct { Bar string }\nctx := \u0026Foo{ Bar: \"Hi, from a struct!\" }\nmustache.Render(\"{{Bar}}\", ctx) // Hi, from a struct!\n```\n\n```Go\ntype Foo struct { bar string }\nfunc (f *Foo) Bar() string { return f.bar }\nctx := \u0026Foo{\"Hi, from a method!\"}\nmustache.Render(\"{{Bar}}\", ctx) // Hi, from a method!\n```\n\n```Go\ntype Foo struct { Bar string `tag:\"bar\"` }\nctx := \u0026Foo{ Bar: \"Hi, from a struct tag!\" }\nmustache.Render(\"{{bar}}\", ctx) // Hi, from a struct tag!\n```\n\n# Tests\n\nRun `go test` as usual. If you want to run the spec tests against this package,\nmake sure you've checked out the specs submodule. Otherwise, spec tests will be\nskipped.\n\nCurrently, certain spec tests are skipped as they fail due to an issue with how\nstandalone tags and empty lines are being handled. Inspecting them manually, one\ncan see that the templates render correctly but with some additional `\\n` which\nshould have been omitted. See issue\n[#1](http://github.com/alexkappa/mustache/issues/1).\n\nSee [SPEC.md](https://github.com/alexkappa/mustache/blob/master/SPEC.md) for a\nbreakdown of which spec tests pass and fail.\n\n# Contributing\n\nIf you would like to contribute, head on to the\n[issues](https://github.com/alexkappa/mustache/issues) page for tasks that need\nhelp.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexkappa%2Fmustache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexkappa%2Fmustache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexkappa%2Fmustache/lists"}