nikestep / html-angular-validate

A HTML validator node module aimed at AngularJS projects
MIT License
14 stars 13 forks source link

Support for component templates (HTML in JS) #26

Closed miguelCT closed 6 years ago

miguelCT commented 6 years ago

Description

My team is working on an AngularJS project where we are using the latest ES specification along with an approach of "everything as a component".

Our AngularJS components tend to be small, so we decided to include the controller and template in the same file, following the same approach that the modern JS framework/libraries are using.

Example:

const angularComponent = {
    template: `
        <div id="dvContainer" class="container top-level">
            <span class="label">Nothing Special Div Fragment</span>
            <div>
                <ul>
                    <li>Item One</li>
                    <li>Item Two</li>
                    <li>Item Three</li>
                </ul>
            </div>
        </div>
    `,
    controller: class ComponentController {
        constructor() {
            console.log('This is the constructor');
        }
    }
};
export default angularComponent;

The only problem that we had encounter is the impossibility to validate the HTML inside the JS file because html-angular-validate only supports HTML files.

So I wonder if the library would be open to adding support for it.

Proposal

I've already implemented this feature in my local version of the library, so if you want, I can create a fork and open a PR with the changes.

The main idea is to add a new config parameter called componentext (similar to tmplext). Having this parameter, the library can read the component file and extract the template attribute and pass it to the w3cjs validator to be validated as a regular template.

miguelCT commented 6 years ago

Is there any update on this issue?

In my company, we have our own fork version published in our private npm repository, but we would like to do it more "official". @nikestep, if you see you can't continue with the support of this project, maybe my company could continue with it if you want.

miguelCT commented 6 years ago

This change has been accepted in #27. Thanks @nikestep