# ExpressTemplates Provides a DSL for HTML templates using a declarative style of Ruby as an alternative to Erb or HAML. Although originally we implemented our own DSL and used a code generation approach, this gem now uses [ActiveAdmin's arbre](https://github.com/activeadmin/arbre). Arbre is widely used as part of ActiveAdmin, has a long history and many contributors and is conceptually much simpler. ## Usage Add this to your gemfile: ```ruby gem 'express_templates' ``` Rename your application.html.erb to application.html.et. Change your template to look like this. ```ruby html(lang: "en") { head { meta charset: 'utf-8' meta name: 'viewport', content: "width=device-width, initial-scale=1.0" title { content_for(:title) } stylesheet_link_tag "application", media: 'all', 'data-turbolinks-track' => true csrf_meta_tags } body { current_arbre_element.add_child yield javascript_include_tag "application" } } ``` Everything should work as you would expect. Set your editor syntax for .et files to Ruby. You can now utilize components which are found with documentation and examples in ExpressTemplates::Components. Components are the real strength of both arbre and express_templates. express_templates now *is* arbre + some components + some conventions. ExpressTemplates::Components::Base provides a little syntactic sugar in the form of the emits class method. In terms of conventions, we use brace blocks { } to indicate html structure and do/end blocks to indicate control flow. Control flow should only be used in Components. This is currently not enforced but it will be in the future. The purpose of express_templates is to provide a foundation for a library of reusable UX components which we can enhance for drag-and-drop style UX construction and template editing. ## Block Structure ExpressTemplates use Ruby's block structure and execution order to indicate parent-child relationships and to build the tree structure that ultimately results in nodes in the DOM. Example: ```ruby ul { li { "one" } li "two" li %Q(#{@three}) } ``` Let us suppose that an @three variable exists in the view context with the value "three". This would yield the following markup: ```html