The thin template interprets {{myJsVar}} as a grouping of HTML attributes

I play with Angularjs and Slim, but try to figure out how to come up with a cleaner syntax.

I want to make:

td {{content.name}} td {{content.body}} td {{content.owner}} 

But that gives me an error. Most likely because { used to group HTML attributes. I had to change it to this:

 td | {{content.name}} td | {{content.body}} td | {{content.owner}} 

Is there a cleaner way to do this?

+4
source share
5 answers

The change that allows this to be done in the thin version 2.0.3.

You can add the following to config/initializers/slim.rb :

 Slim::Engine.set_options :attr_list_delims => {'(' => ')', '[' => ']'} 

This removes { from the defaults. See the document here and search at attr_list_delims .

+4
source

I'm not sure if you consider it cleaner, but you can put all attributes in parentheses.

 td() {{content.name}} td(otherattr=2 thisattr=3) {{content.body}} td() {{content.owner}} 
+4
source

I ended up fixing the thin stone myself. Only 2 lines changed.

You can see it at https://github.com/brennancheung/slim/tree/angularjs_support

And you can include it in your Rails project using:

 gem 'slim', :git => 'git://github.com/brennancheung/slim.git', :branch => 'angularjs_support' 
+3
source

In another embodiment, but I'm still not happy with this:

 td ng-bind="content.name" td ng-bind="content.body" td ng-bind="content.owner" 

I tend to customize slim, so it doesn’t use { to group HTML attributes.

0
source

I know this is an old question, but now there is an ideal solution. The latest thin interface supports user-friendly attr_delims parameters. I do not know when it was added, but v2.0.3 has this. Using the command line you can use:

slimrb -o "attr_delims={'(' => ')', '[' => ']'}" <file>

Or, if you are using gulp-slim , you can write it like this:

 .pipe(slim({ pretty: true, options: "attr_delims={'(' => ')', '[' => ']'}" })) 

You can refer to the document here .

0
source

Source: https://habr.com/ru/post/1491730/


All Articles