Git Product home page Git Product logo

mustache.github.com's Introduction

mustache.github.com's People

Contributors

abhidilliwal avatar ahmetb avatar ajacksified avatar alanyee avatar amirmc avatar benjamindblock avatar bobthecow avatar bryfry avatar cbroglie avatar cgcgbcbc avatar d-led avatar dandv avatar dawee avatar dayanruben avatar defunkt avatar dmboyd avatar emaringolo avatar fidian avatar floatplane avatar gaurav2728 avatar groue avatar jgonggrijp avatar jknack avatar locks avatar mcandre avatar nadako avatar nagaozen avatar romanx avatar sbcgua avatar timcharper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mustache.github.com's Issues

How to access the parent variable.?

I am accessing some data from the JSON. Once i access the child element, i don't have reference to the parent element. How to manage this other than passing the parent element when accessing the child element.

Context name from list

I'm trying to render a list of values. In my real problem, each list item has a name property, and also another list, in which the items also have a 'name' property. I'm trying to avoid renaming the nested list items in my context.

I've done some testing and I figure out that this works perfectly:

        template = '''
{{#my_list}}
My list name is: {{my_list.name}}
{{/my_list}}
'''
        context = {'my_list' : {'name': 'This is my first item'}}

        renderer = pystache.Renderer(missing_tags='strict')
        s = renderer.render(template, context)
        print(s)

The output is what you expect:

My list name is: This is my first item

However, if my_list is actually a list (like it is in my actual problem), this breaks:

        context = {'my_list' : [
                {'name': 'This is my first item'},
                {'name': 'This is my second item'}
            ]}

I've tried with Pystache and Chevron, and they don't work, I get:

My list name is: 
My list name is:

My question is: should it work according to the specs?

Thanks a lot!

Pass variables to different template/entries

Hey there,
I've got 3 different .mustache files (index.mustache, work.mustache and about.mustache) and I'm trying to pass different variables to those 3 entries from my webpack.common.js. (Let's say I want my title to change and say Hello Index in Index, Hello About in About and Hello Work in Work, for example).
For this, this is my typical folder stucture:

+--js
+--scss
+--img
|   index.mustache
|   about.mustache
|   work.mustache

I've got the same lines in both index, about and work .mustache:

<!DOCTYPE html>
<html lang="en">
<head>
    ...
</head>
<body>
   <h1>{{title}}</h1>
</body>
</html>

and here's my webpack.common.js

const webpack = require('webpack');
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const currentTask = process.env.npm_lifecycle_event;
const VueLoaderPlugin = require('vue-loader/lib/plugin');



module.exports = {
    
    entry: {
        main: './src/js/home.js',
        about: './src/js/about.js',
        work: './src/js/work.js',
    },

    module:{
        rules: [
            //rule for JS
            {
                test: /\.js$/,
                exclude: /(node_modules)/,
                use:'babel-loader'
            },
            {
                test: /\.mustache$/,
                loader: 'mustache-loader',
                options: {
                    tiny: true,
                    render: {
                        title: 'hello Index',
                    },
                },
            } ,

            //Vue Loader
            { 
                test: /\.vue$/, 
                use: 'vue-loader'
            },
            
           //rule for img 
           {
            test: /\.(png|svg|gif|jpg)$/,
            use: [
                {
                    loader: 'file-loader',
                    options: {
                        name: "[name].[hash].[ext]",
                        outputPath: "img/",
                        publicPath: './img/'
                    }
                },
            ],
        },

         // // PDF Loader
         {
            test: /\.(pdf)$/,
            use: {
                loader: 'file-loader',
                options:{
                    name: '[name].[ext]',
                    outputPath: "files/",
                    publicPath: './files/'  
                }
            },
        },

        // // Assets Loader
        {
            test: /\.(mp4|mov|avi|wmv|webm)$/,
            use: {
                loader: 'file-loader',
                options:{
                    name: '[name].[hash].[ext]',
                    outputPath: "video/",
                    publicPath: './video/'
                }
            },
        },

        // Font Loader
        {
            test: /\.(woff|woff2|svg)$/,
            exclude: [path.resolve(__dirname, './src/img/')],
            use: {
                loader: 'file-loader',
                options:{
                    name: '[name].[ext]',
                    limit: 4096,
                    mimetype: "application/font-woff",
                    outputPath: 'css/fonts/',
                    publicPath: './css/fonts/',  
                }
            },
        }

        ],
    },
    plugins:[
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            filename: './index.html',
            template: './src/index.mustache',
            inject: 'body',
            chunks: ['main'],
        }),
        new HtmlWebpackPlugin({
            filename: './about.html',
            template: './src/about.mustache',
            inject: 'body',
            chunks: ['about'],
        }),
        new HtmlWebpackPlugin({
            filename: './work.html',
            template: './src/work.mustache',
            inject: 'body',
            chunks: ['work']
        }),
    ],

    resolve: {
        alias: {
            '@scss': path.resolve(__dirname, 'src/scss'),
            '@img': path.resolve(__dirname, 'src/img'),
            '@': path.resolve(__dirname, 'src')
        }
    }
    
}

