-
Notifications
You must be signed in to change notification settings - Fork 14
Inserting a string from external file inside a generated js file brings an undesired newline #11
Comments
Are you sure that |
Hi Tav, I work with Augusto. Whay not create a specific parameter that says to Assentgem to consider the cheers, On Thu, Oct 25, 2012 at 11:10 AM, tav notifications@github.com wrote:
|
Hey Nitai, As it is, it's left up to the developer to decide whether they want a newline or not by putting them in or leaving them out of the source files that they are including. I think that's the simplest approach and provides no surprises since it outputs exactly what is provided as input. However, your use case suggested that there might be value in having a generate:
- runtime-styles.js:
source:
- assets/single-line.css
compress: false
template: |
insert_css(${source|trim,jsliteral});
js.uglify.bin: uglifyjs
output.directory: build
output.hashed: false The |
Hi, Tav! Thanks for implementing this so quickly! This solution works as desired. However, it's unclear what the expected behavior should be when we have more than one source file. As experimented, it seems that the generate:
- composite.js:
source:
- assets/some-content.html
- assets/behavior.coffee
- raw: "})();"
template: |
(function(){var htmlContent = '${source|trim,jsliteral}'; This works, but it probably should be explicit, should you have more than one source file, don't you think so? |
Ah, my bad, should have been clearer on the usage. It applies the template to every source file (i.e. not raw strings) which is not processed in any way, i.e. not CoffeeScript/TypeScript files. And, oh, it only works when source maps are disabled. Hope that makes sense? |
Thanks! I've updated the example in the README so people can see and use this new feature. Even though at some point I think we should have a full blown documentation (e.g. on readthedocs.org, using Sphinx). I don't have experience with that yet, but this could be an excuse to learn. :) |
Thanks again and, yeah, proper documentation would be very cool. If you are up for it, that would be fantastic! |
Description
We're trying to build a js file that has a string whose content comes from another external file (e.g. for inserting css styles dynamically into the DOM). The problem is, in Javascript, strings must be contained in a single line, and when assetgen imports the file, a newline gets added at the end.
How to reproduce
Take any file (in this example, assets/single-line.css) that has a single line (contains no newlines) in it. Use the following yaml configuration file to generate a new .js file (in this case, runtime-styles.js). For the record, we're using Linux (in case the newline stuff makes any difference).
The generated runtime-styles.js file will have to lines. An unwanted newline will appear before the closing part (i.e.
");"
).The text was updated successfully, but these errors were encountered: