{"id":19436369,"url":"https://github.com/beached/parse_template","last_synced_at":"2025-02-25T06:46:41.285Z","repository":{"id":149955367,"uuid":"58171343","full_name":"beached/parse_template","owner":"beached","description":"A library that accepts a UTF-8 text template and generates text(e.g. html)","archived":false,"fork":false,"pushed_at":"2023-02-08T23:48:09.000Z","size":116,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-07T21:12:32.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beached.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-05-06T01:25:25.000Z","updated_at":"2023-12-10T02:33:54.000Z","dependencies_parsed_at":"2023-05-05T06:15:53.068Z","dependency_job_id":null,"html_url":"https://github.com/beached/parse_template","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/beached%2Fparse_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fparse_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fparse_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fparse_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beached","download_url":"https://codeload.github.com/beached/parse_template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240619430,"owners_count":19830204,"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-10T15:10:49.537Z","updated_at":"2025-02-25T06:46:41.263Z","avatar_url":"https://github.com/beached.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Template Tags\n\nA library that accepts a UTF-8 text template and generates text(e.g. html)\n\n--------------\n\n| Tag                                            | Description                                                                                                                                                                                                                                                                                                                          |\n|------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| \u003c%call args=\"callback_name,callback_args...\"%\u003e | insert text from callback                                                                                                                                                                                                                                                                                                            |\n| \u003c%timestamp args=\"fmt,tz\"%\u003e                    | See [date_formatting.md](date_formatting.md) for fmt, timezone name from IANA database e.g. America/NewYork. The default fmt is \"%Y-%m-%dT%T%z\", the ISO9601 timestamp format, and tz=\"\" the system's timezone.  See the [wiki](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) article for listing of time zone names |\n| \u003c%date args=\"tz\"%\u003e                             | insert current date with timezone tz. The default timezone is the current system's.  Same as timestamp with fmt=\"%Y-%m-%d\" and tz                                                                                                                                                                                                    |\n| \u003c%time args=\"tz\"%\u003e                             | insert current time with timezone tz.  The default timezone is the current system's. Same as timestamp with fmt=\"%T\" and tz                                                                                                                                                                                                          |\n\n### Note:\n\nDo not put spaces between comma separates currently\n\n# Code Usage\n\nThe constructor for parse_template takes any container that is string like(e.g. std::string, string_view..). This allows for things like memory mapped files.\n\n``` C++\nstd::string str = ...;\nauto tmp = parse_template{ str };\n```\n\nAdding callbacks requires one to specify how the arguments are to be parsed. Often this is just specifying the types of the arguments, but tag types can be used as any type specified must have a ``` std::string parse_to_value( daw::string_view, type_tag ) ``` method\n\n``` C++\ntmp.add_callback\u003cint,int,bool\u003e( \"callback_name\", []( int a, int b, bool c ) {\n\tif( c ) {\n\t\ta += b;\n\t}\n\treturn a;\n} );\n```\n\nThe previous example adds a callback that takes the arguments of int, int, and bool and returns an int. The result must be a string, have a ``` to_string ``` overload, or take a `daw::io::WriteProxy \u0026` param. To use the example in a template you would call it like the following:\n\n``` html\n\u003c%call args=\"callback_name,5,5,true\"%\u003e\u003cbr\u003e\n\u003c%call args=\"callback_name,5,5,false\"%\u003e\n```\n\nOne can output to any Writable type, see [daw-read-write](https://github.com/beached/daw_read_write), such as strings, streams, and FILE *.\n\n```cpp\ntmp.write_to( std::cout );\n```\n\nIf the text output was html, the output would be\n\n```\n10\n5\n```\n\n## Callbacks\n\nCallbacks are specified with the parameters the template will use and needs to be invokable with them, but one can optionally add a `daw::io::WriteProxy \u0026` param and/or a `void * state` param. These allow for directly writing to the output without a string intermediary and passing state to each call. Stateful callbacks also work.\n\n`daw::escaped_string` on the parameter lists says that the strring in the document will be escaped and needs to be unescaped prior to sending to the function.\n\nFor example\n\n```cpp\ntmp.add_callback\u003cdaw::escaped_string, daw::escaped_string\u003e( []( std::string a, std::string b, daw::io::WriteProxy \u0026 writer ) {\n  writer.write( {a, \":\", b} );\n)\n```\n\nThe previous function takes 2 string parameters and uses the writer to write them to the callers output.\n\n## Stateful Callbacks\nStateful callbacks allow for passing a mutable parameter to the callback.\n\n```cpp\ntmp.add_stateful_callback\u003cint\u003e( \"name\", []( int \u0026 x ) {\n    return x;\n});\ntmp.add_stateful_callback\u003cint, daw::escaped_string, unsigned\u003e( \"name\", []( std::string s, unsigned u, int \u0026 x ) {\n    using std::to_string;\n    return s + to_string( u ) + \":\" + to_string( x );\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeached%2Fparse_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeached%2Fparse_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeached%2Fparse_template/lists"}