All Projects → emmanueltouzery → Ng Typeview

emmanueltouzery / Ng Typeview

Licence: mit
Enables type-checking of angular1 views

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ng Typeview

Staradmin Free Angular Admin Template
Star Admin Angular Admin is a free admin template based on Bootstrap 4 and Angular
Stars: ✭ 112 (+460%)
Mutual labels:  templates, angularjs
Swiftgen
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!
Stars: ✭ 7,580 (+37800%)
Mutual labels:  templates
Ng Gentelella
An AngularJS admin interface based on the Gentelella bootstrap template markup.
Stars: ✭ 24 (+20%)
Mutual labels:  angularjs
Ng Suggest
AngularJS module to provide Typeahead via OpenSearch Suggestions
Stars: ✭ 9 (-55%)
Mutual labels:  angularjs
Jocs.github.io
💯Jocs 的个人博客,所有的文章都在 issues 里面
Stars: ✭ 840 (+4100%)
Mutual labels:  angularjs
Angular Svg Timer
An SVG-based timer button in AngularJS
Stars: ✭ 11 (-45%)
Mutual labels:  angularjs
Easy Pandoc Templates
A collection of portable pandoc templates with no dependencies
Stars: ✭ 23 (+15%)
Mutual labels:  templates
Ionic3 Angular43 Httpclient
Example of Ionic 3 and the new Angular 4.3 HTTPClient
Stars: ✭ 20 (+0%)
Mutual labels:  angularjs
Jmmasw
Just make me a static website
Stars: ✭ 13 (-35%)
Mutual labels:  templates
Load Templates
Load templates from file paths, globs or objects, and cache them as normalized objects.
Stars: ✭ 9 (-55%)
Mutual labels:  templates
Firebase Demo
Stars: ✭ 9 (-55%)
Mutual labels:  angularjs
Angular Loading Feedback
Angular directive to indicate loads in app
Stars: ✭ 8 (-60%)
Mutual labels:  angularjs
Chn Eolinker Ams Lite 4.0 For Php
中国最大的在线API管理平台EOLINKER 旗下API管理系统开源精简版,适合个人以及微型团队使用。
Stars: ✭ 869 (+4245%)
Mutual labels:  angularjs
Ngfilereader
This is file reader component on angular.
Stars: ✭ 25 (+25%)
Mutual labels:  angularjs
Bojler
Bojler is an email framework
Stars: ✭ 885 (+4325%)
Mutual labels:  templates
Mean Angular5 Passport Authentication
Securing MEAN Stack (Angular 5) Web Application using Passport Authentication
Stars: ✭ 24 (+20%)
Mutual labels:  angularjs
Materializecss Autocomplete
Small material design autocomplete library for materializecss
Stars: ✭ 9 (-55%)
Mutual labels:  angularjs
Angular Typed
the angularjs typing tool module, that helps you with typing animation
Stars: ✭ 11 (-45%)
Mutual labels:  angularjs
Angular Token Auth Seed
Stars: ✭ 20 (+0%)
Mutual labels:  angularjs
Builder Template Categories
Organize your Page Builder Templates in the WordPress Admin. Time saver, especially for bigger projects. Get a better and faster overview, don't get lost. Filter templates with your categories. With extended plugin & theme support.
Stars: ✭ 20 (+0%)
Mutual labels:  templates

ng-typeview

NPM version

Purpose

ng-typeview aims to enable type-checking of angular1 views. Normally, angular1 views are html files with special purpose markers (special tags & annotations) which are registered as angular directives and filters, which cooperate with the matching controller(s) which are written in javascript.

It is possible to use typescript instead of javascript for angular applications; in that case you get type-checking for the controllers and the remaining client-side code, but still no type-checking for the views, which are exercised only at runtime.

ng-typeview allows to extract the code from the views in new 'viewtest' typescript files, which can then get type-checked against the controllers.

Operation mode

