Question

HAML understands a basic hash for the "data" keyword, so that:

%div{ data: { id: "5", name: "carsten" } }

is equivalent to

%div{ 'data-id' => "5", 'data-name' => "carsten" }

IMHO the former syntax is much more readable.

AngularJS uses a lot of ng-something attributes. Is it possible to configure HAML, so that:

%html{ 'ng-app' => "myApp", 'ng-controller' => "myCtrl" }

can be written as

%html{ ng: { app: "myApp", controller: "myCtrl" } }

Was it helpful?

Solution

You don’t need to configure anything, this is how the current version works already:

%html{ ng: { app: "myApp", controller: "myCtrl" } }

produces:

<html ng-app='myApp' ng-controller='myCtrl'></html>

The docs need updating, but the current behaviour is any attribute with a value that is a hash is expanded in this way, not just data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top