Code Monkey home page Code Monkey logo

gulp-directive-replace's Introduction

Hello there! ๐Ÿ‘‹

I've been a Web Developer since 2006, and I've worked as a front-end, back-end, mobile, full stack and tech leader in several startups and companies of all sizes.

My current core stack is based on the JavaScript ecosystem, with NodeJS, KoaJS, Prisma, React, React Native, TailwindCSS, NextJS and Vercel, but I have a lot of experience with AWS services, Docker, CI/CD in general, serverless and some other cool stuff.

Since 2019, I've been constantly creating content in Portuguese, on Instagram and Youtube through Codar.me, a company that I create with my wife to teach developers how to develop real software. In total, we've helped over 70k developers and counting!

gulp-directive-replace's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

gulp-directive-replace's Issues

empty attribute is removed

I have a template that needs to have an empty attribute, but it is being removed.

It is a case of ng-options, for a select box where I want to have a static option on top in case no model is selected yet. This option-tag needs to have value="" for angular to pick it up properly. See more over at the docs: https://docs.angularjs.org/api/ng/directive/select

So, is this optimisation of the html customizeable? Can I turn it off?

Escaping ' character

Any of my directives html that contain the ' character don't get properly escaped when replacing the templateUrl with a string literal.

I looked through the source and found the following code on line 80 in index.js:

var result = output.replace(templateUrlRegExp, 'template: \'' + data + '\'');

I found that replacing the above line of code with the following fixes the problem:

var result = output.replace(templateUrlRegExp, 'template: \'' + data.replace(new RegExp("[']", 'g'), "\\'") + '\'');

I request that this fix be place into the main source.

Cheers

Fails when more than one `templateUrl` instance per file

(1) If a file has more than one templateUrl: '.../template.html'; instance, the script fails and is unable to inline both templates properly. This could be the case if a user has more than one directive per file, or has a directive which references multiple template files.

Should upgrade the plugin logic to map the templateUrl matches to an array, then get template contents for each result in that array, then search-replace with template: '...' based on content position within that array.

(2) If using <script type="text/ng-template" id="template.html">...</script> to push a template into your $templateCache, when plugin comes across templateUrl: 'template.html'; instance in a directive, it will fail to find a matching template file.

In this case, the expected behavior is to use try { ... } catch (error) { ... } so that the gulp task doesn't crash. And in the case that a template file is not found, skip replacing this instance and leave it as-is (ie. leave it as templateUrl: 'template.html', instead of making it template: '' [where the content is blank]).

Issue with ng-pattern when compiled into template

If your template.html file has a field that uses an ng-pattern="/^[^\s]*$/", where the pattern has a backslash, when the templateUrl: '...' is changed to template: '...' within your directive, the pattern now fails (because it requires a double-backslash as a result of being declared within javascript).

Relevant discussion: http://stackoverflow.com/questions/24394216/i-want-to-be-able-to-set-angulars-ng-pattern-inside-a-directive-with-a-template

My suggestion: when injecting the minified template content into the directive, at this point, regex match the template content for ng-pattern="(.*)", and for the matched content, replace \ with \\.

[Edit:] Issue effects all backslashes, not just ng-pattern. So for example, if you have a backslash character in a paragraph, it will not appear when the view is rendered.

[Edit:] Had another bug where the minimize was causing the template to break. It took <option value="">...</option> on a select dropdown, and changed it to <option>...</option>, causing the label in that option field to no longer display. I had to set minify: {empty: true}. Not really something that should be set by default, but leaving this here for future reference, in case someone else has a similar error.

minify: can no longer set options

I would like to set removeComments: true for minify to remove comments from the template html, but the package no longer allows changing minify options :(

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.