alanshaw / grunt-include-replace

Grunt task to include files and replace variables. Allows for parameterised includes.
MIT License
200 stars 45 forks source link

Global issue #50

Closed XhmikosR closed 9 years ago

XhmikosR commented 9 years ago

Hey, @alanshaw.

I have a project I use grunt-include-replace. My config is

includereplace: {
    dist: {
        options: {
            globals: {
                DATE: '<%= grunt.template.today("dddd, mmmm dS, yyyy, HH:MM:ss Z") %>',
                headHtml: '',
                bottomHtml: '',
                metaDescription: '',
                metaKeywords: ''
            }
        },
        files: [{
            src: ['*.html', '!**/google*.html'],
            dest: '<%= dirs.dest %>/',
            expand: true,
            cwd: '<%= dirs.src %>/'
        }]
    }
},

Everything works fine, except for bottomHtml; it's always empty. Here's how I call it from an HTML file:

@@include("_includes/header.html", {
    "title": "BowPad JavaScript Plugins",
    "headHtml": "<link rel=\"stylesheet\" href=\"/css/prettify.min.css\">",
    "bottomHtml": "<script src=\"/js/prettify/prettify.js\"></script>\n<script>window.onload = prettyPrint();</script>"
})
...

and in my footer.html I have

    @@bottomHtml

</body>
</html>

If I set bottomHtml to anything in Gruntfile globals, then it gets replaced just fine too.

Any ideas?

XhmikosR commented 9 years ago

In case you want to try, here's the source

svn checkout https://svn.code.sf.net/p/stefanstools/code/trunk/www/ stexbar-www
alanshaw commented 9 years ago

Is it because your include is including header.html and your trying to use bottomHtml in the footer, which is an empty global?

XhmikosR commented 9 years ago

Hmm, damn it, you are right. :)

This gets replaced, sort of

@@include("_includes/footer.html", {
    "bottomHtml": "<script src=\"/js/prettify/prettify.js\"></script>\n<script>window.onload = prettyPrint();</script>"
)}

But I end up with

@@include("_includes/footer.html", {
    "bottomHtml": "<script src=\"/js/prettify/prettify.js\"></script>\n<script>window.onload = prettyPrint();</script>"
)}

in the replaced html.

XhmikosR commented 9 years ago

Here's my local patch (sorry, it's a little messy, but you know, SVN :p) https://gist.github.com/XhmikosR/5eb919a788b6264fb302

XhmikosR commented 9 years ago

All right, a wrongly placed brace after the parentheses caused this :/

Thanks for all your help!