{"id":26870824,"url":"https://github.com/mrhdias/tera-shortcodes","last_synced_at":"2026-01-24T21:08:31.778Z","repository":{"id":255926506,"uuid":"853760678","full_name":"mrhdias/tera-shortcodes","owner":"mrhdias","description":"Tera Shortcodes in Rust: A WordPress-Like Implementation","archived":false,"fork":false,"pushed_at":"2024-10-06T17:43:18.000Z","size":122,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-03T01:43:37.934Z","etag":null,"topics":["rust","template-engine","tera"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/mrhdias.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":"2024-09-07T13:13:11.000Z","updated_at":"2024-10-06T17:42:26.000Z","dependencies_parsed_at":"2024-09-12T05:58:43.458Z","dependency_job_id":"c2f95a7e-862e-47a7-9c10-9063939280ee","html_url":"https://github.com/mrhdias/tera-shortcodes","commit_stats":null,"previous_names":["mrhdias/tera-shortcodes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrhdias%2Ftera-shortcodes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrhdias%2Ftera-shortcodes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrhdias%2Ftera-shortcodes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrhdias%2Ftera-shortcodes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrhdias","download_url":"https://codeload.github.com/mrhdias/tera-shortcodes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252826402,"owners_count":21810107,"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":["rust","template-engine","tera"],"created_at":"2025-03-31T07:17:24.186Z","updated_at":"2026-01-24T21:08:31.745Z","avatar_url":"https://github.com/mrhdias.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tera-shortcodes\nTera Shortcodes in Rust: A WordPress-Like Implementation\n\nThe goal of this library is to bring WordPress-style shortcodes to the Tera template engine, enabling their use in templates to display dynamic content or functionality. Two methods are available for rendering shortcode content: a slower one that utilizes Tokio's `block_in_place` function, and a faster one that leverages an auxiliary JavaScript function.\n\n[![Rust](https://github.com/mrhdias/tera-shortcodes/actions/workflows/rust.yml/badge.svg)](https://github.com/mrhdias/tera-shortcodes/actions/workflows/rust.yml)\n\n```html\n{{ shortcode(display=\"myshortcode\", foo=\"bar\", bar=\"bing\", jscaller=\"true\") | safe }}\n```\n\n## How to perform a test?\n\nAn example is provided to demonstrate how a shortcode is implemented.\nClone the repository and edit the test template if you wish. In the products shortcode, you can change the limit and order.\n\n```sh\ngit clone https://github.com/mrhdias/tera-shortcodes\ncd tera-shortcodes\ncargo build\nnano -w examples/templates/test_shortcode.html\ncargo run --example app\ncurl http://127.0.0.1:8080/test\n```\n\n## Usage\n\nAn example of shortcode:\n```html\n{{ shortcode(display=\"my_shortcode\", foo=\"bar\", bar=\"bing\", jscaller=\"true\") | safe }}\n```\n\n```rust\nuse tera_shortcodes;\n\nlet shortcodes = tera_shortcodes::Shortcodes::new()\n  .register(\"my_shortcode\", |args| -\u003e String {\n\n    let js_caller = match args.get(\"jscaller\") {\n        Some(value) =\u003e value\n            .as_str()\n            .unwrap()\n            .trim_matches(|c| c == '\"' || c == '\\'')\n            .parse()\n            .unwrap_or(false),\n        None =\u003e false,\n    };\n\n    let foo = match args.get(\"foo\") {\n      Some(value) =\u003e value.as_str().unwrap()\n        .trim_matches(|c| c == '\"' || c == '\\''),\n      None =\u003e \"no foo\",\n    };\n\n    let bar = match args.get(\"bar\") {\n      Some(value) =\u003e value.as_str().unwrap()\n        .trim_matches(|c| c == '\"' || c == '\\''),\n      None =\u003e \"no bar\",\n    };\n\n    let json_body = serde_json::to_string(\u0026DataTest {\n      foo: foo.to_string(),\n      bar: bar.to_string(),\n    }).unwrap();\n  \n    // axum route that receives the data from the shortcode\n    let url = format!(\"http://{}/data\", ADDRESS);\n\n    if js_caller {\n      tera_shortcodes::fetch_shortcode_js(\n        \u0026url,\n        Some(\"post\"),\n        Some(\u0026json_body),\n        None,\n      )\n    } else {\n      tera_shortcodes::fetch_shortcode(\n        \u0026url,\n        Some(\"post\"),\n        Some(\u0026json_body),\n      )\n    }\n  })\n  .register(\"another_shortcode\", another_shortcode_fn);\n\nlet mut tera = Tera::new(\"templates/**/*\").unwrap();\n\n// Register the custom function\ntera.register_function(\"shortcode\", shortcodes);\n```\n\n## Benchemarks\n\nFetch shortcode in Rust with `block_in_place` to run the async function.\n```sh\nRunning 30s test @ http://127.0.0.1:8080/test\n  12 threads and 400 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   250.98ms   60.48ms 528.39ms   68.72%\n    Req/Sec   131.94     31.32   260.00     68.57%\n  47193 requests in 30.10s, 84.30MB read\nRequests/sec:   1567.81\nTransfer/sec:      2.80MB\n```\nFetch a shortcode using an `auxiliary function` in JavaScript.\n```sh\nRunning 30s test @ http://127.0.0.1:8080/test\n  12 threads and 400 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency    57.46ms   22.86ms 162.02ms   69.30%\n    Req/Sec   577.12     48.80     1.43k    73.41%\n  207147 requests in 30.10s, 437.77MB read\nRequests/sec:   6882.17\nTransfer/sec:     14.54MB\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrhdias%2Ftera-shortcodes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrhdias%2Ftera-shortcodes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrhdias%2Ftera-shortcodes/lists"}