{"id":20191400,"url":"https://github.com/htfy96/reformism","last_synced_at":"2026-05-10T01:04:53.542Z","repository":{"id":86702025,"uuid":"65796467","full_name":"htfy96/reformism","owner":"htfy96","description":"Utilities to empower Go's native template","archived":false,"fork":false,"pushed_at":"2016-08-19T02:02:39.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T18:52:34.431Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/htfy96.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":"2016-08-16T07:12:49.000Z","updated_at":"2018-01-15T17:07:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d67c459-730b-4de3-b647-54f3da0c192d","html_url":"https://github.com/htfy96/reformism","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Freformism","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Freformism/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Freformism/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Freformism/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/htfy96","download_url":"https://codeload.github.com/htfy96/reformism/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241629736,"owners_count":19993707,"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":[],"created_at":"2024-11-14T03:48:44.799Z","updated_at":"2025-12-01T06:07:24.025Z","avatar_url":"https://github.com/htfy96.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reformism\nUtilities to empower Go's `{text/html}/template`.\n\n## Usage\n### Example\n```go\nimport (\n    \"github.com/htfy96/reformism\"\n    \"text/template\"\n    \"os\"\n)\n\nconst template_text = `\n{{define \"foo\"}}\n\t{{if $args := . | require \"arg1\" | require \"arg2\" \"int\" | args }}\n\t    {{with .Origin }} // Original dot\n\t\t\t{{.Bar}}\n\t\t\t{{$args.arg1}}\n\t\t{{ end }}\n\t{{ end }}\n{{ end }}\n\n\n{{ $x := slice 1 2 3 }}\n\n{{ range $y := $x }}\n    {{$y}},\n{{end}}\n// Result 1,2,3,\n\n{{ $r0 := rng 5 }}\n{{ range $e := $r0 }}\n    {{$e}},\n{{ end }}\n// result: 0,1,2,3,4\n\n{{ $r1 := rng 1,5 }}\n{{ range $e := $r1 }}\n    {{$e}},\n{{ end }}\n// result: 1,2,3,4,\n\n{{ $r1_app := $r1 | append 5 6 }}\n{{ $r1_app }}\n// result 1,2,3,4,5,6\n\n{{ $r2 := rng 10, 1, -3 }}\n{{ range $e := $r2 }}\n    {{$e}},\n{{end}}\n// result: 10,7,4,\n\n{{ $el := \"1,2,3\" | split \",\" }}\n{{$el}};\n{{end}}\n// result 1;2;3;\n\n{{ $el := \"1,2,3\" | split \",\" | join \";\" }}\n{{ $el }}\n{{end}}\n// result 1;2;3\n\n{{ $m := map \"foo\" 1 | map \"bar\" 2 }}\n{{ range $k, $v := $m }}\n    {{$k}}:{{$v}},\n{{end}}\n// Result: bar:1,foo:2,\n\t\t\n{{ template \"foo\" . | arg \"arg1\" \"Arg1\" | arg \"arg2\" 42 }}\n{{ template \"foo\" . | arg \"arg1\" \"Arg1\" | arg \"arg2\" \"42\" }} // will raise an error`\n\n\nfunc main() {\n    renderContext := map[string]string {\n        \"Bar\": \"bar\",\n    }\n    t := template.Must(\n        template.New(\"test_template\").Funcs(\n            reformism.FuncsText, // Use .FuncsHTML for html/template\n        ).Parse(template_text))\n    t.Execute(os.Stdout, renderContext)\n}\n```\n\n### Docs\nThis package provides several utility functions for `{text/html}/template`, \nmappings to which are defined in `.FuncsText`(for `text/template`) and \n `.FuncsHTML`(for `html/template`)\n \n#### slice\n```\n{{ slice 1 2 \"abc\" }}\n```\n\nmake `[]interface{}`\n\n#### rng\n```\n{{ rng {{count}} }} // 0, ..., count-1\n{{ rng {{start}} {{end}} }}\n{{ rng {{start}} {{end}} {{step}} }}\n```\nmake `[]int` in given range\n\n#### append\n```\n{{ append el1, el2, ..., slice }}\n{{ slice | append el1, el2 }}\n```\n\nappend elements to given slice\n\n#### split\n```\n{{ split \"separator\" \"str\" }}\n{{ \"str\" | split \"separator\" }}\n```\nsplit `string` by given separator to `[]string`\n\n#### join\n```\n{{ \"1,2,3\" | split \",\" | join \";\" }}\n```\n\njoin `[]string` with given separator to `string`\n\n#### map\n```\n{{ map \"foo\" 1 \"bar\" 2 }}\n// Equivalent to \n{{ map \"foo\" 1 | map \"bar\" 2 }}\n```\n\nmake `map[string]interface{}`\n\n#### arg\n```\n{{ .Anything | arg \"ArgName\" ArgValue | ... }}\n```\n\nConvert anything to `Pack` type with argument stored.\n\n#### require\n```\n// In template\n{{ . | require \"ArgName\" | require \"ArgName2\" \"typeName\" | ... }}\n```\nCheck `Pack` type's arguments, then returns `Pack` without any modification.\n\n#### args\n```\n// In template\n{{ if $args := . | ... | args }}\n```\n\nExtract `Args` Field of `Pack`. \n\n#### done\n```\n// In template \n{{ . | require \"argname\" | ... | done }}\n```\nEats all data and returns nil.\n\n#### Pack\n```\ntype Pack struct {\n\tOrigin interface{}\n\tArgs   map[string]interface{}\n}\n```\n\n## License\nApache. See `LICENSE` for more info.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtfy96%2Freformism","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhtfy96%2Freformism","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtfy96%2Freformism/lists"}