Skip to content

Commit

Permalink
added route for web-based controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaslin committed Oct 3, 2013
1 parent f9cab1b commit 364356d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/templates/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ dependencies {
exclude module: 'spring-boot-starter-tomcat'
}
compile 'org.springframework.boot:spring-boot-starter-jetty:<%= bootVersion %>'<% } %>
compile 'org.thymeleaf:thymeleaf-spring3:2.0.17'
<% if( actuator ){ %>compile 'org.springframework.boot:spring-boot-starter-actuator:<%= bootVersion %>'<% } %>
<% if( batch ){ %>compile 'org.springframework.boot:spring-boot-starter-batch:<%= bootVersion %>'<% } %>
<% if( jdbc ){ %>compile 'org.springframework.boot:spring-boot-starter-jdbc:<%= bootVersion %>'<% } %>
<% if( jpa ){ %>compile 'org.springframework.boot:spring-boot-starter-data-jpa:<%= bootVersion %>'<% } %>
<% if( hateoas ){ %>compile 'com.fasterxml.jackson.core:jackson-databind')
<% if( hateoas ){ %>compile 'com.fasterxml.jackson.core:jackson-databind'
compile 'org.springframework.hateoas:spring-hateoas:0.7.0.RELEASE'<% } %>
<% if( integration ){ %>compile 'org.springframework.boot:spring-boot-starter-integration:<%= bootVersion %>'<% } %>
<% if( logging ){ %>compile 'org.springframework.boot:spring-boot-starter-logging:<%= bootVersion %>'<% } %>
Expand Down
63 changes: 63 additions & 0 deletions route/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';
var util = require('util');
var yeoman = require('yeoman-generator');

var RestGenerator = module.exports = function RestGenerator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);
};

util.inherits(RestGenerator, yeoman.generators.Base);

RestGenerator.prototype.askFor = function askFor() {
var cb = this.async();

var prompts = [
{
type: 'string',
name: 'packageName',
message: '(1/4) Package name:',
default: this.config.get('packageName')
},
{
type: 'string',
name: 'viewName',
message: '(2/4) Name for your view:',
default: 'page'
},
{
type: 'string',
name: 'controllerName',
message: '(3/4) Name for your controller:',
default: 'MyController'
},
{
type: 'string',
name: 'controllerPath',
message: '(4/4) Path to Controller:',
default: '/hello-world'
}
]

this.prompt(prompts, function (props) {
this.packageName = props.packageName;
this.viewName = props.viewName;
this.controllerName = props.controllerName;
this.controllerPath = props.controllerPath;
cb();
}.bind(this));

};

RestGenerator.prototype.files = function app() {
var packageFolder = this.packageName.replace(/\./g, '/');
var controllersDir = 'src/main/java/' + packageFolder + '/controller';
var viewsDir = 'src/main/resources/templates';

this.mkdir(controllersDir);
this.mkdir(viewsDir);

this.template('Controller.java', controllersDir + '/' + this.controllerName + '.java');
this.template('view.html', viewsDir + '/' + this.viewName + '.html');

this.config.set('packageName', this.packageName);
};
17 changes: 17 additions & 0 deletions route/templates/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package <%= packageName %>.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class <%= controllerName %> {

@RequestMapping("<%= controllerPath %>")
public String process(@RequestParam(value = "content", required = false, defaultValue = "content") String content, Model model) {
model.addAttribute("content", content);
return "<%= viewName %>";
}

}
9 changes: 9 additions & 0 deletions route/templates/view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="${content}" />
</body>
</html>

0 comments on commit 364356d

Please sign in to comment.