Please pay attention to this part:

{
                test: /\.mustache$/,
                loader: 'mustache-loader',
                options: {
                    tiny: true,
                    //I want this part to be used differently for each page 
                    render: {
                        title: 'hello Index',
                    },
                },
}

I know I could write as many rules as number of mustache pages I have, but I'm wondering whether data can be passed to the template through each HtmlWebpackPlugin declaration, instead of through the rule.

Thank in advance ๐Ÿ‘Œ๐Ÿฝ

How do mustache avoid xss attack?

At first ,I use doT.js,It seems that doT do not check the input content.If the content is alert(999)</script>,then it will execute and alert the window. Now I change to use mustache.js.It seems OK.How do mustache avoid xss attack?

YAML support

I can't find a way to use YAML with mustache.

I insalled this node version: https://www.npmjs.com/package/mustache

Works fine if I use a JSON.

This is the files I use:
data.yml

---
name: Hello
---

template.html

<html>
<body>
<h1>{{name}}</h1>
</body>
</html>

Windows Command
$ mustache data.yml tempalte.html > template_compiled.html

Mustache-ES6

Mustache is an important template system for Web and non-Web applications... But Javascript is also a great inspiration and reference, for JSON and Mustache. Javascript evolved, particularly with the ECMA's v6 edition, "ES6". Currently, the ${x} of the template literals is a de facto standard.

The adoption of {{x}} was a good choice (it resembles the Mediawiki templates), and there is no problem with it... But it was arbitrary, before 2015 there was no Javascript-reference โ€” that's an important part of the "standards ecosystem". Now, maybe, we can try to restart with non-arbitrary choice.

Question and suggestion: is it possible (or "are there people in this community?") to create a fork by Mustache iniciative (suggested name "Mustache-ES6") to test and evolve to the new standard?


PS: about particular Javascript implementation and optimizations, see this es6-template-engine project.

How to scape template variables?

Hi,

I have a template file, that i am using to generate some project files, and this template file has some mustache variables that I do not want to expand/render at the generation phase, because that should be done in a later stage when the project is already generated and we want to deploy it.

I would like to be able to escape some template variables to be able to use them only when application is deployed and not in the "generation" phase.

Thank you

Pedro

What characters are allowed in a tag name/key?

Hi

What characters are allowed as a tag name/key?

I looked in the documentation but couldn't find anything. For example is {{first-name}} and {{firstName}} ok, or is it only lowercase a-z?

all the best
Dave

Mustache substitution minimum string length

I'm writing a template that eventually will render C structures. For that, I want to set the minimum substitution length, pretty much like printf("%10s") would do, so I get aligned members in my header file.

Is there a way to set the minimum length of a string when it's substituted or I have to do it on my context?

