selaux / node-sprite-generator

Generates image sprites and their spritesheets (css, stylus, sass or less) from sets of images. Supports retina sprites. Provides express middleware and grunt task.
MIT License
192 stars 39 forks source link

Fails to render custom template... template file name is contents of output stylesheet #69

Open knightcode opened 6 years ago

knightcode commented 6 years ago

For each template type, lib/stylesheet/index.js calls getTemplatedStylesheet once passing in the contents of a file for the respective built in template, and getTemplatedStylesheet then returns a function that is used as renderStylesheet in nsg.js.

However, when using a custom template file,getTemplatedStylesheet is passed the filename instead of the contents of the file.

selaux commented 6 years ago

That was an intentional change on the current master here, which is not yet documented properly. Basically the new version will require you to pass the contents of a custom template file instead of the path. Does it work when you read the file contents with fs.readFileSync?

knightcode commented 6 years ago

eh. I don't really like the idea of including the template in Gruntfile.js. It's seems cleaner to have it separated off in its own file with which I can do a git diff independently of other code. Gruntfile is configuration.

It also seems harder to include a custom template if you ever provide a CLI.

selaux commented 6 years ago

You dont have to have it in your gruntfile, you just need to read it there. And for the CLI some code would be needed anyways so than can include reading custom templates. Of course it is one more line in your gruntfile but it makes the sprite generator much more versatile. The whole code can be executed independent of the javascript runtime that is used, e.g. in the browser. See https://github.com/selaux/node-sprite-generator/pull/67.

knightcode commented 6 years ago

I can't really imagine the app that would inflict that work on it's user, but I get what you're going for.

It still seems like you could load the 'fs' dependency only if the config calls for it and not obliterate your legacy users like me. But I don't keep grunt running in production, so my template will only waste memory on my MacBook while 'grunt watch' is running. I guess I can deal with that.