Giter VIP home page Giter VIP logo

grunt-kot2html's Introduction

  • ๐Ÿ”ญ Iโ€™m currently working at codestar.nl
  • ๐Ÿ’ฌ Ask me about FRP in the front-end, State Management, TypeScript, GraphQL, React, Nx

grunt-kot2html's People

Contributors

mdvanes avatar

Watchers

 avatar  avatar

Forkers

gruntjs-updater

grunt-kot2html's Issues

Missing property rootId for 'stripping' templateId

As we discussed. We need some sort of logic to 'strip' the template Id
`/*

'use strict';

module.exports = function (grunt) {

grunt.registerMultiTask('kot2html', 'Grunt task to combine Knockout templates into one HTML for the Knockout.js-External-Template-Engine.', function () {

    var path = require('path'),
        files = grunt.file.expand(this.data.src),
        destObj = path.parse(this.data.dest),
        result = '',
        deepEqual = require('deep-equal'),
        prefix = this.data.prefix,
        idRoot = this.data.idRoot,
        relativePath;


    files.forEach(function (file) {
        grunt.verbose.writeln('Processing', file);


        // Prevent reading the output file
        if (!deepEqual(destObj, path.parse(file))) {

            relativePath = path.dirname(file);

            //check if a path is defined to used for stripping the base
            if(idRoot){
                if(path.dirname(file).indexOf(idRoot) === 0){
                    relativePath = relativePath.replace(idRoot, '');
                }else if(path.dirname(file).indexOf(idRoot) > 0){
                    throw new Error('idRoot is not the root of the source-file');
                }else if(path.dirname(file).indexOf(idRoot) === -1){
                    throw new Error('idRoot does exist in root path of source-file');
                }
            }

            // Strip the extension to determine the template name
            var templateId = prefix +
                relativePath + '/' +
                path.basename(file).replace('.html', '');
            var content = grunt.file.read(file);

            result += '<script type="text/html" id="' + templateId + '">\n    ' + content + '\n</script>\n\n';
        }
    });

    grunt.file.write(this.data.dest, result);
    grunt.log.writeln('Compilation to ' + this.data.dest + ' completed successfully');
});

};
`

prevent template nesting

When having a template which already has a small part of js-templating inside the file, script-tags will get nested. To prevent this, you should check the content of the html file for existing <script> tags and write that part directly into the output file.

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.