heroku-vraptor-scaffold 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.rdoc +188 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +22 -0
- data/README.md +23 -0
- data/README.textile +51 -0
- data/Rakefile +20 -0
- data/bin/heroku-vraptor +8 -0
- data/heroku-vraptor-scaffold.gemspec +28 -0
- data/index.sample.html +169 -0
- data/lib/vraptor-scaffold.rb +14 -0
- data/lib/vraptor-scaffold/configuration.rb +54 -0
- data/lib/vraptor-scaffold/execution.rb +22 -0
- data/lib/vraptor-scaffold/generators/app/app_generator.rb +161 -0
- data/lib/vraptor-scaffold/generators/app/dependency.rb +15 -0
- data/lib/vraptor-scaffold/generators/app/dependency_manager.rb +32 -0
- data/lib/vraptor-scaffold/generators/app/templates/angular/angular.js +14327 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap-responsive.css +9 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.css +9 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.js +6 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings-white.png +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings.png +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/classpath.erb +18 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/project.erb +36 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.jdt.core.prefs +8 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.component.tt +10 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.project.facet.core.xml +10 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.container +1 -0
- data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.name +1 -0
- data/lib/vraptor-scaffold/generators/app/templates/heroku/Main.java +21 -0
- data/lib/vraptor-scaffold/generators/app/templates/heroku/Procfile +1 -0
- data/lib/vraptor-scaffold/generators/app/templates/jquery/jquery.min.js +4 -0
- data/lib/vraptor-scaffold/generators/app/templates/models/Entity.erb +46 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-hibernate.java.tt +50 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-jpa.java.tt +48 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-objectify.java.tt +41 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/hibernate.cfg.xml +7 -0
- data/lib/vraptor-scaffold/generators/app/templates/orm/persistence.xml +10 -0
- data/lib/vraptor-scaffold/generators/app/templates/pom.erb +110 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources-test/.empty_directory +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources/hibernate.properties +16 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources/log4j.properties +4 -0
- data/lib/vraptor-scaffold/generators/app/templates/resources/messages.properties +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/underscore/underscore.min.js +32 -0
- data/lib/vraptor-scaffold/generators/app/templates/vraptor-scaffold.erb +5 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/WEB-INF/web.xml.tt +33 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/images/.empty_directory +0 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/index.html +24 -0
- data/lib/vraptor-scaffold/generators/app/templates/webapp/javascripts/utils.js +7 -0
- data/lib/vraptor-scaffold/generators/base.rb +16 -0
- data/lib/vraptor-scaffold/generators/scaffold/attribute.rb +51 -0
- data/lib/vraptor-scaffold/generators/scaffold/base_scaffold.rb +54 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/client_generator.rb +41 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/controller.erb +75 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/details.erb +16 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/form.erb +39 -0
- data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/list.erb +40 -0
- data/lib/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator.rb +20 -0
- data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller.erb +77 -0
- data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller_test.erb +12 -0
- data/lib/vraptor-scaffold/generators/scaffold/model_generator/model_generator.rb +26 -0
- data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model.erb +32 -0
- data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model_test.erb +13 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator.rb +32 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository.erb +22 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_impl.erb +16 -0
- data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_test.erb +13 -0
- data/lib/vraptor-scaffold/generators/scaffold/scaffold_generator.rb +35 -0
- data/lib/vraptor-scaffold/runner.rb +9 -0
- data/lib/vraptor-scaffold/runner/commands_help.rb +13 -0
- data/lib/vraptor-scaffold/runner/generator.rb +15 -0
- data/lib/vraptor-scaffold/runner/help.rb +12 -0
- data/lib/vraptor-scaffold/runner/scaffold.rb +16 -0
- data/lib/vraptor-scaffold/version.rb +3 -0
- data/maven/repo/br/com/caelum/vraptor-gae/1.0/vraptor-gae-1.0.jar +0 -0
- data/spec/resources/vraptor-scaffold-objectify.properties +7 -0
- data/spec/resources/vraptor-scaffold.properties +7 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/vraptor-scaffold/configuration_spec.rb +146 -0
- data/spec/vraptor-scaffold/execution_spec.rb +51 -0
- data/spec/vraptor-scaffold/generators/app/app_generator_spec.rb +557 -0
- data/spec/vraptor-scaffold/generators/app/dependency_manager_spec.rb +34 -0
- data/spec/vraptor-scaffold/generators/app/dependency_spec.rb +14 -0
- data/spec/vraptor-scaffold/generators/app/freemarker_template_engine_spec.rb +80 -0
- data/spec/vraptor-scaffold/generators/app/jsp_template_engine_spec.rb +77 -0
- data/spec/vraptor-scaffold/generators/app/templates/Entity.java +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/FreemarkerPathResolver.java +21 -0
- data/spec/vraptor-scaffold/generators/app/templates/ObjectifyFactory.java +30 -0
- data/spec/vraptor-scaffold/generators/app/templates/RepositoryJPA.java +48 -0
- data/spec/vraptor-scaffold/generators/app/templates/RepositoryObjectify.java +41 -0
- data/spec/vraptor-scaffold/generators/app/templates/build.gradle +60 -0
- data/spec/vraptor-scaffold/generators/app/templates/build.properties +18 -0
- data/spec/vraptor-scaffold/generators/app/templates/build.xml +146 -0
- data/spec/vraptor-scaffold/generators/app/templates/classpath-gae +18 -0
- data/spec/vraptor-scaffold/generators/app/templates/decorators-jsp.xml +7 -0
- data/spec/vraptor-scaffold/generators/app/templates/decorators.xml +7 -0
- data/spec/vraptor-scaffold/generators/app/templates/freemarker-web.xml +60 -0
- data/spec/vraptor-scaffold/generators/app/templates/gae-jsp-web.xml +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/ivy-gae.xml +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/ivy.xml +40 -0
- data/spec/vraptor-scaffold/generators/app/templates/jsp-web.xml +45 -0
- data/spec/vraptor-scaffold/generators/app/templates/pom-heroku.xml +182 -0
- data/spec/vraptor-scaffold/generators/app/templates/pom.xml +157 -0
- data/spec/vraptor-scaffold/generators/app/templates/project-gae +47 -0
- data/spec/vraptor-scaffold/generators/app/templates/vraptor-scaffold.properties +7 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/build.gradle +62 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_build.gradle +62 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_ivy.xml +41 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_pom.xml +152 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/ivy.xml +42 -0
- data/spec/vraptor-scaffold/generators/plugin/expected_configs/pom.xml +182 -0
- data/spec/vraptor-scaffold/generators/scaffold/attribute_spec.rb +186 -0
- data/spec/vraptor-scaffold/generators/scaffold/base_scaffold_spec.rb +73 -0
- data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/controller_generator_spec.rb +62 -0
- data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/templates/ProductController.java +95 -0
- data/spec/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator_spec.rb +62 -0
- data/spec/vraptor-scaffold/generators/scaffold/controller_generator/templates/ProductController.java +95 -0
- data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/freemarker_generator_spec.rb +81 -0
- data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/templates/form.ftl +28 -0
- data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/jsp_generator_spec.rb +81 -0
- data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/templates/form.jsp +61 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/model_generator_spec.rb +54 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/objectify_model_generator_spec.rb +40 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/ObjectifyFactory.java +33 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Objectify_Product.java +38 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Product.java +25 -0
- data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/hibernate.cfg.xml +8 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/objectify_repository_generator_spec.rb +33 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator_spec.rb +68 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepository.java +22 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepositoryImpl.java +16 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepository.java +22 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepositoryImpl.java +16 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepository.java +22 -0
- data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepositoryImpl.java +16 -0
- data/spec/vraptor-scaffold/generators/scaffold/scaffold_generator_spec.rb +79 -0
- data/spec/vraptor-scaffold/http_request_spec.rb +40 -0
- data/spec/vraptor-scaffold/runner/commands_help_spec.rb +12 -0
- data/spec/vraptor-scaffold/runner/configure_spec.rb +12 -0
- data/spec/vraptor-scaffold/runner/generator_spec.rb +31 -0
- data/spec/vraptor-scaffold/runner/help_spec.rb +29 -0
- data/spec/vraptor-scaffold/runner/scaffold_spec.rb +35 -0
- data/spec/vraptor-scaffold/runner/start_spec.rb +51 -0
- data/spec/vraptor-scaffold_spec.rb +4 -0
- metadata +261 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
|
2
|
+
|
3
|
+
describe ControllerGenerator do
|
4
|
+
|
5
|
+
it "paths to simple model name" do
|
6
|
+
ControllerGenerator.new("product", build_attributes).path.should == "/products"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "paths to compound model name" do
|
10
|
+
ControllerGenerator.new("orderItem", build_attributes).path.should == "/orderItems"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "controller template path" do
|
14
|
+
ControllerGenerator.new("category", build_attributes).template_path.should == "src/templates/controllers"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "generating from a lowercased name" do
|
18
|
+
before(:each) do
|
19
|
+
mock_config_file
|
20
|
+
@generator = ControllerGenerator.new("product", build_attributes)
|
21
|
+
@generator.build
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
FileUtils.remove_dir("src")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create controller" do
|
29
|
+
source = File.join File.dirname(__FILE__), "templates", "ProductController.java"
|
30
|
+
destination = Configuration.main_class_path "controller", "ProductController.java"
|
31
|
+
exists_and_identical?(source, destination)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should create controller test" do
|
35
|
+
test_class = Configuration.test_class_path "controller", "ProductControllerTest.java"
|
36
|
+
File.exist?(test_class).should be_true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "generating from an uppercased name" do
|
41
|
+
before(:each) do
|
42
|
+
mock_config_file
|
43
|
+
@generator = ControllerGenerator.new("Product", build_attributes)
|
44
|
+
@generator.build
|
45
|
+
end
|
46
|
+
|
47
|
+
after(:each) do
|
48
|
+
FileUtils.remove_dir("src")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create controller" do
|
52
|
+
source = File.join File.dirname(__FILE__), "templates", "ProductController.java"
|
53
|
+
destination = Configuration.main_class_path "controller", "ProductController.java"
|
54
|
+
exists_and_identical?(source, destination)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should create controller test" do
|
58
|
+
test_class = Configuration.test_class_path "controller", "ProductControllerTest.java"
|
59
|
+
File.exist?(test_class).should be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
package app.controller;
|
2
|
+
|
3
|
+
import java.util.List;
|
4
|
+
|
5
|
+
import app.model.Product;
|
6
|
+
import app.repositories.ProductRepository;
|
7
|
+
import br.com.caelum.vraptor.Delete;
|
8
|
+
import br.com.caelum.vraptor.Get;
|
9
|
+
import br.com.caelum.vraptor.Post;
|
10
|
+
import br.com.caelum.vraptor.Put;
|
11
|
+
import br.com.caelum.vraptor.Resource;
|
12
|
+
import br.com.caelum.vraptor.Result;
|
13
|
+
import br.com.caelum.vraptor.Validator;
|
14
|
+
import br.com.caelum.vraptor.view.Results;
|
15
|
+
import com.google.gson.Gson;
|
16
|
+
|
17
|
+
@Resource
|
18
|
+
public class ProductController {
|
19
|
+
|
20
|
+
private final Result result;
|
21
|
+
private final ProductRepository repository;
|
22
|
+
private final Validator validator;
|
23
|
+
private final Gson json;
|
24
|
+
|
25
|
+
ProductController(Result result, ProductRepository repository, Validator validator) {
|
26
|
+
this.result = result;
|
27
|
+
this.repository = repository;
|
28
|
+
this.validator = validator;
|
29
|
+
this.json = new Gson();
|
30
|
+
}
|
31
|
+
|
32
|
+
@Get("/products")
|
33
|
+
public List<Product> index() {
|
34
|
+
List<Product > list = repository.findAll();
|
35
|
+
result.include("json", json.toJson(list));
|
36
|
+
return repository.findAll();
|
37
|
+
}
|
38
|
+
|
39
|
+
@Get("/products.json")
|
40
|
+
public void indexJson() {
|
41
|
+
result.use(Results.json()).withoutRoot().from(index()).recursive().serialize();
|
42
|
+
}
|
43
|
+
|
44
|
+
@Post("/products")
|
45
|
+
public void create(Product product) {
|
46
|
+
validator.validate(product);
|
47
|
+
validator.onErrorUsePageOf(this).newProduct();
|
48
|
+
repository.create(product);
|
49
|
+
result.redirectTo(this).index();
|
50
|
+
}
|
51
|
+
|
52
|
+
@Get("/products/new")
|
53
|
+
public Product newProduct() {
|
54
|
+
Product product = new Product();
|
55
|
+
result.include("json", json.toJson(product));
|
56
|
+
return product;
|
57
|
+
}
|
58
|
+
|
59
|
+
@Put("/products")
|
60
|
+
public void update(Product product) {
|
61
|
+
validator.validate(product);
|
62
|
+
validator.onErrorUsePageOf(this).edit(product);
|
63
|
+
repository.update(product);
|
64
|
+
result.redirectTo(this).index();
|
65
|
+
}
|
66
|
+
|
67
|
+
@Get("/products/{product.id}/edit")
|
68
|
+
public Product edit(Product product) {
|
69
|
+
product = repository.find(product.getId());
|
70
|
+
result.include("json", json.toJson(product));
|
71
|
+
return product;
|
72
|
+
}
|
73
|
+
|
74
|
+
@Get("/products/{product.id}.json")
|
75
|
+
public void showJson(Product product) {
|
76
|
+
serialize(show(product));
|
77
|
+
}
|
78
|
+
|
79
|
+
@Get("/products/{product.id}")
|
80
|
+
public Product show(Product product) {
|
81
|
+
product = repository.find(product.getId());
|
82
|
+
result.include("json", json.toJson(product));
|
83
|
+
return product;
|
84
|
+
}
|
85
|
+
|
86
|
+
@Delete("/products/{product.id}")
|
87
|
+
public void destroy(Product product) {
|
88
|
+
repository.destroy(repository.find(product.getId()));
|
89
|
+
result.redirectTo(this).index();
|
90
|
+
}
|
91
|
+
|
92
|
+
private void serialize(Object object) {
|
93
|
+
result.use(Results.json()).withoutRoot().from(object).recursive().serialize();
|
94
|
+
}
|
95
|
+
}
|
data/spec/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator_spec.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
|
2
|
+
|
3
|
+
describe ControllerGenerator do
|
4
|
+
|
5
|
+
it "paths to simple model name" do
|
6
|
+
ControllerGenerator.new("product", build_attributes).path.should == "/products"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "paths to compound model name" do
|
10
|
+
ControllerGenerator.new("orderItem", build_attributes).path.should == "/orderItems"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "controller template path" do
|
14
|
+
ControllerGenerator.new("category", build_attributes).template_path.should == "src/templates/controllers"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "generating from a lowercased name" do
|
18
|
+
before(:each) do
|
19
|
+
mock_config_file
|
20
|
+
@generator = ControllerGenerator.new("product", build_attributes)
|
21
|
+
@generator.build
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
FileUtils.remove_dir("src")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create controller" do
|
29
|
+
source = File.join File.dirname(__FILE__), "templates", "ProductController.java"
|
30
|
+
destination = Configuration.main_class_path "controller", "ProductController.java"
|
31
|
+
exists_and_identical?(source, destination)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should create controller test" do
|
35
|
+
test_class = Configuration.test_class_path "controller", "ProductControllerTest.java"
|
36
|
+
File.exist?(test_class).should be_true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "generating from an uppercased name" do
|
41
|
+
before(:each) do
|
42
|
+
mock_config_file
|
43
|
+
@generator = ControllerGenerator.new("Product", build_attributes)
|
44
|
+
@generator.build
|
45
|
+
end
|
46
|
+
|
47
|
+
after(:each) do
|
48
|
+
FileUtils.remove_dir("src")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create controller" do
|
52
|
+
source = File.join File.dirname(__FILE__), "templates", "ProductController.java"
|
53
|
+
destination = Configuration.main_class_path "controller", "ProductController.java"
|
54
|
+
exists_and_identical?(source, destination)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should create controller test" do
|
58
|
+
test_class = Configuration.test_class_path "controller", "ProductControllerTest.java"
|
59
|
+
File.exist?(test_class).should be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/vraptor-scaffold/generators/scaffold/controller_generator/templates/ProductController.java
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
package app.controller;
|
2
|
+
|
3
|
+
import java.util.List;
|
4
|
+
|
5
|
+
import app.models.Product;
|
6
|
+
import app.repositories.ProductRepository;
|
7
|
+
import br.com.caelum.vraptor.Delete;
|
8
|
+
import br.com.caelum.vraptor.Get;
|
9
|
+
import br.com.caelum.vraptor.Post;
|
10
|
+
import br.com.caelum.vraptor.Put;
|
11
|
+
import br.com.caelum.vraptor.Resource;
|
12
|
+
import br.com.caelum.vraptor.Result;
|
13
|
+
import br.com.caelum.vraptor.Validator;
|
14
|
+
import br.com.caelum.vraptor.view.Results;
|
15
|
+
import com.google.gson.Gson;
|
16
|
+
|
17
|
+
@Resource
|
18
|
+
public class ProductController {
|
19
|
+
|
20
|
+
private final Result result;
|
21
|
+
private final ProductRepository repository;
|
22
|
+
private final Validator validator;
|
23
|
+
private final Gson json;
|
24
|
+
|
25
|
+
ProductController(Result result, ProductRepository repository, Validator validator) {
|
26
|
+
this.result = result;
|
27
|
+
this.repository = repository;
|
28
|
+
this.validator = validator;
|
29
|
+
this.json = new Gson();
|
30
|
+
}
|
31
|
+
|
32
|
+
@Get("/products")
|
33
|
+
public List<Product> index() {
|
34
|
+
List<Product > list = repository.findAll();
|
35
|
+
result.include("json", json.toJson(list));
|
36
|
+
return repository.findAll();
|
37
|
+
}
|
38
|
+
|
39
|
+
@Get("/products.json")
|
40
|
+
public void indexJson() {
|
41
|
+
result.use(Results.json()).withoutRoot().from(index()).recursive().serialize();
|
42
|
+
}
|
43
|
+
|
44
|
+
@Post("/products")
|
45
|
+
public void create(Product product) {
|
46
|
+
validator.validate(product);
|
47
|
+
validator.onErrorUsePageOf(this).newProduct();
|
48
|
+
repository.create(product);
|
49
|
+
result.redirectTo(this).index();
|
50
|
+
}
|
51
|
+
|
52
|
+
@Get("/products/new")
|
53
|
+
public Product newProduct() {
|
54
|
+
Product product = new Product();
|
55
|
+
result.include("json", json.toJson(product));
|
56
|
+
return product;
|
57
|
+
}
|
58
|
+
|
59
|
+
@Put("/products")
|
60
|
+
public void update(Product product) {
|
61
|
+
validator.validate(product);
|
62
|
+
validator.onErrorUsePageOf(this).edit(product);
|
63
|
+
repository.update(product);
|
64
|
+
result.redirectTo(this).index();
|
65
|
+
}
|
66
|
+
|
67
|
+
@Get("/products/{product.id}/edit")
|
68
|
+
public Product edit(Product product) {
|
69
|
+
product = repository.find(product.getId());
|
70
|
+
result.include("json", json.toJson(product));
|
71
|
+
return product;
|
72
|
+
}
|
73
|
+
|
74
|
+
@Get("/products/{product.id}.json")
|
75
|
+
public void showJson(Product product) {
|
76
|
+
serialize(show(product));
|
77
|
+
}
|
78
|
+
|
79
|
+
@Get("/products/{product.id}")
|
80
|
+
public Product show(Product product) {
|
81
|
+
product = repository.find(product.getId());
|
82
|
+
result.include("json", json.toJson(product));
|
83
|
+
return product;
|
84
|
+
}
|
85
|
+
|
86
|
+
@Delete("/products/{product.id}")
|
87
|
+
public void destroy(Product product) {
|
88
|
+
repository.destroy(repository.find(product.getId()));
|
89
|
+
result.redirectTo(this).index();
|
90
|
+
}
|
91
|
+
|
92
|
+
private void serialize(Object object) {
|
93
|
+
result.use(Results.json()).withoutRoot().from(object).recursive().serialize();
|
94
|
+
}
|
95
|
+
}
|
data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/freemarker_generator_spec.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
|
2
|
+
|
3
|
+
describe FreemarkerGenerator do
|
4
|
+
|
5
|
+
it "freemarker template path" do
|
6
|
+
FreemarkerGenerator.new("category", build_attributes).template_path.should == "src/templates/views"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should append context to path" do
|
10
|
+
FreemarkerGenerator.new("myModel", build_attributes).path.should == "${base}/myModels"
|
11
|
+
end
|
12
|
+
|
13
|
+
context "simple model name" do
|
14
|
+
before(:all) do
|
15
|
+
model = "product"
|
16
|
+
@views_path = File.join Configuration::WEB_INF, "views", model
|
17
|
+
@generator = FreemarkerGenerator.new(model, build_attributes)
|
18
|
+
@generator.build
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:all) do
|
22
|
+
FileUtils.remove_dir("src")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create index view" do
|
26
|
+
File.exist?("#{@views_path}/index.ftl").should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should create show view" do
|
30
|
+
File.exist?("#{@views_path}/show.ftl").should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create form view" do
|
34
|
+
File.exist?("#{@views_path}/form.ftl").should be_true
|
35
|
+
source = File.join File.dirname(__FILE__), "templates", "form.ftl"
|
36
|
+
destination = "#{Configuration::WEB_INF}/views/product/form.ftl"
|
37
|
+
exists_and_identical?(source, destination)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should create new view" do
|
41
|
+
File.exist?("#{@views_path}/newProduct.ftl").should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create edit view" do
|
45
|
+
File.exist?("#{@views_path}/edit.ftl").should be_true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "compound model name" do
|
50
|
+
before(:all) do
|
51
|
+
model = "OrderItem"
|
52
|
+
@views_path = File.join Configuration::WEB_INF, "views", "orderItem"
|
53
|
+
@generator = FreemarkerGenerator.new(model, build_attributes)
|
54
|
+
@generator.build
|
55
|
+
end
|
56
|
+
|
57
|
+
after(:all) do
|
58
|
+
FileUtils.remove_dir("src")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should create index view" do
|
62
|
+
File.exist?("#{@views_path}/index.ftl").should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should create show view" do
|
66
|
+
File.exist?("#{@views_path}/show.ftl").should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should create form view" do
|
70
|
+
File.exist?("#{@views_path}/form.ftl").should be_true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should create new view" do
|
74
|
+
File.exist?("#{@views_path}/newOrderItem.ftl").should be_true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should create edit view" do
|
78
|
+
File.exist?("#{@views_path}/edit.ftl").should be_true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<#if errors??>
|
2
|
+
<#list errors as error>
|
3
|
+
${error.category} - ${error.message}<br />
|
4
|
+
</#list>
|
5
|
+
</#if>
|
6
|
+
|
7
|
+
<form action="${base}/products" method="post">
|
8
|
+
|
9
|
+
<#if product.id??>
|
10
|
+
<input type="hidden" name="product.id" value="${product.id}"/>
|
11
|
+
<input type="hidden" name="_method" value="put"/>
|
12
|
+
</#if>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
Name:<br />
|
16
|
+
<@html.text "product.name" product.name/>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
My flag:<br />
|
20
|
+
<@html.checkbox "product.myFlag" product.myFlag/>
|
21
|
+
</div>
|
22
|
+
<div class="actions">
|
23
|
+
<button type="submit">send</button>
|
24
|
+
</div>
|
25
|
+
</form>
|
26
|
+
|
27
|
+
<a href="${base}/products">Back</a>
|
28
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
|
2
|
+
|
3
|
+
describe JspGenerator do
|
4
|
+
|
5
|
+
it "should append context to path" do
|
6
|
+
JspGenerator.new("myModel", build_attributes).path("/edit").should == "${pageContext.request.contextPath}/myModels/edit"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "jsp template path" do
|
10
|
+
JspGenerator.new("category", build_attributes).template_path.should == "src/templates/views"
|
11
|
+
end
|
12
|
+
|
13
|
+
context "simple model name" do
|
14
|
+
before(:all) do
|
15
|
+
model = "product"
|
16
|
+
@views_path = File.join Configuration::WEB_INF, "jsp", model
|
17
|
+
@generator = JspGenerator.new(model, build_attributes)
|
18
|
+
@generator.build
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:all) do
|
22
|
+
FileUtils.remove_dir("src")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create index view" do
|
26
|
+
File.exist?("#{@views_path}/index.jsp").should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should create show view" do
|
30
|
+
File.exist?("#{@views_path}/show.jsp").should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create form view" do
|
34
|
+
source = File.join File.dirname(__FILE__), "templates", "form.jsp"
|
35
|
+
destination = "#{Configuration::WEB_INF}/jsp/product/form.jsp"
|
36
|
+
exists_and_identical?(source, destination)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should create new view" do
|
40
|
+
File.exist?("#{@views_path}/newProduct.jsp").should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should create edit view" do
|
44
|
+
File.exist?("#{@views_path}/edit.jsp").should be_true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "compound model name" do
|
49
|
+
before(:all) do
|
50
|
+
model = "OrderItem"
|
51
|
+
@views_path = File.join Configuration::WEB_INF, "jsp", "orderItem"
|
52
|
+
@generator = JspGenerator.new(model, build_attributes)
|
53
|
+
@generator.build
|
54
|
+
end
|
55
|
+
|
56
|
+
after(:all) do
|
57
|
+
FileUtils.remove_dir("src")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should create index view" do
|
61
|
+
File.exist?("#{@views_path}/index.jsp").should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should create show view" do
|
65
|
+
File.exist?("#{@views_path}/show.jsp").should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should create form view" do
|
69
|
+
File.exist?("#{@views_path}/form.jsp").should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should create new view" do
|
73
|
+
File.exist?("#{@views_path}/newOrderItem.jsp").should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should create edit view" do
|
77
|
+
File.exist?("#{@views_path}/edit.jsp").should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|