mustache / mustache.github.com

The {{official}} website
http://mustache.github.io/
Other
2.31k stars 293 forks source link

How to trim all the spaces of a string #90

Closed ShinojEdakkara closed 7 years ago

ShinojEdakkara commented 7 years ago

I have the following snippet from a template which needs to take tags, trim the tags, and generted the code,

com.test.{{#vendorExtensions.x-tags}}{{tag}}{{#hasMore}}{{/hasMore}}{{/vendorExtensions.x-tags}}Api apiInstance;

Here is the Json (again only snippet is provided here)

{
      "tags":[
          "Event Manager Tasks",
          "Health Management"
        ]
}

I want to remove all the spaces in the tags in the generated code

What it generates is this ,

  com.test.Event Manager TasksHealth ManagementApi apiInstance ;

Instead what I want to generate is , com.test.EventManagerTasksHealthManagmentApi apiInstance;

Another thing I would like to do is to just use the first item in the tags , ie "Event Manager Tasks" and then generate the above code. How can I do that ?

locks commented 7 years ago

Hi @ShinojEdakkara, you should process the data and remove all of the spaces before giving it to the template. This will depend on the language and implementation you are using. Thanks for using Mustache :)

ShinojEdakkara commented 7 years ago

Yes, that is what I eventually did, but then I forgot to add the comment here on how I fixed it -:)

locks commented 7 years ago

Thanks for the follow up! Nice to know you managed to solve it.