{"id":13878837,"url":"https://github.com/BlakeWilliams/triplet","last_synced_at":"2025-07-16T14:33:05.194Z","repository":{"id":55598755,"uuid":"322736177","full_name":"BlakeWilliams/triplet","owner":"BlakeWilliams","description":"Simple, experimental HTML DSL for Ruby","archived":false,"fork":false,"pushed_at":"2020-12-19T18:52:51.000Z","size":39,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-21T09:56:46.513Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/BlakeWilliams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-19T00:39:30.000Z","updated_at":"2021-08-16T18:50:28.000Z","dependencies_parsed_at":"2022-08-15T04:01:04.781Z","dependency_job_id":null,"html_url":"https://github.com/BlakeWilliams/triplet","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Ftriplet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Ftriplet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Ftriplet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2Ftriplet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlakeWilliams","download_url":"https://codeload.github.com/BlakeWilliams/triplet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226138849,"owners_count":17579496,"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-08-06T08:02:01.538Z","updated_at":"2024-11-24T07:31:21.308Z","avatar_url":"https://github.com/BlakeWilliams.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Triplet\n\nA simple Ruby DSL for defining templates. (Maybe) useful for defining single file [view\ncomponents](https://github.com/github/view_component).\n\nFeatures:\n\n* Easy to use \"AST\" for defining HTML tags. `[:a, { href: \"/\" }, \"Home\"]`\n* DSL methods to make defining triplets easier. `a(href: \"/\") { \"Home\" }`\n* Supports Rails helper methods. e.g. `form_for`, `text_field_tag`, `link_to`,\n  etc.\n* View Component support via `include Triplet::ViewComponent`\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'triplet'\n```\n\nAnd then execute: `bundle install` in your shell.\n\n## Usage\n\n```ruby\nnav_items = { \"home\": \"/\", \"Sign Up\": \"/sign-up\" }\n\nTriplet.template {[\n  nav(class: \"max-w-3xl mx-auto flex\") {[\n    h1(class: \"font-3xl\") { \"My App\" },\n    ul(class: \"\") {[\n      nav_items.map do |name, link|\n        li(class: \"bold font-xl\") {[ a(href: link.html_safe) { name } ]}\n      end\n    ]}\n  ]},\n  \"Hello\",\n  span(class: \"bold\") { \"world\" },\n]}\n```\n\nWill output the equivalent HTML:\n\n```html\n\u003cnav class=\"max-w-3xl mx-auto flex\"\u003e\n   \u003ch1 class=\"font-3xl\"\u003eMy App\u003c/h1\u003e\n   \u003cul class=\"\"\u003e\n      \u003cli class=\"bold font-xl\"\u003e\u003ca href=\"/\"\u003ehome\u003c/a\u003e\u003c/li\u003e\n      \u003cli class=\"bold font-xl\"\u003e\u003ca href=\"/sign-up\"\u003eSign Up\u003c/a\u003e\u003c/li\u003e\n   \u003c/ul\u003e\n\u003c/nav\u003e\nHello\u003cspan class=\"bold\"\u003eworld\u003c/span\u003e\n```\n\nThe tag methods (e.g. `nav`, `h1`, `p`) are helpers that turn Ruby code into\ntriples, or 3 element arrays.\n\ne.g. `p(class: \"font-xl\") { \"hello world!\" }` becomes `[:p, { class: \"font-xl\" }, \"hello world!\"]`\n\nThe two formats can be used interchangeably in templates.\n\nIf you need a custom tag, you can return a triplet directly:\n\n```ruby\n[:\"my-tag\", { \"custom-attribute\" =\u003e \"value\" }, [\"body content\"]]\n# \u003cmy-tag custom-attribute=\"value\"\u003ebody content\u003c/my-tag\u003e\n```\n\n### View Component Support\n\nTo use in view components, include the `Triplet::ViewComponent` module and\ndefine a `call` method. The module will handle the rest.\n\n```ruby\nclass NavComponent \u003c ViewComponent::Base\n  include Triplet::ViewComponent\n\n  def template\n    [\n      h1 { \"hello world\" },\n      render NavItemComponent.new(title: \"Home\", path: \"/\"),\n      render NavItemComponent.new(title: \"Pricing\", path: \"/pricing\")\n    ]\n  end\nend\n```\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 tags, 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/BlakeWilliams/triplet.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlakeWilliams%2Ftriplet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlakeWilliams%2Ftriplet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlakeWilliams%2Ftriplet/lists"}