grunt-ts icon indicating copy to clipboard operation
grunt-ts copied to clipboard

Grunt attempts to process htmlOutputTemplate option

Open gustavderdrache opened this issue 9 years ago • 7 comments
trafficstars

I'm using [email protected] and when I specify a custom htmlOutputTemplate, I get this fairly cryptic error:

Running "ts:custom-template" (ts) task
Warning: An error occurred while processing a template (content is not defined). Use --force to continue.

Aborted due to warnings.

I've created a minimal configuration that reproduces the problem.

The issue appears to be the config.get function, which is documented to automatically process Lo-dash templates:

Template strings can be processed manually using the provided template functions. In addition, the config.get method (used by many tasks) automatically expands <% %> style template strings specified as config data inside the Gruntfile.

I'm not familiar enough with Grunt to know what the fix is. Hopefully it's as simple as just reading off the configuration object without calling get on it. If not, would you be amenable to allowing a function instead? It could have the same signature as the Lo-dash template, that is, (variables: { content: string, modulename: string, varname: string}) => string.

gustavderdrache avatar May 27 '16 15:05 gustavderdrache

Thanks for reporting. Works with old Grunt but seems broken with 1.0.1. Will investigate further. I don't know if it's possible for you, but if you go back to Grunt 0.4.5 it should work.

nycdotnet avatar May 30 '16 14:05 nycdotnet

This may be a breaking change in 1.x Grunt - I'm going to ask the folks at the Grunt repo. You identified the correct issue. The good news is that it's workaroundable by escaping the < and > chars with double backslashes.

https://lodash.com/docs#template

test_issue357: {
              test: true,
              html: ['test/test357/file.html'],
              src: ['./test/test357/'],
              options: {
                compile: false,
                htmlOutputTemplate: 'export default \'\\<%= content %\\>\''
              }
            }

nycdotnet avatar May 30 '16 15:05 nycdotnet

@gustavderdrache Thanks for the report - I think that the fix will be simply escaping the < and > chars in your templates as specified above if you're using Grunt >= 1.0. I will document this with the next patch.

nycdotnet avatar Jun 06 '16 18:06 nycdotnet

Sounds good. Thanks for the follow-up!

gustavderdrache avatar Jun 06 '16 18:06 gustavderdrache

The above workaround does not seem to work for me.

output in the *.html.ts:

export default '\<%= content %\>'

grunt:

$ grunt --version
grunt-cli v1.2.0
grunt v1.0.1

grunt-ts:

$ npm ls | grep grunt-ts
├─┬ [email protected]
├─┬ [email protected]

-Updated PS: could this be useful in finiding a fix: https://github.com/gruntjs/grunt/issues/123

TannerPO avatar Jun 22 '16 22:06 TannerPO

Any news or workaround?

viceice avatar Dec 17 '18 16:12 viceice

Sorry I have not been able to identify a solution.

nycdotnet avatar Dec 17 '18 16:12 nycdotnet