{"id":13409915,"url":"https://github.com/milancermak/graffiti","last_synced_at":"2026-03-08T15:38:24.856Z","repository":{"id":201181450,"uuid":"694743177","full_name":"milancermak/graffiti","owner":"milancermak","description":"A Cairo library for building XML based documents","archived":false,"fork":false,"pushed_at":"2024-01-27T23:20:48.000Z","size":136,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-20T03:18:21.446Z","etag":null,"topics":["cairo","html","starknet","svg","xml"],"latest_commit_sha":null,"homepage":"","language":"Cairo","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/milancermak.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":"2023-09-21T15:46:52.000Z","updated_at":"2024-07-30T22:51:35.818Z","dependencies_parsed_at":"2024-07-30T23:09:00.665Z","dependency_job_id":null,"html_url":"https://github.com/milancermak/graffiti","commit_stats":null,"previous_names":["milancermak/graffiti"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milancermak%2Fgraffiti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milancermak%2Fgraffiti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milancermak%2Fgraffiti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milancermak%2Fgraffiti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milancermak","download_url":"https://codeload.github.com/milancermak/graffiti/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241928519,"owners_count":20043822,"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":["cairo","html","starknet","svg","xml"],"created_at":"2024-07-30T20:01:04.033Z","updated_at":"2026-03-08T15:38:19.825Z","avatar_url":"https://github.com/milancermak.png","language":"Cairo","funding_links":[],"categories":["Libraries","Additional developer resources"],"sub_categories":[],"readme":"# Graffiti\n\n![tests](https://github.com/milancermak/graffiti/actions/workflows/tests.yml/badge.svg)\n\nGraffiti is a Cairo library for building XML based documents - think SVG, HTML, RSS. If it has a `\u003ctag with=\"attribute\"\u003e`, you can use Graffiti.\n\n![](./graffiti.png)\n\n## Installation\n\nAdd the package as a dependency in Scarb.toml:\n\n```toml\n[dependencies]\ngraffiti = { git = \"https://github.com/milancermak/graffiti.git\" }\n```\n\n## Usage\n\nThe main building block of a XML document is a tag. In Graffiti, it's represented by the `Tag` type:\n\n```rust\nlet div: Tag = TagImpl::new(\"div\");\n```\n\nA tag can have any number of `Attributes` assigned to it:\n\n```rust\nlet div: Tag = TagImpl::new(\"div\").attr(\"id\", \"hero\").attr(\"class\", \"text-center\");\n```\n\nA tag element can hold textual content:\n\n```rust\nlet paragraph: Tag = TagImpl::new(\"p\").content(\"Lorem ipsum dolor sit amet\");\n```\n\nXML tags can be combined into a tree to get the desired structure:\n\n```rust\nlet paragraph: Tag = TagImpl::new(\"p\").content(\"Lorem ipsum dolor sit amet\");\nlet text: Tag: TagImpl::new(\"text\").insert(p);\nlet h1: Tag = TagImpl::new(\"h1\").content(\"Graffiti\");\nlet h2: Tag = TagImpl::new(\"h2\").content(\"An awesome Cairo lib for building XML documents\").\nlet body: Tag = TagImpl::new(\"body\").insert(\"h1\").insert(\"h2\").insert(\"text\");\n\n// the outcome is the following structure:\n// \u003cbody\u003e\u003ch1\u003eGraffiti\u003c/h1\u003e\u003ch2\u003eAn awesome Cairo lib for building XML documents\u003c/h2\u003e\u003ctext\u003e\u003cp\u003eLorem ipsum dolor sit amet\u003c/p\u003e\u003c/text\u003e\u003c/body\u003e\n```\n\nNote that Graffiti does not place any constraints on the names or values of the tags or attributes. Any text (Cairo's `ByteArray` type) is accepted. In future versions, there might be specific submodules for building HTML or SVG that do some kind of type checking to achieve valid output.\n\nTo get the `ByteArray` representation of the document built in Graffiti, call the `build` function on it. Following the example above:\n\n```rust\nassert(\n    body.build() ==\n    \"\u003cbody\u003e\u003ch1\u003eGraffiti\u003c/h1\u003e\u003ch2\u003eAn awesome Cairo lib for building XML documents\u003c/h2\u003e\u003ctext\u003e\u003cp\u003eLorem ipsum dolor sit amet\u003c/p\u003e\u003c/text\u003e\u003c/body\u003e\",\n    \"Nope\"\n);\n```\n\n### TagBuilder trait\n\nThe `TagBuilder` trait is the centerpiece of building documents with Graffiti:\n\n```rust\ntrait TagBuilder\u003cT\u003e {\n    fn new(name: ByteArray) -\u003e T;\n    fn build(self: T) -\u003e ByteArray;\n    fn attr(self: T, name: ByteArray, value: ByteArray) -\u003e T;\n    fn content(self: T, content: ByteArray) -\u003e T;\n    fn insert(self: T, child: T) -\u003e T;\n}\n```\n\n`Tag` implements this trait via `TagImpl`. Import both to use Graffiti:\n\n```rust\nuse graffiti::{Tag, TagImpl};\n```\n\n### Examples\n\nCheck the [examples](./examples/) folder to see how to build a minimal HTML page, the Starknet logo in SVG or a single Loot bag using this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilancermak%2Fgraffiti","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilancermak%2Fgraffiti","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilancermak%2Fgraffiti/lists"}