context = {
    'group' : [
        {'name' : 'Bob',
         'id'   : 2345},
        {'name' : 'Alice',
         'id'   : 4567}
    ],
    'id' : 1234
}

template =\
'''
The group id is {{id}}
{{#group}}
Name: {{name}}, id {{id}}
{{/group}}
'''

renderer = pystache.Renderer()
output = renderer.render(template, context)
print(output)

I would like to render it like:

The group id is 1234
Name: Bob,   id 2345
Name: Alice, id 4567

I know I could pass the resulting header file in a beautifier tool like indent or uncrustify, but I'm curious if it can be done in Mustache.

Thanks!!

Link to node.js is a deprecated project

I would suggest removing the link to "node.js" (leading to https://github.com/raycmorgan/Mu) on the https://mustache.github.io/ page. That project seems to be abandoned, the author hasn't commited anything in over a year and there are four open pull requests. One of them is by me, the author has never responded. I'm suggesting to remove that link, since the project linked under "JavaScript" (https://github.com/janl/mustache.js) also has a node.js command line tool. So the link under "node.js" is actually just a less maintained version of the "JavaScript" link.

another implementation in Erlang

Dear site owner

I am writing another implementation in Erlang, which supports partials tag and a bit performance improved.
Please add my implementation aihtml in your site.

How is multi-line content handled?

What should I do if my content can contain line breaks?
In general, content is HTML encoded while rendering, but that does not affect \n

What should I do if my content is a multi-line string?

  • pre-process the text, replacing newlines by
    tags?
    => then I cannot use mustache's built-in HTML encoding for the content, as it would HTML-encode each
    tag to <br>

  • post-process the rendered output, replacing newlines by
    ?
    => I might incorrectly encode newlines which were not part of any content

  • Do all the HTML encoding of my content myself, so I can convert newlines to
    and then use a triple{{{}}} tag for my content
    => this seems to be the only working solution, but it seems a little cumbersome

Since content is HTML-encoded by default, wouldn't it make sense then, to also convert newlines in content to
tags?

How to escape a partial's output?

Hi,
is there any way to escape the output of a partial? E.g. when using the output of the partial as the value of an attribute like this:
<input type="hidden" value="{{> generateHtml }} "/>
Thanks in advance!

Handling recursion

I'm working on a family tree project which currently builds it's html with a recursive php function. It starts with the oldest ancestor and processes family units, meaning husband/wife/children. Each child within a family unit could have it's own family unit and so on to an unknown depth.

The information for each individual is fixed and could be expressed as a Mustache template but I can't figure out how to handle the recursive and nesting aspects of the tree.

Has anyone come across this situation and solved it? It could apply to iother examples like bill-of-materials or org charts.

Thanks,
Pete

Mustache need a standard helper-library?

Mustache is simple and can do a lot of things, but some simple-tasks, typical for any template system, are not trivial with Mustache... For example the classic simple task of rendering a list with separators in TXT format:

red, green, blue need commas separating items.

The best solution is not automatic, need the "strange input" last.

{"items": [
    {"name": "red"},
    {"name": "green"},
    {"name": "blue"}
]}
{{#items}}
    {{name}}{{^last}}, {{/last}}
{{/items}} 

The "strange input" (a boolean) and the "reserved word" (last) can be injected by a helper-function... So, the best practice is to imagine "strange input" and the "reserved word" as standard Mustache's recommendations, instead "strangers". The logic of the injection is something as:

model['items'][ model['items'].length - 1 ].last = true;

And, in fact, it received ~100 votes as good practice here... See also this suggestion to transform it into a function of a reference-library... standard external library of helper-functions, or external class of helper-methods.
Imagine helper-functions grouped my prefix ms_. The function ms_items_setLast() solves the problem above, and some other functions as will be the recommended solution for other simple tasks, like the ones discussed on Stackoverflow.


Javascript:

function ms_items_setLast(x,label='') {
   x[ x.length - 1 ].last = true
   return x
}
// model = ms_items_setLast(model.items);

Python:

def ms_items_setLast(x,label=''):
      x[ len(x) - 1 ]['last'] = True
# ms_items_setLast(model['items'])

Summary: a "good practice + helper-functions" library.

PS: people who like the initiative just need a bit of discussion and blessings here, to start a new git with the library... External standalone, no impact, but ideally at github.com/mustache/stdlib.

Suppress stdout

Hi, can the ...

say qq(Tag Type: "$tag->{type}", txt: $txt);

on line 342 be taken out, or made into an option? As when running inside Mojolicious framework, the 'say' is outputted to the http response and corrupts the headers. Unless there is an easy way to temporarily redirect stdout while running the render method?

Great module by the way.

Thanks,
Dan

Lists delimiter character

When working with lists, sometimes you need to have a delimiter character like a comma, to separate them, but when the last item is rendered that comma should not be added.

I'm thinking in something like this as a starting point:

export no_proxy="{{#noproxy}}{{.}}{{=,}}{{/noproxy}}"

the {{=,}} is the delimiting character that should be used when is not the last item.

Naming of # symbol

In the documentation, the symbol # is called pound, which is really confusing in British English and in financial institutions, as it used for the GBP symbol (ยฃ).

Problem with html-loader and mustache

My html-loader is having issues with mustache. I added an option for images to have hash and also for videos to have hash in my webpack.common.js. The output for the videos and for the images is correct in the /dist folder - the hash is there, but my output code does not have the hash.

Here is my folder structure:

+--js
+--scss
+--img
+--video
|   index.mustache
|   about.mustache
|   work.mustache

And my webpack.common.js configuration:

const webpack = require('webpack');
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const currentTask = process.env.npm_lifecycle_event;
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
    
    entry: {
        main: './src/js/home.js',
        about: './src/js/about.js',
        work: './src/js/work.js',
    },

    module:{
        rules: [
            //rule for JS
            {
                test: /\.js$/,
                exclude: /(node_modules)/,
                use:'babel-loader'
            },
            //rule for html
            {
                test: /\.html$/i,
                loader: 'html-loader',
            },
            //rule for mustache files
            {
                test: /\.mustache$/,
                loader: 'mustache-loader',
                options: {
                    tiny: true,
                    render: {
                        title: 'hello Index',
                        subtitle: 'this is a subtitle',
                    },
                },
            } ,
            //Vue loader
            { 
                test: /\.vue$/, 
                use: 'vue-loader'
            },
           //rule for img 
           {
            test: /\.(png|svg|gif|jpg)$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: "[name].[hash].[ext]",
                            outputPath: "img/",
                            publicPath: './img/'
                        }
                    },
                ],
            },
         // // rule for pdf files
            {
                test: /\.(pdf)$/,
                use: {
                    loader: 'file-loader',
                    options:{
                        name: '[name].[ext]',
                        outputPath: "files/",
                        publicPath: './files/'  
                    }
                },
            },

            // // Assets Loader
            {
                test: /\.(mp4|mov|avi|wmv|webm)$/,
                use: {
                    loader: 'file-loader',
                    options:{
                        name: '[name].[hash].[ext]',
                        outputPath: "video/",
                        publicPath: './video/'
                    }
                },
            },

            // Font Loader
            {
                test: /\.(woff|woff2|svg)$/,
                exclude: [path.resolve(__dirname, './src/img/')],
                use: {
                    loader: 'file-loader',
                    options:{
                        name: '[name].[ext]',
                        limit: 4096,
                        mimetype: "application/font-woff",
                        outputPath: 'css/fonts/',
                        publicPath: './css/fonts/',  
                    }
                },
            }

        ],
    },
    plugins:[
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            filename: './index.html',
            template: './src/index.mustache',
            inject: 'body',
            chunks: ['main'],
        }),
        new HtmlWebpackPlugin({
            filename: './about.html',
            template: './src/about.mustache',
            inject: 'body',
            chunks: ['about'],
        }),
        new HtmlWebpackPlugin({
            filename: './work.html',
            template: './src/work.mustache',
            inject: 'body',
            chunks: ['work']
        }),
    ],
    resolve: {
        alias: {
            '@scss': path.resolve(__dirname, 'src/scss'),
            '@img': path.resolve(__dirname, 'src/img'),
            '@': path.resolve(__dirname, 'src')
        }
    }
    
}

