{"id":24505834,"url":"https://github.com/michaeltelford/yart","last_synced_at":"2026-05-19T18:04:15.085Z","repository":{"id":56899054,"uuid":"390014135","full_name":"michaeltelford/yart","owner":"michaeltelford","description":"Yet Another Ruby Templater (YART) turns plain Ruby into HTML, making it fun to write webpages","archived":false,"fork":false,"pushed_at":"2021-08-11T13:32:00.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T05:40:40.062Z","etag":null,"topics":["html","ruby","template-engine"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/michaeltelford.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-27T14:28:20.000Z","updated_at":"2023-03-16T22:03:24.000Z","dependencies_parsed_at":"2022-08-21T02:20:47.669Z","dependency_job_id":null,"html_url":"https://github.com/michaeltelford/yart","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeltelford%2Fyart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeltelford%2Fyart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeltelford%2Fyart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeltelford%2Fyart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaeltelford","download_url":"https://codeload.github.com/michaeltelford/yart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243707299,"owners_count":20334615,"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":["html","ruby","template-engine"],"created_at":"2025-01-21T23:31:54.806Z","updated_at":"2025-12-29T18:54:08.429Z","avatar_url":"https://github.com/michaeltelford.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YART\n\n*Yet Another Ruby Templater* turns plain Ruby into HTML making it fun to write webpages.\n\n- YART provides an intuitive DSL that feels natural to use and removes the boiler plate from writing HTML\n- YART has zero runtime dependencies and around 120 lines of code\n- YART is fully unit tested\n\n## Example Usage\n\n\u003e login.html\n\n```ruby\nrequire \"yart\"\n\nYART.parse do\n  form action: \"/auth\" do\n    input type: :email, placeholder: \"Email Address\", required: true, close: true\n    input type: :password, placeholder: \"Password\", required: true, close: true\n    button(type: :submit, id: :login) { \"Login\" }\n  end\nend\n```\n\nWhich renders:\n\n```html\n\u003cform action='/auth'\u003e\n  \u003cinput type='email' placeholder='Email Address' required\u003e\n  \u003cinput type='password' placeholder='Password' required\u003e\n  \u003cbutton type='submit' id='login'\u003eLogin\u003c/button\u003e\n\u003c/form\u003e\n```\n\nNote that the above HTML snippet is *prettified* for demonstration. The actual generated HTML will be *minified*.\n\n## Installation\n\nRequires Ruby `\u003e= 2.7`\n\n### RubyGems\n\n    $ gem install yart\n\n### Bundler\n\n    $ bundle add yart\n\n## API\n\nThe best way to fully demonstrate the YART API is with a more complex example:\n\n```ruby\nrequire 'yart'\n\nYART.parse do\n  element \"!DOCTYPE\", html: true, close: true # Or just call `doctype`\n  html lang: :en do\n    head do\n      title { \"YART API\" }\n    end\n    body do\n      h1 { \"Use a block to return a String of innerText or more elements\" }\n      div data_test_id: \"String attribute values will be parsed as is\" do\n        h2(data_x: :sub_heading) { \"Symbol attribute keys/values will be kebab-cased\" }\n        text { \"Set the div's innerText, before and/or after its child elements\" }\n        p(class: [:content, :italic_text], id: :paragraph) do\n          \"You can pass an array of attribute values and they will be space separated\"\n        end\n      end\n      footer # Render an empty \u003cfooter\u003e\u003c/footer\u003e element\n    end\n  end\nend\n```\n\nWhich renders, minifies and returns the following HTML5 from `YART.parse`:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang='en'\u003e\n\u003chead\u003e\n  \u003ctitle\u003eYART API\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003ch1\u003eUse a block to return a String of innerText or more elements\u003c/h1\u003e\n  \u003cdiv data-test-id='String attribute values will be parsed as is'\u003e\n    \u003ch2 data-x='sub-heading'\u003eSymbol attribute keys/values will be kebab-cased\u003c/h2\u003e\n    Set the div's innerText, before and/or after its child elements\n    \u003cp class='content italic-text' id='paragraph'\u003e\n      You can pass an array of attribute values and they will be space separated\n    \u003c/p\u003e\n  \u003c/div\u003e\n  \u003cfooter\u003e\u003c/footer\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nMain points to note:\n\n- Pass a block to `YART.parse` and it will render and return a HTML `String`.\n- Create the HTML document hierarchy using element calls and blocks.\n- Call the element as it's named in HTML, e.g. `h1`, `div`, `p` etc. This works as long as it's lowercase.\n- Call `element` when you need to render the *raw* element name (case insensitive) e.g. `!DOCTYPE`.\n- Pass the element's attributes as a `Hash` argument.\n- Pass a block to return a `String` of `innerText` or more DSL calls (which will eventually return a `String`).\n- An element doesn't require attributes or even a block. Where a block is absent, an empty element will be rendered.\n- Use the `text` method to render the `innerText` of the element when it consists of *both* inner text *and* child elements.\n- An attribute key or value of type `Symbol` will be parsed, converting `snake_case` to `kebab-case`.\n- An attribute *value* of type `String` will be parsed as is (not modified in any way).\n- An attribute *value* of `true` renders the attribute key without a value e.g. `input required: true` renders `\u003cinput required\u003e`.\n- Several attibute *values* can be rendered by passing an `Array` e.g. `p class: [:para, :italic]`. The values will be rendered space separated.\n- Attribute *values* containing illegal characters (like quotes etc.) will be escaped in the rendered HTML.\n- The attribute `close: true` is special and tells the parser to auto-close the element (because it's empty).\n- Use the convenience methods `doctype`, `javascript`, `stylesheet` and `br` as needed.\n\n## Markdown\n\nIf you're creating a site with a lot of static textual content, check out the [static_site_builder](https://github.com/michaeltelford/static_site_builder) gem. It can render HTML sites built using Markdown and it fully supports YART; meaning you can write your text in Markdown and your forms etc in YART, never needing to touch HTML.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/michaeltelford/yart. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/michaeltelford/yart/blob/master/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the YART project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/michaeltelford/yart/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeltelford%2Fyart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaeltelford%2Fyart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeltelford%2Fyart/lists"}