mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
Feature(generators): Add generators for login page and signup page
This commit is contained in:
26
tooling/generators/page-login/index.js
Normal file
26
tooling/generators/page-login/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
var fs = require('fs'),
|
||||
Generator = module.exports,
|
||||
Generate = require('../../generate'),
|
||||
path = require('path'),
|
||||
Q = require('q');
|
||||
/*
|
||||
@options
|
||||
name: Page name
|
||||
appDirectory: App directory of where to save file
|
||||
*/
|
||||
Generator.run = function run(options) {
|
||||
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
|
||||
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
|
||||
|
||||
var templates = Generate.loadGeneratorTemplates(__dirname);
|
||||
|
||||
templates.forEach(function(template) {
|
||||
var templatePath = path.join(__dirname, template.file);
|
||||
options.templatePath = templatePath;
|
||||
var renderedTemplate = Generate.renderTemplateFromFile(options);
|
||||
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join(''));
|
||||
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
|
||||
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
|
||||
fs.writeFileSync(saveFilePath, renderedTemplate);
|
||||
});
|
||||
};
|
22
tooling/generators/page-login/page-login.tmpl.html
Normal file
22
tooling/generators/page-login/page-login.tmpl.html
Normal file
@ -0,0 +1,22 @@
|
||||
<ion-toolbar *header>
|
||||
|
||||
<ion-title>
|
||||
<%= javascriptClassName %>
|
||||
</ion-title>
|
||||
|
||||
</ion-toolbar>
|
||||
|
||||
<ion-content padding>
|
||||
<form (submit)="doLogin($event)" [control-group]="loginForm">
|
||||
<ion-input>
|
||||
<input control="email" type="email" placeholder="Your email">
|
||||
</ion-input>
|
||||
<ion-input>
|
||||
<input control="password" type="password" placeholder="Your password">
|
||||
</ion-input>
|
||||
<button dark block type="submit">Log in</button>
|
||||
<div>
|
||||
<button block (click)="doSignup()">Create an account</button>
|
||||
</div>
|
||||
</form>
|
||||
</ion-content>
|
32
tooling/generators/page-login/page-login.tmpl.js
Normal file
32
tooling/generators/page-login/page-login.tmpl.js
Normal file
@ -0,0 +1,32 @@
|
||||
import {FormBuilder, Validators} from 'angular2/angular2';
|
||||
import {Log} from 'ionic/util'
|
||||
import {Page, NavController} from 'ionic/ionic'
|
||||
|
||||
@Page({
|
||||
templateUrl: 'app/<%= fileAndClassName %>/<%= fileAndClassName %>.html'
|
||||
})
|
||||
class <%= javascriptClassName %> {
|
||||
constructor(nav: NavController ) {
|
||||
|
||||
this.nav = nav
|
||||
Log.log('LOGIN PAGE', this)
|
||||
|
||||
var fb = new FormBuilder()
|
||||
|
||||
this.loginForm = fb.group({
|
||||
email: ['', Validators.required],
|
||||
password: ['', Validators.required],
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
doLogin(event) {
|
||||
Log.log('Doing login')
|
||||
event.preventDefault();
|
||||
console.log(this.loginForm.value);
|
||||
}
|
||||
|
||||
doSignup(event) {
|
||||
this.nav.push(SignupPage)
|
||||
}
|
||||
}
|
27
tooling/generators/page-signup/index.js
Normal file
27
tooling/generators/page-signup/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
var fs = require('fs'),
|
||||
Generator = module.exports,
|
||||
Generate = require('../../generate'),
|
||||
path = require('path'),
|
||||
Q = require('q');
|
||||
/*
|
||||
@options
|
||||
name: Page name
|
||||
appDirectory: App directory of where to save file
|
||||
*/
|
||||
Generator.run = function run(options) {
|
||||
|
||||
options.rootDirectory = options.rootDirectory || path.join('www', 'app');
|
||||
var savePath = path.join(options.appDirectory, options.rootDirectory, options.fileAndClassName);
|
||||
|
||||
var templates = Generate.loadGeneratorTemplates(__dirname);
|
||||
|
||||
templates.forEach(function(template) {
|
||||
var templatePath = path.join(__dirname, template.file);
|
||||
options.templatePath = templatePath;
|
||||
var renderedTemplate = Generate.renderTemplateFromFile(options);
|
||||
var saveFilePath = path.join(savePath, [options.fileAndClassName, template.type].join(''));
|
||||
// console.log('renderedTemplate', renderedTemplate, 'saving to', saveFilePath);
|
||||
console.log('√ Create'.blue, path.relative(options.appDirectory, saveFilePath));
|
||||
fs.writeFileSync(saveFilePath, renderedTemplate);
|
||||
});
|
||||
};
|
18
tooling/generators/page-signup/page-signup.tmpl.html
Normal file
18
tooling/generators/page-signup/page-signup.tmpl.html
Normal file
@ -0,0 +1,18 @@
|
||||
<ion-view nav-title="Signup" style="padding: 20px">
|
||||
<form (submit)="doSignup($event)" [control-group]="signupForm">
|
||||
<ion-input>
|
||||
<input control="name" type="text" placeholder="Your name">
|
||||
</ion-input>
|
||||
<ion-input>
|
||||
<input control="email" type="email" placeholder="Your email">
|
||||
</ion-input>
|
||||
<ion-input>
|
||||
<input control="password" type="password" placeholder="Your password">
|
||||
</ion-input>
|
||||
<button dark block type="submit">Create account</button>
|
||||
<div>
|
||||
<button block (click)="doLogin()">Log in</button>
|
||||
</div>
|
||||
</form>
|
||||
</ion-view>
|
||||
|
34
tooling/generators/page-signup/page-signup.tmpl.js
Normal file
34
tooling/generators/page-signup/page-signup.tmpl.js
Normal file
@ -0,0 +1,34 @@
|
||||
import {FormBuilder, Validators} from 'angular2/angular2';
|
||||
import {Log} from 'ionic/util'
|
||||
import {Page, NavController} from 'ionic/ionic'
|
||||
|
||||
|
||||
@Page({
|
||||
templateUrl: 'app/<%= fileAndClassName %>/<%= fileAndClassName %>.html'
|
||||
})
|
||||
export class <%= javascriptClassName %> {
|
||||
constructor(nav: NavController) {
|
||||
this.nav = nav
|
||||
|
||||
Log.log('SIGNUP PAGE')
|
||||
|
||||
var fb = new FormBuilder()
|
||||
|
||||
this.signupForm = fb.group({
|
||||
name: ['', Validators.required],
|
||||
email: ['', Validators.required],
|
||||
password: ['', Validators.required],
|
||||
});
|
||||
}
|
||||
|
||||
doLogin(event) {
|
||||
this.nav.pop()
|
||||
}
|
||||
doSignup(event) {
|
||||
Log.log('Doing signup')
|
||||
event.preventDefault();
|
||||
console.log(this.signupForm.value);
|
||||
|
||||
this.nav.push(AppPage)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user