# Hamlit Basically Hamlit is the same as Haml. See [Haml's tutorial](http://haml.info/tutorial.html) if you are not familiar with Haml's syntax. [REFERENCE - Haml Documentation](http://haml.info/docs/yardoc/file.REFERENCE.html) ## Supported features See [Haml's reference](http://haml.info/docs/yardoc/file.REFERENCE.html) for full features in original implementation. - [ ] Using Haml - [x] Rails XSS Protection - [x] Ruby Module - [x] Options - [ ] Encodings - [x] Plain Text - [x] Escaping: \ - [ ] HTML Elements - [x] Element Name: % - [ ] Attributes: ` - [x] :class and :id Attributes - [x] HTML-style Attributes: () - [x] Ruby 1.9-style Hashes - [ ] Attribute Methods - [x] Boolean Attributes - [x] HTML5 Custom Data Attributes - [x] Class and ID: . and # - Implicit Div Elements - [x] Empty (void) Tags: / - [x] Whitespace Removal: > and < - [x] Object Reference: [] - [x] Doctype: !!! - [x] Comments - [x] HTML Comments: / - [x] Conditional Comments: /[] - [x] Haml Comments: -# - [x] Ruby Evaluation - [x] Inserting Ruby: = - [x] Running Ruby: - - [x] Ruby Blocks - [x] Whitespace Preservation: ~ - [x] Ruby Interpolation: #{} - [x] Escaping HTML: &= - [x] Unescaping HTML: != - [ ] Filters - [x] :cdata - [x] :coffee - [x] :css - [x] :erb - [x] :escaped - [x] :javascript - [x] :less - [x] :markdown - [ ] :maruku - [x] :plain - [x] :preserve - [x] :ruby - `haml_io` API is not supported. Use [hamlit-haml\_io.gem](https://github.com/hamlit/hamlit-haml_io) if you need. - [x] :sass - [x] :scss - [ ] :textile - [ ] Custom Filters - [x] Helper Methods - [x] preserve - [x] surround - [x] precede - [x] succeed - [x] Multiline: | - [x] Whitespace Preservation - [ ] Helpers ## Limitations ### No Haml buffer Hamlit uses `Array` as buffer for performance. So you can't touch Haml::Buffer from template when using Hamlit. ### Haml helpers are still in development At the same time, because some methods in `Haml::Helpers` require `Haml::Buffer`, they are not supported now. But some helpers are supported on Rails. Some of not-implemented methods are planned to be supported. ### Limited attributes hyphenation In Haml, `%a{ foo: { bar: 'baz' } }` is rendered as ``, whatever foo is. In Hamlit, this feature is supported only for aria and data attribute. Hamlit renders `%a{ data: { foo: 'bar' } }` as `` because it's data attribute. This design allows us to reduce work on runtime and the idea is originally in [Faml](https://github.com/eagletmt/faml). ### Limited boolean attributes In Haml, `%a{ foo: false }` is rendered as ``, whatever `foo` is. In Hamlit, this feature is supported for only boolean attributes, which are defined by http://www.w3.org/TR/xhtml1/guidelines.html or https://html.spec.whatwg.org/. The list is the same as `ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES`. In addition, aria-\* and data-\* is also regarded as boolean. Since `foo` is not boolean attribute, `%a{ foo: false }` is rendered as `` This is the same behavior as Rails helpers. Also for `%a{ foo: nil }`, Hamlit does not remove non-boolean attributes and render `` (`foo` is not removed). This design allows us to reduce string concatenation and is the only difference between Faml and Hamlit. You may be also interested in [hamlit/hamlit-boolean\_attributes](https://github.com/hamlit/hamlit-boolean_attributes). ## 5 Types of Attributes Haml has 3 types of attributes: id, class and others. In addition, Hamlit treats aria/data and boolean attributes specially. So there are 5 types of attributes in Hamlit. ### id attribute Almost the same behavior as Haml, except no hyphenation and boolean support. Arrays are flattened, falsey values are removed (but attribute itself is not removed) and merging multiple ids results in concatenation by "\_". ```rb # Input #foo{ id: 'bar' } %div{ id: %w[foo bar] } %div{ id: ['foo', false, ['bar', nil]] } %div{ id: false } # Output