I don't want to remove the hashes from the images and videos, so I wonder what else can I do.
Thank you!

linebreaks / empty vars in plain text files

Hi,
I'm using Mustache to merge plain text templates.
I have the following scenario:

data

{
"name":"James"
,"colour":"green"
,"book":"War and peace"
}

template

This is what we know about {{name}}: 
{{#colour}}- Favourite colour is {{colour}}{{/colour}}
{{#fruit}}- Favourite fruit is {{fruit}}{{/fruit}}
{{#book}}- Favourite book is {{book}}{{/book}}

Result:

This is what we know about James: 
- Favourite colour is green

- Favourite book is War and peace

Note the glaring gap between the two lines...
Now, in a HTML template this would not be and issue, white spaces and empty lines are eaten by the browser and the result flows nicely. In a plain text environment though, this is an issue.

Is there an established way to deal with this? Is there a construct that drops the line including the line break after the field?

Nested contexts

There is a difference in specifications and documentation about contexts. The documentation says the following:

A {{name}} tag in a basic template will try to find the name key in the current context. If there is no name key, nothing will be rendered.

In other words there is no context inheritance.

But as i can see in specifications context inheritance exists. For example in the spec https://github.com/mustache/spec/blob/master/specs/sections.yml#L67 there is no property "b" in object "a" but it is successfully used.

Where is a mistake? Or may be i missunderstood something?

Optional variables

Many mustache implementations throw an error if a referenced variable has a null value.
However this is z common case: print the value if it is not null.
Now we can handle this by the following syntax:

{{#someVariableA}}{{.}}{{/someVariableA}}

I suggest to introduce the following syntax sugar to replace the following:

{{?someVariableA}}

multi-line yaml input to mustache template outputs as JSON

I posted this question on stack exchange...

https://stackoverflow.com/questions/53829832/multi-line-yaml-input-to-mustache-template-outputs-as-json

However, it looks like a bug to me after reading the manual and trawling google searches all morning.

I stripped the code down even further, since I posted that example to really try to minimise.

inputs="ingress_test_inputs.yaml"
auth_annotations="
    foo: bar baz
    sam: jam man"
echo "namespace: qa" > $inputs
echo "auth_annotations: ${auth_annotations}" >> $inputs

echo "----- Ingress inputs (${inputs}) -----"
cat $inputs

echo '---
metadata:
  annotations:
    nginx/thing:
      another_thing:
      {{{auth_annotations}}}
spec:
  rules:
    - host: bla-bla-bla.{{{ namespace }}}.example.com' >ingress.mustache

echo "----- Raw Ingress (ingress.mustache): -----"
cat ingress.mustache

mustache $inputs ingress.mustache > ingress-1.0.yaml

echo "----- Will apply the following ingress: -----"
cat ingress-1.0.yaml

Here's the output I get from the above...

----- Ingress inputs (ingress_test_inputs.yaml) -----
namespace: qa
auth_annotations:
    foo: bar baz
    sam: jam man
----- Raw Ingress (ingress.mustache): -----
---
metadata:
  annotations:
    nginx/thing:
      another_thing:
      {{{auth_annotations}}}
spec:
  rules:
    - host: bla-bla-bla.{{{ namespace }}}.example.com
----- Will apply the following ingress: -----
---
metadata:
  annotations:
    nginx/thing:
      another_thing:
      {"foo"=>"bar baz", "sam"=>"jam man"}
spec:
  rules:
    - host: bla-bla-bla.qa.example.com

and I really don't understand why the line after "another_thing" is rendered as JSON instead of YAML.

I'm using mustashe v1.1.0 on Ubuntu 18.04.

Thanks!

Unrendered MD Link in mustache(5)

For some reason, the ERB link in mustache(5) (in Partials) is not being rendered as expected:

They also inherit the calling context. Whereas in an [ERB]
(http://en.wikipedia.org/wiki/ERuby) file you may have this:

It looks like the markdown link was not rendered but carried over verbatim to HTML:

I couldn't figure which is the markdown source file used to build that page, otherwise I'd have made a PR to fix it.

time complexity of mustache

Hi, where can I find some general details about mustache time complexity or algorithm details (without dive into the code)?

how the size of the template / dictionary influence the time complexity?

thanks!

Logic-less value key compare and default value suggestion

I know this is not an issue, but it would be nice to have some possibility to compare or test value when writing block and to write default value more effective way.

To keep logic-less syntax, what about something like this?

Compare:

/* data */
{'value': 'ipsum'}

/* mustache */
{{ #value is lorem }}
    [[ Value is equal to lorem ]]
{{ /value }}

{{ ^value is lorem }}
    [[ Value is not lorem ]]
{{ /value }}

Occurence in the string:

/* data */
{'value': 'lorem': 'lorem ipsum'}

/* mustache */
{{ #value contains lorem }}
    [[ Value contains lorem ]]
{{ /value }}

{{ ^value contains lorem }}
    [[ Value doesn't contain lorem ]]
{{ /value }}

I think this is quite logic-less. More than that, I think that more can be improved eg for default values Because of following reasons.

Istead of writing this:

{{ value }}{{ ^value }} [[ No value ]] {{ /value }}

Wouldn't it be easier and more clear to have syntax like this?

{{ value, No value }}

I understand logic-less structure, it can be used by anyone, but sometimes this kind of "logic-less" code is really hard to read. And Im saying this as developer whose "logic-less" needs to be understand by non developers, by marketing people or designers. Such functionality I'm proposing could help a lot. I also know I can use handlebars instead, or I can modify mustache code, but I believe this shouldn't be prefered way.

Thanks in advance for considering my suggestions.

use value from list based on another key

Hello, Everyone

Sorry if the question is already answered somewhere or it's too trivial.
I'm looking for a way to use a value from the list based on another value
e.g.

system: {
latest: v2
}

systems: {
v1: {
item: 1
},
v2: {
item: 111
}
}

and in markdown:

{{systems.{{system.latest}}.item}}

:) syntax doesn't work but I hope it will help to show where I'm heading.

Help with sections

Hi, I need some help preparing a template. I have the following hash:

{
    "key": "value123"
}

I want to print Value is: value123 only if there is key in the hash. How would I do that?

{{#key}}
Value is {{XXX}}.
{{/key}}
{{^key}}
No key, no value!
{{/key}}

What should I put in place of XXX to get the desired output? In other words, how do I display the value of a hash key that I based the section on, rather than a nested key value?

I know that if the case would be

{
   "key":  { "door":  "value123" }
}

I could do

{{#key}}
Value is {{door}}.
{{/key}}
{{^key}}
No key, no door, no value!
{{/key}}

It's just not what I need right now.

custom section delimeters

I'd like to use mustache section template tags in filenames but my file system won't allow me to include the / character. Would you be open to modifying the spec to include customizing section tag delimiters?

Currently string replacement before rendering is a trivial work around, but I think this would be a nice feature.

Thanks!

Make current index available for lists

I've found it extremely limiting not to be able to have a reference to the current index while rendering lists of data. An example of when this is useful is when each rendered item needs a unique ID.

Currently the workaround is to include this unique ID in the data, but that is error-prone and not really the correct place for it.

Thank you for considering this feature

How to trim all the spaces of a string

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 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.