{"id":13879750,"url":"https://github.com/amatsuda/himl","last_synced_at":"2025-04-05T08:07:44.961Z","repository":{"id":48038460,"uuid":"176057647","full_name":"amatsuda/himl","owner":"amatsuda","description":"HTML-based Indented Markup Language for Ruby","archived":false,"fork":false,"pushed_at":"2023-01-21T02:44:59.000Z","size":48,"stargazers_count":232,"open_issues_count":3,"forks_count":4,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-29T07:07:28.452Z","etag":null,"topics":["erb","haml","rails","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/amatsuda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-17T04:50:15.000Z","updated_at":"2024-12-21T01:44:31.000Z","dependencies_parsed_at":"2023-02-12T07:30:27.142Z","dependency_job_id":null,"html_url":"https://github.com/amatsuda/himl","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/amatsuda%2Fhiml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fhiml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fhiml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fhiml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amatsuda","download_url":"https://codeload.github.com/amatsuda/himl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305934,"owners_count":20917208,"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":["erb","haml","rails","ruby","template-engine"],"created_at":"2024-08-06T08:02:31.507Z","updated_at":"2025-04-05T08:07:44.939Z","avatar_url":"https://github.com/amatsuda.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Himl\n\nHiml is an HTML-based Indented Markup Language for Ruby.\n\n\n## What's This?\n\nHiml is a yet another template engine for Haml-lovers and non Haml-lovers, deriving HTML validity from Haml and syntax intuitiveness from ERB.\n\n\n## Motivation\n\nHaml is a great template engine that liberates us from annoying HTML bugs.\nBy automatically closing the HTML tags, Haml always produces perfectly structured 100% valid HTML responses.\nActually, I've never experienced the HTML closing tag mismatch error over the past 10 years or so, thanks to Haml.\n\nHowever, the Haml (or Slim or whatever equivalent) syntax is very much different from that of HTML.\nAnd to be honest, I still rarely can complete my template markup works without consulting the Haml online reference manual.\n\nOh, why do we have to learn another markup language syntax where we just want to generate HTML documents?\nHTML has tags. HTML has indentations. Why can't we just use them?\n\n\n## Syntax\n\nHiml syntax is a hybrid of ERB and Haml.\nHiml is basically just a kind of ERB. Indeed, Himl documents are compiled to ERB internally, then rendered by the ERB handler.\n\nSo, the following Himl template opening and closing a tag will be compiled to exactly the same ERB template.\n\nHiml\n```erb\n\u003cdiv\u003e\n\u003c/div\u003e\n```\n\nERB\n```erb\n\u003cdiv\u003e\n\u003c/div\u003e\n```\n\nYou can omit closing tags. Then Himl auto-closes them, just like Haml does.\n\nHiml\n```erb\n\u003cdiv\u003e\n```\nERB\n```erb\n\u003cdiv\u003e\n\u003c/div\u003e\n```\n\nFor nesting tags, use whitespaces just like you do in the Haml templates.\n\nHiml\n```erb\n\u003csection\u003e\n  \u003cdiv\u003e\n```\n\nERB\n```erb\n\u003csection\u003e\n  \u003cdiv\u003e\n  \u003c/div\u003e\n\u003c/section\u003e\n```\n\nOf course you can include dynamic Ruby code in the ERB way.\n\nHiml\n```erb\n\u003csection\u003e\n  \u003cdiv\u003e\n    \u003c%= post.content %\u003e\n```\n\nERB\n```erb\n\u003csection\u003e\n  \u003cdiv\u003e\n    \u003c%= post.content %\u003e\n  \u003c/div\u003e\n\u003c/section\u003e\n```\n\nRuby blocks in the ERB tag can also automatically be closed.\n\nHiml\n```erb\n\u003cul\u003e\n  \u003c%= @users.each do |user| %\u003e\n    \u003cli\u003e\n      \u003c%= user.name %\u003e\n```\n\nERB\n```erb\n\u003cul\u003e\n  \u003c%= @users.each do |user| %\u003e\n    \u003cli\u003e\n      \u003c%= user.name %\u003e\n    \u003c/li\u003e\n  \u003c% end %\u003e\n\u003c/ul\u003e\n```\n\nOr manually be closed.\n\nHiml\n```erb\n\u003cul\u003e\n  \u003c%= @users.each do |user| %\u003e\n    \u003cli\u003e\n      \u003c%= user.name %\u003e\n  \u003c% end %\u003e\n```\n\nERB\n```erb\n\u003cul\u003e\n  \u003c%= @users.each do |user| %\u003e\n    \u003cli\u003e\n      \u003c%= user.name %\u003e\n    \u003c/li\u003e\n  \u003c% end %\u003e\n\u003c/ul\u003e\n```\n\nYou can open and close tags in the same line.\n\nHiml\n```erb\n\u003csection\u003e\n  \u003ch1\u003e\u003c%= post.title %\u003e\u003c/h1\u003e\n```\n\nERB\n```erb\n\u003csection\u003e\n  \u003ch1\u003e\u003c%= post.title %\u003e\u003c/h1\u003e\n\u003c/section\u003e\n```\n\nThere's no special syntax for adding HTML attributes to the tags. You see, it's just ERB.\n\nHiml\n```erb\n\u003csection class=\"container\"\u003e\n  \u003cdiv class=\"content\"\u003e\n```\n\nERB\n```erb\n\u003csection class=\"container\"\u003e\n  \u003cdiv class=\"content\"\u003e\n  \u003c/div\u003e\n\u003c/section\u003e\n```\n\nMore detailed syntax may be covered in [the tests](https://github.com/amatsuda/himl/blob/master/test/himl_test.rb).\n\n\n## Document Validations\n\nHiml's strongest advantage is not that you just can reduce the template LOC, but the engine validates the structure of the document and detects some syntax errors.\nFor example, Himl raises `SyntaxError` while parsing these templates.\n\nMismatched closing tag\n```erb\n\u003cdiv\u003e\n  hello?\n  \u003c/div\u003e\n```\n\nMismatched ERB `end` expression\n```erb\n  \u003c% if @current_user.admin? %\u003e\n    TOP SECRET\n\u003c% end %\u003e\n```\n\nExtra ERB `end` expression\n```erb\n\u003c% @books.each do |book| %\u003e\n  \u003c% book.read %\u003e\n\u003c% end %\u003e\n\u003c% end %\u003e\n```\n\n\n## Example\n\nFollowing is a comparison of ERB, Haml, and Himl templates that renders similar HTML results (the Haml example is taken from the [Haml documentation](http://haml.info/)).\nYou'll notice that Himl consumes the same LOC with the Haml version for expressing the structure of this document, without introducing any new syntax from the ERB version.\n\n### ERB Template\n```erb\n\u003csection class=\"container\"\u003e\n  \u003ch1\u003e\u003c%= post.title %\u003e\u003c/h1\u003e\n  \u003ch2\u003e\u003c%= post.subtitle %\u003e\u003c/h2\u003e\n  \u003cdiv class=\"content\"\u003e\n    \u003c%= post.content %\u003e\n  \u003c/div\u003e\n\u003c/section\u003e\n\n```\n\n### Haml Template\n```haml\n%section.container\n  %h1= post.title\n  %h2= post.subtitle\n  .content\n    = post.content\n```\n\n### Himl Template\n```erb\n\u003csection class=\"container\"\u003e\n  \u003ch1\u003e\u003c%= post.title %\u003e\u003c/h1\u003e\n  \u003ch2\u003e\u003c%= post.subtitle %\u003e\u003c/h2\u003e\n  \u003cdiv class=\"content\"\u003e\n    \u003c%= post.content %\u003e\n```\n\n\n## Installation\n\nBundle 'himl' gem to your project.\n\n\n## Usage\n\nThe gem contains the Himl template handler for Rails.\nYou need no extra configurations for your Rails app to render `*.himl` templates.\n\n\n## Runtime Performance\n\nSince every Himl template is converted to ERB, then cached as a Ruby method inside the view frameworks (such as Action View in Rails), Himl runtime performance in production is exactly the same with that of ERB.\n\n\n## Contributing\n\nPull requests are welcome on GitHub at https://github.com/amatsuda/himl.\n\n\n## Other Template Engines That I Maintain\n\n### [jb](https://github.com/amatsuda/jb)\n\nA faster and simpler and stronger alternative to Jbuilder.\n\n### [string_template](https://github.com/amatsuda/string_template)\n\nThe ultimate fastest template engine for Rails in the world.\n\n### [Haml](https://github.com/haml/haml)\n\nThe one that you may be currently using everyday.\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%2Famatsuda%2Fhiml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famatsuda%2Fhiml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famatsuda%2Fhiml/lists"}