heroku-vraptor-scaffold 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +6 -0
  3. data/CHANGELOG.rdoc +188 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +30 -0
  6. data/LICENSE +22 -0
  7. data/README.md +23 -0
  8. data/README.textile +51 -0
  9. data/Rakefile +20 -0
  10. data/bin/heroku-vraptor +8 -0
  11. data/heroku-vraptor-scaffold.gemspec +28 -0
  12. data/index.sample.html +169 -0
  13. data/lib/vraptor-scaffold.rb +14 -0
  14. data/lib/vraptor-scaffold/configuration.rb +54 -0
  15. data/lib/vraptor-scaffold/execution.rb +22 -0
  16. data/lib/vraptor-scaffold/generators/app/app_generator.rb +161 -0
  17. data/lib/vraptor-scaffold/generators/app/dependency.rb +15 -0
  18. data/lib/vraptor-scaffold/generators/app/dependency_manager.rb +32 -0
  19. data/lib/vraptor-scaffold/generators/app/templates/angular/angular.js +14327 -0
  20. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap-responsive.css +9 -0
  21. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.css +9 -0
  22. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/bootstrap.js +6 -0
  23. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings-white.png +0 -0
  24. data/lib/vraptor-scaffold/generators/app/templates/bootstrap/glyphicons-halflings.png +0 -0
  25. data/lib/vraptor-scaffold/generators/app/templates/eclipse/classpath.erb +18 -0
  26. data/lib/vraptor-scaffold/generators/app/templates/eclipse/project.erb +36 -0
  27. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.jdt.core.prefs +8 -0
  28. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.component.tt +10 -0
  29. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.common.project.facet.core.xml +10 -0
  30. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.container +1 -0
  31. data/lib/vraptor-scaffold/generators/app/templates/eclipse/settings/org.eclipse.wst.jsdt.ui.superType.name +1 -0
  32. data/lib/vraptor-scaffold/generators/app/templates/heroku/Main.java +21 -0
  33. data/lib/vraptor-scaffold/generators/app/templates/heroku/Procfile +1 -0
  34. data/lib/vraptor-scaffold/generators/app/templates/jquery/jquery.min.js +4 -0
  35. data/lib/vraptor-scaffold/generators/app/templates/models/Entity.erb +46 -0
  36. data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-hibernate.java.tt +50 -0
  37. data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-jpa.java.tt +48 -0
  38. data/lib/vraptor-scaffold/generators/app/templates/orm/Repository-objectify.java.tt +41 -0
  39. data/lib/vraptor-scaffold/generators/app/templates/orm/hibernate.cfg.xml +7 -0
  40. data/lib/vraptor-scaffold/generators/app/templates/orm/persistence.xml +10 -0
  41. data/lib/vraptor-scaffold/generators/app/templates/pom.erb +110 -0
  42. data/lib/vraptor-scaffold/generators/app/templates/resources-test/.empty_directory +0 -0
  43. data/lib/vraptor-scaffold/generators/app/templates/resources/hibernate.properties +16 -0
  44. data/lib/vraptor-scaffold/generators/app/templates/resources/log4j.properties +4 -0
  45. data/lib/vraptor-scaffold/generators/app/templates/resources/messages.properties +0 -0
  46. data/lib/vraptor-scaffold/generators/app/templates/underscore/underscore.min.js +32 -0
  47. data/lib/vraptor-scaffold/generators/app/templates/vraptor-scaffold.erb +5 -0
  48. data/lib/vraptor-scaffold/generators/app/templates/webapp/WEB-INF/web.xml.tt +33 -0
  49. data/lib/vraptor-scaffold/generators/app/templates/webapp/images/.empty_directory +0 -0
  50. data/lib/vraptor-scaffold/generators/app/templates/webapp/index.html +24 -0
  51. data/lib/vraptor-scaffold/generators/app/templates/webapp/javascripts/utils.js +7 -0
  52. data/lib/vraptor-scaffold/generators/base.rb +16 -0
  53. data/lib/vraptor-scaffold/generators/scaffold/attribute.rb +51 -0
  54. data/lib/vraptor-scaffold/generators/scaffold/base_scaffold.rb +54 -0
  55. data/lib/vraptor-scaffold/generators/scaffold/client_generator/client_generator.rb +41 -0
  56. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/controller.erb +75 -0
  57. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/details.erb +16 -0
  58. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/form.erb +39 -0
  59. data/lib/vraptor-scaffold/generators/scaffold/client_generator/templates/list.erb +40 -0
  60. data/lib/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator.rb +20 -0
  61. data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller.erb +77 -0
  62. data/lib/vraptor-scaffold/generators/scaffold/controller_generator/templates/controller_test.erb +12 -0
  63. data/lib/vraptor-scaffold/generators/scaffold/model_generator/model_generator.rb +26 -0
  64. data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model.erb +32 -0
  65. data/lib/vraptor-scaffold/generators/scaffold/model_generator/templates/model_test.erb +13 -0
  66. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator.rb +32 -0
  67. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository.erb +22 -0
  68. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_impl.erb +16 -0
  69. data/lib/vraptor-scaffold/generators/scaffold/repository_generator/templates/repository_test.erb +13 -0
  70. data/lib/vraptor-scaffold/generators/scaffold/scaffold_generator.rb +35 -0
  71. data/lib/vraptor-scaffold/runner.rb +9 -0
  72. data/lib/vraptor-scaffold/runner/commands_help.rb +13 -0
  73. data/lib/vraptor-scaffold/runner/generator.rb +15 -0
  74. data/lib/vraptor-scaffold/runner/help.rb +12 -0
  75. data/lib/vraptor-scaffold/runner/scaffold.rb +16 -0
  76. data/lib/vraptor-scaffold/version.rb +3 -0
  77. data/maven/repo/br/com/caelum/vraptor-gae/1.0/vraptor-gae-1.0.jar +0 -0
  78. data/spec/resources/vraptor-scaffold-objectify.properties +7 -0
  79. data/spec/resources/vraptor-scaffold.properties +7 -0
  80. data/spec/spec.opts +4 -0
  81. data/spec/spec_helper.rb +31 -0
  82. data/spec/vraptor-scaffold/configuration_spec.rb +146 -0
  83. data/spec/vraptor-scaffold/execution_spec.rb +51 -0
  84. data/spec/vraptor-scaffold/generators/app/app_generator_spec.rb +557 -0
  85. data/spec/vraptor-scaffold/generators/app/dependency_manager_spec.rb +34 -0
  86. data/spec/vraptor-scaffold/generators/app/dependency_spec.rb +14 -0
  87. data/spec/vraptor-scaffold/generators/app/freemarker_template_engine_spec.rb +80 -0
  88. data/spec/vraptor-scaffold/generators/app/jsp_template_engine_spec.rb +77 -0
  89. data/spec/vraptor-scaffold/generators/app/templates/Entity.java +45 -0
  90. data/spec/vraptor-scaffold/generators/app/templates/FreemarkerPathResolver.java +21 -0
  91. data/spec/vraptor-scaffold/generators/app/templates/ObjectifyFactory.java +30 -0
  92. data/spec/vraptor-scaffold/generators/app/templates/RepositoryJPA.java +48 -0
  93. data/spec/vraptor-scaffold/generators/app/templates/RepositoryObjectify.java +41 -0
  94. data/spec/vraptor-scaffold/generators/app/templates/build.gradle +60 -0
  95. data/spec/vraptor-scaffold/generators/app/templates/build.properties +18 -0
  96. data/spec/vraptor-scaffold/generators/app/templates/build.xml +146 -0
  97. data/spec/vraptor-scaffold/generators/app/templates/classpath-gae +18 -0
  98. data/spec/vraptor-scaffold/generators/app/templates/decorators-jsp.xml +7 -0
  99. data/spec/vraptor-scaffold/generators/app/templates/decorators.xml +7 -0
  100. data/spec/vraptor-scaffold/generators/app/templates/freemarker-web.xml +60 -0
  101. data/spec/vraptor-scaffold/generators/app/templates/gae-jsp-web.xml +45 -0
  102. data/spec/vraptor-scaffold/generators/app/templates/ivy-gae.xml +45 -0
  103. data/spec/vraptor-scaffold/generators/app/templates/ivy.xml +40 -0
  104. data/spec/vraptor-scaffold/generators/app/templates/jsp-web.xml +45 -0
  105. data/spec/vraptor-scaffold/generators/app/templates/pom-heroku.xml +182 -0
  106. data/spec/vraptor-scaffold/generators/app/templates/pom.xml +157 -0
  107. data/spec/vraptor-scaffold/generators/app/templates/project-gae +47 -0
  108. data/spec/vraptor-scaffold/generators/app/templates/vraptor-scaffold.properties +7 -0
  109. data/spec/vraptor-scaffold/generators/plugin/expected_configs/build.gradle +62 -0
  110. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_build.gradle +62 -0
  111. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_ivy.xml +41 -0
  112. data/spec/vraptor-scaffold/generators/plugin/expected_configs/default_org_pom.xml +152 -0
  113. data/spec/vraptor-scaffold/generators/plugin/expected_configs/ivy.xml +42 -0
  114. data/spec/vraptor-scaffold/generators/plugin/expected_configs/pom.xml +182 -0
  115. data/spec/vraptor-scaffold/generators/scaffold/attribute_spec.rb +186 -0
  116. data/spec/vraptor-scaffold/generators/scaffold/base_scaffold_spec.rb +73 -0
  117. data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/controller_generator_spec.rb +62 -0
  118. data/spec/vraptor-scaffold/generators/scaffold/client_controller_generator/templates/ProductController.java +95 -0
  119. data/spec/vraptor-scaffold/generators/scaffold/controller_generator/controller_generator_spec.rb +62 -0
  120. data/spec/vraptor-scaffold/generators/scaffold/controller_generator/templates/ProductController.java +95 -0
  121. data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/freemarker_generator_spec.rb +81 -0
  122. data/spec/vraptor-scaffold/generators/scaffold/freemarker_generator/templates/form.ftl +28 -0
  123. data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/jsp_generator_spec.rb +81 -0
  124. data/spec/vraptor-scaffold/generators/scaffold/jsp_generator/templates/form.jsp +61 -0
  125. data/spec/vraptor-scaffold/generators/scaffold/model_generator/model_generator_spec.rb +54 -0
  126. data/spec/vraptor-scaffold/generators/scaffold/model_generator/objectify_model_generator_spec.rb +40 -0
  127. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/ObjectifyFactory.java +33 -0
  128. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Objectify_Product.java +38 -0
  129. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/Product.java +25 -0
  130. data/spec/vraptor-scaffold/generators/scaffold/model_generator/templates/hibernate.cfg.xml +8 -0
  131. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/objectify_repository_generator_spec.rb +33 -0
  132. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/repository_generator_spec.rb +68 -0
  133. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepository.java +22 -0
  134. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ClientRepositoryImpl.java +16 -0
  135. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepository.java +22 -0
  136. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/Objectify_ProductRepositoryImpl.java +16 -0
  137. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepository.java +22 -0
  138. data/spec/vraptor-scaffold/generators/scaffold/repository_generator/templates/ProductRepositoryImpl.java +16 -0
  139. data/spec/vraptor-scaffold/generators/scaffold/scaffold_generator_spec.rb +79 -0
  140. data/spec/vraptor-scaffold/http_request_spec.rb +40 -0
  141. data/spec/vraptor-scaffold/runner/commands_help_spec.rb +12 -0
  142. data/spec/vraptor-scaffold/runner/configure_spec.rb +12 -0
  143. data/spec/vraptor-scaffold/runner/generator_spec.rb +31 -0
  144. data/spec/vraptor-scaffold/runner/help_spec.rb +29 -0
  145. data/spec/vraptor-scaffold/runner/scaffold_spec.rb +35 -0
  146. data/spec/vraptor-scaffold/runner/start_spec.rb +51 -0
  147. data/spec/vraptor-scaffold_spec.rb +4 -0
  148. 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
+ }
@@ -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.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
+ }
@@ -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