Giter Club home page Giter Club logo

Comments (7)

tav avatar tav commented on June 22, 2024

Are you sure that assets/single-line.css doesn't have a newline at the end of it? That's the only explanation I can see why there might be an unwanted newline in the generated file. Some text editors automatically put in a closing newline, e.g. with nano you have to explicitly call nano -L to stop it from inserting newlines.

from assetgen.

nitaibezerra avatar nitaibezerra commented on June 22, 2024

Hi Tav,

I work with Augusto.
Indeed there is a invisible newline at the end of it.
But, even so it's a comon use case to insert the content of a file into a
JavaScript string. There should be some easy way to handle that.

Whay not create a specific parameter that says to Assentgem to consider the
content of a file is a string. In other words, it would ignore newlines if
any exist.

cheers,
Nitai

On Thu, Oct 25, 2012 at 11:10 AM, tav [email protected] wrote:

Are you sure that assets/single-line.css doesn't have a newline at the
end of it? That's the only explanation I can see why there might be an
unwanted newline in the generated file. Some text editors automatically put
in a closing newline, e.g. with nano you have to explicitly call nano -Lto stop it from inserting newlines.


Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-9776796.

from assetgen.

tav avatar tav commented on June 22, 2024

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 js.template config value. So I just implemented it using the Mako templating language. Once you've upgraded assetgen to the new 0.3.2 release, you can achieve what you want with:

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 trim filter strips the newlines for you and I also added a jsliteral filter to quote the source properly as a JavaScript string. I hope that satisfies your needs. Let me know what you think. Thanks.

from assetgen.

augusto-herrmann avatar augusto-herrmann commented on June 22, 2024

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 ${source} parameter inside the Mako template applies the content of the first source file. Example:

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?

from assetgen.

tav avatar tav commented on June 22, 2024

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?

from assetgen.

augusto-herrmann avatar augusto-herrmann commented on June 22, 2024

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. :)

from assetgen.

tav avatar tav commented on June 22, 2024

Thanks again and, yeah, proper documentation would be very cool. If you are up for it, that would be fantastic!

from assetgen.

Related Issues (5)

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.