ng-typeview is not an application, but a library. The reason is that it is expected that each real-world angular1 application will have enough customizations to require special handling, which will be better managed through custom code than options of an executable.

ng-typeview expects that in the controllers you define an interface for the scope:

interface Scope extends ng.IScope {
    modal: {title: string};
    showTitle: boolean;
}

(ng-typeview searches for an interface named Scope in the controller)

In the matching view, ng-typeview searches for expressions like {{title}}, or ng-if='showTitle', and similar.

Then it generates a new 'viewtest' typescript file containing the scope definition, and also expressions extracted from the view. A bit more complex expressions such as ng-repeat, ng-switch are also supported. Filters such as myList | orderBy: 'name' as well. The generated typescript code is not meant to be executed, only to be used for type-checking.

In addition you can also let ng-typeview know about your own directives and filters so they'll get extracted from the views & properly converted to typescript code for type-checking.

You can view an example of the operation by looking in the ng-typeview source, in the test/data subfolder, there is a controller, a view, and the expected generated typescript code, that can confirm whether the view type-checks or not.

API docs

You can see the full API documentation by clicking here.

The main entry point is the processProject function. You must prepare a ProjectSettings object and processProject will go through your source and generate the 'viewtest' files. Each field of ProjectSettings allows you to customize an aspect of the integration with your angular1 application.

Getting started

You need to create an application depending on ng-typeview. And basically you just need to call processProject. Then ng-typeview will generate the 'testview' files in the folder of your application. Then try to compile your application. The typescript compiler will warn you in case some code from the views doesn't match code from the controllers.

You can look at test/ng-typeview.ts for a sample set-up.

That's good for a first run, but then you probably have to customize ng-typeview for your application.

ng-typeview leaves the generated 'testview' files in your source code directory; it's probably best not to commit them to source control. If you minify your javascript, they won't be included since nothing links to them. If you don't, they might be copied to your server, but since noone links to them and they have no side-effects they shouldn't pose any problem. That said, deleting them is trivial, as they have a clear filename pattern.

Customizations

ng-typeview uses the typescript compiler API to parse the javascript and typescript code, htmlparser2 to parse the views, and the parsimmon parser combinator library to parse angular expressions (such as "for .. in .. track by ..").

ProjectSettings.ctrlViewConnectors

To begin with, ng-typeview must be able to connect controllers and views. It must find out that the controller app/core/user-list-ctrl.ts matches the view app/core/user-list-view.html. ng-typeview makes no assumption on files layout or naming conventions (especially since the controller-view connection may not be 1:1). By default ng-typeview can detect $modal.open() calls, which connect controllers and views, and also module state declarations (the ng-controller directive is ignored though for now). You can register new ways of connecting controllers and views, for instance if your app wraps these calls through helper functions, preventing ng-typeview from spotting them.

Since this is typescript parsing, this part is tied to the typescript compiler API.

ProjectSettings.ngFilters

If you define your own angular filters, you can let ng-typeview know about them and the parameters they expect through ngFilters. You just need to give a name and parameter types.

ProjectSettings.attributeDirectives & tagDirectives

You can also register your directives. There you must generate typescript code (as string), used to check the type-safety of the expressions found in the views. You implement either a AttributeDirectiveHandler, or a TagDirectiveHandler.

As input you get the contents of tags & attributes from the view. You are given some API to assist with the code generation, CodegenHelper; in fact you must use it, because ng-typeview must know when you declare new variables.

The directives that ng-typeview supports out of the box are developed using that mechanism, so you can also look at src/ng-directives.ts for examples of use.

Caveats

  • the API is still changing very often
  • was tested only against two projects from a single company for now
  • incomplete mapping of standard directives & filters (ng-typeview does not support all of the syntaxes of ng-repeat for instance.. Pull requests welcome :-) )
  • probably incomplete in just about all the aspects, as angular is huge
  • angular1 only

Commands

npm install

npm test

npm run-script docgen
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].