springmvc-scaffold 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +45 -0
  6. data/README.markdown +31 -0
  7. data/Rakefile +9 -0
  8. data/bin/springmvc +7 -0
  9. data/lib/springmvc-scaffold.rb +14 -0
  10. data/lib/springmvc-scaffold/configuration.rb +50 -0
  11. data/lib/springmvc-scaffold/execution.rb +20 -0
  12. data/lib/springmvc-scaffold/generators/app/app_generator.rb +123 -0
  13. data/lib/springmvc-scaffold/generators/app/dependencies.rb +26 -0
  14. data/lib/springmvc-scaffold/generators/app/dependency.rb +15 -0
  15. data/lib/springmvc-scaffold/generators/app/templates/build.gradle.erb +56 -0
  16. data/lib/springmvc-scaffold/generators/app/templates/models/Entity.erb +46 -0
  17. data/lib/springmvc-scaffold/generators/app/templates/orm/Repository-hibernate.java.tt +51 -0
  18. data/lib/springmvc-scaffold/generators/app/templates/orm/Repository-jpa.java.tt +49 -0
  19. data/lib/springmvc-scaffold/generators/app/templates/pom.erb +95 -0
  20. data/lib/springmvc-scaffold/generators/app/templates/resources/hibernate.properties +16 -0
  21. data/lib/springmvc-scaffold/generators/app/templates/resources/log4j.properties +4 -0
  22. data/lib/springmvc-scaffold/generators/app/templates/resources/messages.properties +0 -0
  23. data/lib/springmvc-scaffold/generators/app/templates/springmvc-scaffold.erb +6 -0
  24. data/lib/springmvc-scaffold/generators/app/templates/webapp/.bowerrc +3 -0
  25. data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/jsp/decorators/main.jsp +15 -0
  26. data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/jsp/prelude.jspf +4 -0
  27. data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/sitemesh3.xml +3 -0
  28. data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/spring-servlet.xml.tt +42 -0
  29. data/lib/springmvc-scaffold/generators/app/templates/webapp/WEB-INF/web.xml.tt +52 -0
  30. data/lib/springmvc-scaffold/generators/app/templates/webapp/bower.json.tt +7 -0
  31. data/lib/springmvc-scaffold/generators/app/templates/webapp/stylesheets/application.css +38 -0
  32. data/lib/springmvc-scaffold/generators/base.rb +17 -0
  33. data/lib/springmvc-scaffold/generators/scaffold/attribute.rb +68 -0
  34. data/lib/springmvc-scaffold/generators/scaffold/base_scaffold.rb +54 -0
  35. data/lib/springmvc-scaffold/generators/scaffold/controller/controller_generator.rb +20 -0
  36. data/lib/springmvc-scaffold/generators/scaffold/controller/templates/controller.erb +126 -0
  37. data/lib/springmvc-scaffold/generators/scaffold/controller/templates/controller_test.erb +13 -0
  38. data/lib/springmvc-scaffold/generators/scaffold/imports.rb +18 -0
  39. data/lib/springmvc-scaffold/generators/scaffold/jsp/jsp_generator.rb +40 -0
  40. data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/edit.erb +15 -0
  41. data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/form.erb +14 -0
  42. data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/index.erb +38 -0
  43. data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/new.erb +14 -0
  44. data/lib/springmvc-scaffold/generators/scaffold/jsp/templates/show.erb +16 -0
  45. data/lib/springmvc-scaffold/generators/scaffold/model/model_generator.rb +16 -0
  46. data/lib/springmvc-scaffold/generators/scaffold/model/templates/model.erb +22 -0
  47. data/lib/springmvc-scaffold/generators/scaffold/model/templates/model_test.erb +13 -0
  48. data/lib/springmvc-scaffold/generators/scaffold/repository/repository_generator.rb +30 -0
  49. data/lib/springmvc-scaffold/generators/scaffold/repository/templates/repository.erb +18 -0
  50. data/lib/springmvc-scaffold/generators/scaffold/repository/templates/repository_test.erb +13 -0
  51. data/lib/springmvc-scaffold/generators/scaffold/scaffold_generator.rb +31 -0
  52. data/lib/springmvc-scaffold/runner.rb +7 -0
  53. data/lib/springmvc-scaffold/runner/commands_help.rb +11 -0
  54. data/lib/springmvc-scaffold/runner/generator.rb +14 -0
  55. data/lib/springmvc-scaffold/runner/help.rb +10 -0
  56. data/lib/springmvc-scaffold/runner/scaffold.rb +15 -0
  57. data/lib/springmvc-scaffold/version.rb +3 -0
  58. data/spec/spec_helper.rb +23 -0
  59. data/spec/springmvc-scaffold/configuration_spec.rb +124 -0
  60. data/spec/springmvc-scaffold/execution_spec.rb +40 -0
  61. data/spec/springmvc-scaffold/generators/app/app_generator_spec.rb +226 -0
  62. data/spec/springmvc-scaffold/generators/app/dependency_spec.rb +14 -0
  63. data/spec/springmvc-scaffold/generators/app/templates/Entity.java +46 -0
  64. data/spec/springmvc-scaffold/generators/app/templates/RepositoryJPA.java +49 -0
  65. data/spec/springmvc-scaffold/generators/app/templates/build.gradle +59 -0
  66. data/spec/springmvc-scaffold/generators/app/templates/pom.xml +146 -0
  67. data/spec/springmvc-scaffold/generators/app/templates/springmvc-scaffold.properties +6 -0
  68. data/spec/springmvc-scaffold/generators/scaffold/attribute_spec.rb +215 -0
  69. data/spec/springmvc-scaffold/generators/scaffold/base_scaffold_spec.rb +70 -0
  70. data/spec/springmvc-scaffold/generators/scaffold/controller/controller_generator_spec.rb +53 -0
  71. data/spec/springmvc-scaffold/generators/scaffold/controller/templates/ProductsController.java +97 -0
  72. data/spec/springmvc-scaffold/generators/scaffold/imports_spec.rb +9 -0
  73. data/spec/springmvc-scaffold/generators/scaffold/jsp/jsp_generator_spec.rb +46 -0
  74. data/spec/springmvc-scaffold/generators/scaffold/jsp/templates/form.jsp +25 -0
  75. data/spec/springmvc-scaffold/generators/scaffold/model/model_generator_spec.rb +28 -0
  76. data/spec/springmvc-scaffold/generators/scaffold/model/templates/Product.java +43 -0
  77. data/spec/springmvc-scaffold/generators/scaffold/repository/repository_generator_spec.rb +49 -0
  78. data/spec/springmvc-scaffold/generators/scaffold/repository/templates/Clients.java +16 -0
  79. data/spec/springmvc-scaffold/generators/scaffold/repository/templates/Products.java +10 -0
  80. data/spec/springmvc-scaffold/generators/scaffold/scaffold_generator_spec.rb +60 -0
  81. data/spec/springmvc-scaffold/runner/commands_help_spec.rb +13 -0
  82. data/spec/springmvc-scaffold/runner/generator_spec.rb +21 -0
  83. data/spec/springmvc-scaffold/runner/help_spec.rb +22 -0
  84. data/spec/springmvc-scaffold/runner/scaffold_spec.rb +36 -0
  85. data/spec/springmvc-scaffold_spec.rb +4 -0
  86. data/springmvc-scaffold.gemspec +27 -0
  87. metadata +185 -0
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
2
+
3
+ describe BaseScaffold do
4
+ subject { described_class.new("client") }
5
+
6
+ context "simple model name" do
7
+ it "knows model class name" do
8
+ expect(subject.class_name).to eq "Client"
9
+ end
10
+
11
+ it "knows model test class name" do
12
+ expect(subject.test_class_name).to eq "ClientTest"
13
+ end
14
+
15
+ it "knows repository class name" do
16
+ expect(subject.repository_class_name).to eq "Clients"
17
+ end
18
+
19
+ it "knows repository name" do
20
+ expect(subject.repository_name).to eq "clients"
21
+ end
22
+
23
+ it "knows repository test class name" do
24
+ expect(subject.repository_test_class_name).to eq "ClientsTest"
25
+ end
26
+
27
+ it "knows controller class name" do
28
+ expect(subject.controller_class_name).to eq "ClientsController"
29
+ end
30
+
31
+ it "knows controller test class name" do
32
+ expect(subject.controller_test_class_name).to eq "ClientsControllerTest"
33
+ end
34
+
35
+ it "knows path" do
36
+ expect(subject.base_path).to eq "clients"
37
+ end
38
+ end
39
+
40
+ context "compound model name" do
41
+ it "knows class name to 'orderItem'" do
42
+ expect(described_class.new('orderItem').class_name).to eq "OrderItem"
43
+ end
44
+
45
+ it "knows class name to 'OrderItem'" do
46
+ expect(described_class.new('OrderItem').class_name).to eq "OrderItem"
47
+ end
48
+
49
+ it "knows parameter name to 'OrderItem'" do
50
+ expect(described_class.new("OrderItem").model_parameter_name).to eq "orderItem"
51
+ end
52
+
53
+ it "knows parameter name to 'OrderItem'" do
54
+ expect(described_class.new("orderItem").model_parameter_name).to eq "orderItem"
55
+ end
56
+
57
+ it "knows path to 'orderItem'" do
58
+ expect(described_class.new("orderItem").base_path).to eq "orderItems"
59
+ end
60
+
61
+ it "knows path to 'OrderItem'" do
62
+ expect(described_class.new("OrderItem").base_path).to eq "orderItems"
63
+ end
64
+ end
65
+
66
+ it "do not allow duplicate import" do
67
+ base = described_class.new("product", [Attribute.new("created", "date"), Attribute.new("validity", "date")])
68
+ expect(base.imports.one?).to be true
69
+ end
70
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe ControllerGenerator do
4
+
5
+ it "controller template path" do
6
+ expect(described_class.new("category", build_attributes).template_path).to eq "src/templates/controllers"
7
+ end
8
+
9
+ context "paths" do
10
+ it "to simple model name" do
11
+ expect(described_class.new("product", build_attributes).path).to eq "/products"
12
+ end
13
+
14
+ it "to compound model name" do
15
+ expect(described_class.new("orderItem", build_attributes).path).to eq "/orderItems"
16
+ end
17
+ end
18
+
19
+ context "generating" do
20
+ before { mock_config_file }
21
+ after { FileUtils.remove_dir("src") }
22
+
23
+ context "from a lowercase name" do
24
+ before { described_class.new("product", build_attributes).build }
25
+
26
+ it "creates controller" do
27
+ source = File.join(File.dirname(__FILE__), "templates", "ProductsController.java")
28
+ destination = Configuration.main_class_path("controllers", "ProductsController.java")
29
+ exists_and_identical?(source, destination)
30
+ end
31
+
32
+ it "creates controller test" do
33
+ test_class = Configuration.test_class_path("controllers", "ProductsControllerTest.java")
34
+ expect(File.exist?(test_class)).to be true
35
+ end
36
+ end
37
+
38
+ context "from a uppercase name" do
39
+ before { described_class.new("Product", build_attributes).build }
40
+
41
+ it "creates controller" do
42
+ source = File.join(File.dirname(__FILE__), "templates", "ProductsController.java")
43
+ destination = Configuration.main_class_path("controllers", "ProductsController.java")
44
+ exists_and_identical?(source, destination)
45
+ end
46
+
47
+ it "creates controller test" do
48
+ test_class = Configuration.test_class_path "controllers", "ProductsControllerTest.java"
49
+ expect(File.exist?(test_class)).to be true
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,97 @@
1
+ package app.controllers;
2
+
3
+ import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
4
+ import static org.springframework.web.bind.annotation.RequestMethod.GET;
5
+ import static org.springframework.web.bind.annotation.RequestMethod.POST;
6
+
7
+ import javax.validation.Valid;
8
+
9
+ import org.springframework.beans.factory.annotation.Autowired;
10
+ import org.springframework.stereotype.Controller;
11
+ import org.springframework.validation.BindingResult;
12
+ import org.springframework.web.bind.annotation.PathVariable;
13
+ import org.springframework.web.bind.annotation.RequestMapping;
14
+ import org.springframework.web.servlet.ModelAndView;
15
+ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
16
+
17
+ import app.models.Product;
18
+ import app.repositories.Products;
19
+ import app.repositories.Categories;
20
+
21
+ @Controller
22
+ public class ProductsController {
23
+
24
+ private final Products products;
25
+ private final Categories categories;
26
+
27
+ @Autowired
28
+ public ProductsController(final Products products, final Categories categories) {
29
+ this.products = products;
30
+ this.categories = categories;
31
+ }
32
+
33
+ @RequestMapping(value = "/products", method = GET)
34
+ public ModelAndView index() {
35
+ return new ModelAndView("products/index", "productList", products.all());
36
+ }
37
+
38
+ @RequestMapping(value = "/products/{id}", method = GET)
39
+ public ModelAndView show(@PathVariable final Long id) {
40
+ return new ModelAndView("products/show", "product", products.get(id));
41
+ }
42
+
43
+ @RequestMapping(value = "/products/new", method = GET)
44
+ public ModelAndView newProduct() {
45
+ ModelAndView model = new ModelAndView("products/newProduct", "product", new Product());
46
+ model.addObject("categoryList", categories.all());
47
+ return model;
48
+ }
49
+
50
+ @RequestMapping(value = "/products", method = POST)
51
+ public ModelAndView create(@Valid final Product product, final BindingResult result,
52
+ final RedirectAttributes attrs) {
53
+ ModelAndView model = new ModelAndView();
54
+ if(result.hasErrors()) {
55
+ model.setViewName("products/newProduct");
56
+ model.addObject("categoryList", categories.all());
57
+ return model;
58
+ }
59
+
60
+ products.add(product);
61
+ model.setViewName("redirect:/products/{id}");
62
+ model.addObject("id", product.getId());
63
+ attrs.addFlashAttribute("message", "Product was successfully created.");
64
+ return model;
65
+ }
66
+
67
+ @RequestMapping(value = "/products/{id}/edit", method = GET)
68
+ public ModelAndView edit(@PathVariable final Long id) {
69
+ ModelAndView model = new ModelAndView("products/edit", "product", products.get(id));
70
+ model.addObject("categoryList", categories.all());
71
+ return model;
72
+ }
73
+
74
+ @RequestMapping(value = "/products/update", method = POST)
75
+ public ModelAndView update(@Valid final Product product, final BindingResult result,
76
+ final RedirectAttributes attrs) {
77
+ ModelAndView model = new ModelAndView();
78
+ if(result.hasErrors()) {
79
+ model.setViewName("products/edit");
80
+ model.addObject("categoryList", categories.all());
81
+ return model;
82
+ }
83
+
84
+ products.update(product);
85
+ model.setViewName("redirect:/products/{id}");
86
+ model.addObject("id", product.getId());
87
+ attrs.addFlashAttribute("message", "Product was successfully updated.");
88
+ return model;
89
+ }
90
+
91
+ @RequestMapping(value = "/products/{id}", method = DELETE)
92
+ public String destroy(@PathVariable final Long id, final RedirectAttributes attrs) {
93
+ products.remove(id);
94
+ attrs.addFlashAttribute("message", "Product was successfully destroyed.");
95
+ return "redirect:/products";
96
+ }
97
+ }
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
2
+
3
+ describe Imports do
4
+
5
+ it "imports package when type is Date" do
6
+ expect(Imports.new("date").package).to include("java.util.Date")
7
+ end
8
+
9
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe JspGenerator do
4
+
5
+ it "jsp template path" do
6
+ expect(described_class.new("category", build_attributes).template_path).to eq "src/templates/views"
7
+ end
8
+
9
+ it "appends context to path" do
10
+ expect(described_class.new("myModel", build_attributes).path("/edit")).to eq "${pageContext.request.contextPath}/myModels/edit"
11
+ end
12
+
13
+ context "simple model name" do
14
+ let(:model) { "category" }
15
+ let(:views_path) { File.join(Configuration::WEB_INF, "jsp", model.pluralize ) }
16
+
17
+ before do
18
+ generator = described_class.new(model, build_attributes)
19
+ generator.build
20
+ end
21
+ after { FileUtils.remove_dir("src") }
22
+
23
+ it "creates index view" do
24
+ expect(File.exist?("#{views_path}/index.jsp")).to be true
25
+ end
26
+
27
+ it "creates show view" do
28
+ expect(File.exist?("#{views_path}/show.jsp")).to be true
29
+ end
30
+
31
+ it "creates form view" do
32
+ source = File.join(File.dirname(__FILE__), "templates", "form.jsp")
33
+ destination = "#{Configuration::WEB_INF}/jsp/categories/form.jsp"
34
+ exists_and_identical?(source, destination)
35
+ end
36
+
37
+ it "creates new view" do
38
+ expect(File.exist?("#{views_path}/newCategory.jsp")).to be true
39
+ end
40
+
41
+ it "creates edit view" do
42
+ expect(File.exist?("#{views_path}/edit.jsp")).to be true
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,25 @@
1
+ <div class="field">
2
+ Name:<br />
3
+ <form:input path="name" />
4
+ <form:errors path="name" />
5
+ </div>
6
+
7
+ <div class="field">
8
+ Active:<br />
9
+ <form:checkbox path="active" />
10
+ <form:errors path="active" />
11
+ </div>
12
+
13
+ <div class="field">
14
+ Price:<br />
15
+ <form:input path="price" />
16
+ <form:errors path="price" />
17
+ </div>
18
+
19
+ <div class="field">
20
+ Category:<br />
21
+ <form:select path="category.id">
22
+ <form:options items="${categoryList}" itemValue="id" itemLabel="id"/>
23
+ </form:select>
24
+ </div>
25
+
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe ModelGenerator do
4
+
5
+ it "model template path" do
6
+ expect(described_class.new("category", build_attributes).template_path).to eq "src/templates/models"
7
+ end
8
+
9
+ context "jpa" do
10
+ before do
11
+ mock_config_file
12
+ described_class.new("product", build_attributes).build
13
+ end
14
+
15
+ after { FileUtils.remove_dir("src") }
16
+
17
+ it "creates model" do
18
+ source = File.join(File.dirname(__FILE__), "templates", "Product.java")
19
+ destination = Configuration.main_class_path("models", "Product.java")
20
+ exists_and_identical?(source, destination)
21
+ end
22
+
23
+ it "creates model test" do
24
+ test_class = Configuration.test_class_path "models", "ProductTest.java"
25
+ expect(File.exist?(test_class)).to be true
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,43 @@
1
+ package app.models;
2
+
3
+ @javax.persistence.Entity
4
+ public class Product extends Entity {
5
+
6
+ private String name;
7
+ private boolean active;
8
+ private Double price;
9
+ private Category category;
10
+
11
+ public void setName(String name) {
12
+ this.name = name;
13
+ }
14
+
15
+ public String getName() {
16
+ return name;
17
+ }
18
+
19
+ public void setActive(boolean active) {
20
+ this.active = active;
21
+ }
22
+
23
+ public boolean isActive() {
24
+ return active;
25
+ }
26
+
27
+ public void setPrice(Double price) {
28
+ this.price = price;
29
+ }
30
+
31
+ public Double getPrice() {
32
+ return price;
33
+ }
34
+
35
+ public void setCategory(Category category) {
36
+ this.category = category;
37
+ }
38
+
39
+ public Category getCategory() {
40
+ return category;
41
+ }
42
+
43
+ }
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper")
2
+
3
+ describe RepositoryGenerator do
4
+
5
+ it "repository template path" do
6
+ expect(described_class.new("category", build_attributes).template_path).to eq "src/templates/repositories"
7
+ end
8
+
9
+ context 'jpa' do
10
+ before do
11
+ mock_config_file
12
+ described_class.new("product", build_attributes).build
13
+ end
14
+
15
+ after { FileUtils.remove_dir("src") }
16
+
17
+ it "creates repository" do
18
+ source = File.join(File.dirname(__FILE__), "templates", "Products.java")
19
+ destination = Configuration.main_class_path("repositories", "Products.java")
20
+ exists_and_identical?(source, destination)
21
+ end
22
+
23
+ it "creates repository test" do
24
+ test_class = Configuration.test_class_path("repositories", "ProductsTest.java")
25
+ expect(File.exist?(test_class)).to be true
26
+ end
27
+ end
28
+
29
+ context "hibernate" do
30
+ let(:config) { {"package" => "app", "orm" => "hibernate", "repositories_package" => "repositories", "models_package" => "models"} }
31
+ before do
32
+ allow(YAML).to receive(:load_file).with(Configuration::FILENAME).and_return(config)
33
+ described_class.new("client", build_attributes).build
34
+ end
35
+
36
+ after { FileUtils.remove_dir("src") }
37
+
38
+ it "creates repository" do
39
+ source = File.join(File.dirname(__FILE__), "templates", "Clients.java")
40
+ destination = Configuration.main_class_path("repositories", "Clients.java")
41
+ exists_and_identical?(source, destination)
42
+ end
43
+
44
+ it "creates repository test" do
45
+ test_class = Configuration.test_class_path("repositories", "ClientsTest.java")
46
+ expect(File.exist?(test_class)).to be true
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ package app.repositories;
2
+
3
+ import org.hibernate.SessionFactory;
4
+ import org.springframework.beans.factory.annotation.Autowired;
5
+ import org.springframework.stereotype.Repository;
6
+
7
+ import app.models.Client;
8
+
9
+ @Repository
10
+ public class Clients extends GenericRepository<Client> {
11
+
12
+ @Autowired
13
+ public Clients(SessionFactory sessionFactory) {
14
+ super(sessionFactory);
15
+ }
16
+ }