S
S
Sergey Burduzha2017-12-25 11:54:00
JavaScript
Sergey Burduzha, 2017-12-25 11:54:00

Why is mustache.js throwing an error?

I'm trying to create an svg sprite using gulp.
Here is the content of gulpfile.js

let svgSprite = require('gulp-svg-sprite'),
    svgmin = require('gulp-svgmin'),
    gulp = require('gulp'),
    cheerio = require('gulp-cheerio'),
    replace = require('gulp-replace');

gulp.task('svgSpriteBuild', function(){
    return gulp.src('assets/i/icons/*.svg')
    // minify svg
        .pipe(svgmin({
            js2svg: {
                pretty: true
            }
        }))
        // remove all fill, style and stroke declarations in out shapes
        .pipe(cheerio({
            run: function($){
                $('[fill]').removeAttr('fill');
                $('[stroke]').removeAttr('stroke');
                $('[style]').removeAttr('style');
            },
            parserOptions: {xmlMode: true}
        }))
        // cheerio plugin create unnecessary string '>', so replace it.
        .pipe(replace('>', '>'))
        // build svg sprite
        .pipe(svgSprite({
            mode: {
                symbol: {
                    sprite: "../sprite.svg",
                    render: {
                        scss: {
                            dest: '../../../sass/_sprite.scss',
                            template: "assets/sass/templates/_sprite_template.scss"
                        }
                    }
                }
            }
        }))
    .pipe(gulp.dest('assets/i/sprite/'));
});

Here is the contents of the scss template
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  fill: currentColor;
}

{{#shapes}}
.icon-{{base}} {
  font-size:({{height.inner}}/10)*1rem;
  width:({{width.inner}}/{{height.inner}})*1em;
}

Here is the compilation error
Starting 'svgSpriteBuild'...
/var/www/test.loc/node_modules/mustache/mustache.js:226
      throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
      ^

Error: Unclosed section "shapes" at 207
    at parseTemplate (/var/www/test.loc/node_modules/mustache/mustache.js:226:13)
    at Writer.parse (/var/www/test.loc/node_modules/mustache/mustache.js:450:34)
    at Writer.render (/var/www/test.loc/node_modules/mustache/mustache.js:465:23)
    at Object.render (/var/www/test.loc/node_modules/mustache/mustache.js:603:26)
    at /var/www/test.loc/node_modules/svg-sprite/lib/svg-sprite/mode/base.js:165:27
    at /var/www/test.loc/node_modules/async/dist/async.js:3866:24
    at replenish (/var/www/test.loc/node_modules/async/dist/async.js:998:17)
    at /var/www/test.loc/node_modules/async/dist/async.js:1002:9
    at _parallel (/var/www/test.loc/node_modules/async/dist/async.js:3865:5)
    at Object.parallelLimit$1 [as parallelLimit] (/var/www/test.loc/node_modules/async/dist/async.js:3971:5)

Process finished with exit code 1

I think that for mustache.js there are problems with the template, I found it out by random (I commented out all the tasks in turn).
Here is a link to the article glivera-team.github.io/svg/2016/06/13/svg-sprites-...
Here is a link to the project itself https://github.com/seriiserii825/bugfix
I've been struggling with this sprite for half a day , almost that it turned out, a little left to push))
I will be glad to help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kalibrov, 2017-12-25
@serii81

I think that the error occurs due to some invalid svg or scss template in which the tag does not close, check your svg files from which you are collecting the sprite.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question