resty-generators 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/lib/generators/resty/base.rb +33 -5
  2. data/lib/generators/resty/controller/controller_generator.rb +2 -2
  3. data/lib/generators/resty/model/model_generator.rb +1 -1
  4. data/lib/generators/resty/scaffold/scaffold_generator.rb +76 -4
  5. data/lib/generators/resty/setup/setup_generator.rb +141 -4
  6. data/lib/generators/resty/setup/templates/ActivityFactory.java +12 -0
  7. data/lib/generators/resty/setup/templates/ActivityPlace.java +25 -0
  8. data/lib/generators/resty/setup/templates/ActivityPlaceActivityMapper.java +30 -0
  9. data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java +80 -0
  10. data/lib/generators/resty/setup/templates/EntryPoint.java +75 -4
  11. data/lib/generators/resty/setup/templates/GinModule.java +40 -0
  12. data/lib/generators/resty/setup/templates/LoginActivity.java +59 -0
  13. data/lib/generators/resty/setup/templates/LoginPlace.java +20 -0
  14. data/lib/generators/resty/setup/templates/LoginView.ui.xml +18 -0
  15. data/lib/generators/resty/setup/templates/LoginViewImpl.java +21 -0
  16. data/lib/generators/resty/setup/templates/Mavenfile +7 -4
  17. data/lib/generators/resty/setup/templates/PlaceHistoryMapper.java +8 -0
  18. data/lib/generators/resty/setup/templates/RestfulPlace.java +24 -0
  19. data/lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java +71 -0
  20. data/lib/generators/resty/setup/templates/SessionRestService.java +23 -0
  21. data/lib/generators/resty/setup/templates/User.java +8 -0
  22. data/lib/generators/resty/setup/templates/authentication.rb +3 -0
  23. data/lib/generators/resty/setup/templates/empty.css +17 -0
  24. data/lib/generators/resty/setup/templates/gitignore +3 -0
  25. data/lib/generators/resty/setup/templates/group.rb +14 -0
  26. data/lib/generators/resty/setup/templates/gwt.css +17 -0
  27. data/lib/generators/resty/setup/templates/module.gwt.xml +9 -2
  28. data/lib/generators/resty/setup/templates/page.html +1 -1
  29. data/lib/generators/resty/setup/templates/session.rb +45 -0
  30. data/lib/generators/resty/setup/templates/sessions_controller.rb +29 -0
  31. data/lib/generators/resty/setup/templates/user.rb +28 -0
  32. data/lib/generators/resty/setup/templates/web.xml +50 -0
  33. data/lib/generators/resty/templates/Activity.java +140 -0
  34. data/lib/generators/resty/templates/ColumnDefinitionsImpl.java +24 -0
  35. data/lib/generators/resty/templates/Model.java +13 -7
  36. data/lib/generators/resty/templates/Place.java +27 -0
  37. data/lib/generators/resty/templates/PlaceTokenizer.java +25 -0
  38. data/lib/generators/resty/templates/{Controller.java → RestService.java} +16 -12
  39. data/lib/generators/resty/templates/View.java +35 -0
  40. data/lib/generators/resty/templates/View.ui.xml +47 -0
  41. data/lib/generators/resty/templates/ViewImpl.java +196 -0
  42. data/lib/resty-generators.rb +1 -0
  43. data/lib/resty/child_path.rb +17 -4
  44. data/lib/resty/resty_railtie.rb +4 -5
  45. metadata +70 -60
@@ -0,0 +1,3 @@
1
+ lib/
2
+ classes/
3
+ deploy/
@@ -0,0 +1,14 @@
1
+ class Group
2
+ include ActiveModel::Serializers::JSON
3
+ include ActiveModel::Serializers::Xml
4
+
5
+ attr_accessor :name
6
+
7
+ def initialize(attributes = {})
8
+ @name = attributes['name']
9
+ end
10
+
11
+ def attributes
12
+ { 'name' => name }
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ .notice
2
+ {
3
+ background-color:lightgoldenRodYellow;
4
+ border:1px solid darkgoldenrod;
5
+ color:darkgoldenrod;
6
+ margin-left:35%;
7
+ margin-right:35%;
8
+ padding-left:5%;
9
+ width:30%;
10
+ padding-right:5%;
11
+ padding-top:.5em;
12
+ padding-bottom:.5em;
13
+ overflow:auto;;
14
+ position:absolute;
15
+ top:3em;
16
+ opacity:.9;
17
+ }
@@ -1,9 +1,16 @@
1
1
  <module rename-to='<%= application_name.underscore %>'>
2
-
2
+
3
3
  <inherits name='com.google.gwt.user.User' />
4
+ <inherits name="com.google.gwt.activity.Activity"/>
5
+ <inherits name="com.google.gwt.place.Place"/>
6
+
7
+ <inherits name="com.google.gwt.inject.Inject"/>
8
+
4
9
  <inherits name="org.fusesource.restygwt.RestyGWT" />
5
10
 
6
- <entry-point class='<%= base_package %>.<%= application_name %>' />
11
+ <inherits name="de.mkristian.gwt.RailsGWT" />
12
+
13
+ <entry-point class='<%= base_package %>.<%= application_name %>EntryPoint' />
7
14
 
8
15
  <stylesheet src='../stylesheets/<%= application_name.underscore %>.css' />
9
16
 
@@ -24,6 +24,6 @@
24
24
 
25
25
  <!-- OPTIONAL: include this if you want history support -->
26
26
  <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
27
-
27
+
28
28
  </body>
29
29
  </html>
@@ -0,0 +1,45 @@
1
+ class Session
2
+ include ActiveModel::Serializers::JSON
3
+ include ActiveModel::Serializers::Xml
4
+
5
+ attr_accessor :permissions, :user
6
+
7
+ def self.create(params = {})
8
+ if Rails.application.config.respond_to? :remote_sso_url
9
+ begin
10
+ a = Authentication.create(:login => params[:login],
11
+ :password => params[:password])
12
+ result = new
13
+ user = User.new
14
+ user.login = a.login
15
+ user.name = a.name
16
+ user.groups = a.groups
17
+ result.user = user
18
+ result
19
+ rescue ActiveResource::ResourceNotFound
20
+ nil
21
+ end
22
+ else
23
+ user = User.authenticate(params[:login], params[:password])
24
+ if user
25
+ result = new
26
+ result.user = user
27
+ result
28
+ end
29
+ end
30
+ end
31
+
32
+ def idle_session_timeout
33
+ Rails.application.config.idle_session_timeout
34
+ end
35
+
36
+ def attributes
37
+ {'idle_session_timeout' => idle_session_timeout, 'permissions' => permissions, 'user' => user}
38
+ end
39
+
40
+ def id
41
+ ""
42
+ end
43
+ end
44
+ Session.include_root_in_json = false
45
+ Session
@@ -0,0 +1,29 @@
1
+ class SessionsController < ApplicationController
2
+
3
+ skip_before_filter :authorization
4
+
5
+ prepend_after_filter :reset_session, :only => :destroy
6
+
7
+ public
8
+
9
+ def create
10
+ @session = Session.create(params[:session])
11
+
12
+ if @session
13
+ current_user @session.user
14
+ @session.permissions = guard.permissions(self)
15
+
16
+ # TODO make all formats available
17
+ # TODO make html login
18
+ render :json => @session.to_json(:excludes => :groups)
19
+ else
20
+ head :not_found
21
+ end
22
+ end
23
+
24
+ def destroy
25
+ # reset session happens in the after filter which allows for
26
+ # audit log with username which happens in another after filter
27
+ head :ok
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ class User
2
+ include ActiveModel::Serializers::JSON
3
+ include ActiveModel::Serializers::Xml
4
+
5
+ attr_accessor :login, :name, :groups
6
+
7
+ def attributes
8
+ {'login' => login, 'name' => name, 'groups' => groups.collect { |g| g.attributes } }
9
+ end
10
+
11
+ def initialize(attributes = {})
12
+ @login = attributes['login']
13
+ @name = attributes['name']
14
+ @groups = (attributes['groups'] || []).collect {|g| Group.new g }
15
+ end
16
+
17
+ def self.authenticate(login, password)
18
+ if login.size > 0 && password == "behappy"
19
+ u = User.new
20
+ u.login = login
21
+ u.name = login.humanize
22
+ u.groups = [Group.new('name' => login)]
23
+ u
24
+ end
25
+ end
26
+ end
27
+ User.include_root_in_json = false
28
+ User
@@ -0,0 +1,50 @@
1
+ <!DOCTYPE web-app PUBLIC
2
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
4
+ <web-app>
5
+ <welcome-file-list>
6
+ <welcome-file>/<%= application_name %>/<%= application_name %>.html</welcome-file>
7
+ </welcome-file-list>
8
+
9
+ <context-param>
10
+ <param-name>jruby.max.runtimes</param-name>
11
+ <param-value>1</param-value>
12
+ </context-param>
13
+ <context-param>
14
+ <param-name>jruby.min.runtimes</param-name>
15
+ <param-value>1</param-value>
16
+ </context-param>
17
+ <context-param>
18
+ <param-name>rails.root</param-name>
19
+ <param-value>.</param-value>
20
+ </context-param>
21
+ <context-param>
22
+ <param-name>gem.path</param-name>
23
+ <param-value>./target/rubygems</param-value>
24
+ </context-param>
25
+ <context-param>
26
+ <param-name>rails.env</param-name>
27
+ <param-value>development</param-value>
28
+ </context-param>
29
+ <context-param>
30
+ <param-name>jruby.rack.logging</param-name>
31
+ <param-value>stdout</param-value>
32
+ </context-param>
33
+ <context-param>
34
+ <param-name>jruby.rack.layout_class</param-name>
35
+ <param-value>JRuby::Rack::RailsFilesystemLayout</param-value>
36
+ </context-param>
37
+
38
+ <filter>
39
+ <filter-name>RackFilter</filter-name>
40
+ <filter-class>org.jruby.rack.RackFilter</filter-class>
41
+ </filter>
42
+ <filter-mapping>
43
+ <filter-name>RackFilter</filter-name>
44
+ <url-pattern>/*</url-pattern>
45
+ </filter-mapping>
46
+
47
+ <listener>
48
+ <listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
49
+ </listener>
50
+ </web-app>
@@ -0,0 +1,140 @@
1
+ package <%= activities_package %>;
2
+
3
+
4
+ import <%= models_package %>.<%= class_name %>;
5
+ import <%= places_package %>.<%= class_name %>Place;
6
+ import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
7
+ import <%= views_package %>.<%= class_name %>View;
8
+
9
+ import <%= gwt_rails_package %>.Notice;
10
+ import <%= gwt_rails_package %>.RestfulActionEnum;
11
+
12
+ import org.fusesource.restygwt.client.Method;
13
+ import org.fusesource.restygwt.client.MethodCallback;
14
+
15
+ import com.google.gwt.activity.shared.AbstractActivity;
16
+ import com.google.gwt.event.shared.EventBus;
17
+ import com.google.gwt.place.shared.Place;
18
+ import com.google.gwt.place.shared.PlaceController;
19
+ import com.google.gwt.user.client.ui.AcceptsOneWidget;
20
+ import com.google.inject.Inject;
21
+ import com.google.inject.assistedinject.Assisted;
22
+
23
+ public class <%= class_name %>Activity extends AbstractActivity implements <%= class_name %>View.Presenter{
24
+
25
+ private final <%= class_name %>Place place;
26
+ private final <%= class_name.pluralize %>RestService service;
27
+ private final Notice notice;
28
+ private final PlaceController placeController;
29
+ private final <%= class_name %>View view;
30
+
31
+ @Inject
32
+ public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, Notice notice, <%= class_name %>View view,
33
+ <%= class_name.pluralize %>RestService service, PlaceController placeController) {
34
+ this.place = place;
35
+ this.notice = notice;
36
+ this.view = view;
37
+ this.service = service;
38
+ this.placeController = placeController;
39
+ }
40
+
41
+ public void start(AcceptsOneWidget display, EventBus eventBus) {
42
+ display.setWidget(view.asWidget());
43
+ view.setPresenter(this);
44
+ <% if options[:singleton] -%>
45
+ load();
46
+ <% else -%>
47
+ switch(RestfulActionEnum.valueOf(place.action.name())){
48
+ case EDIT:
49
+ case SHOW:
50
+ load(place.id);
51
+ break;
52
+ case INDEX:
53
+ //TODO
54
+ default:
55
+ case NEW:
56
+ notice.setText(null);
57
+ view.reset(new <%= class_name %>());
58
+ break;
59
+ }
60
+ <% end -%>
61
+ view.reset(place.action);
62
+ }
63
+
64
+ public void goTo(Place place) {
65
+ placeController.goTo(place);
66
+ }
67
+
68
+ public void load(<% unless options[:singleton] -%>int id<% end -%>) {
69
+ view.setEnabled(false);
70
+ service.show(<% unless options[:singleton] -%>id, <% end -%>new MethodCallback<<%= class_name %>>() {
71
+
72
+ public void onFailure(Method method, Throwable exception) {
73
+ notice.setText("error loading <%= class_name.humanize %>: "
74
+ + exception.getMessage());
75
+ }
76
+
77
+ public void onSuccess(Method method, <%= class_name %> response) {
78
+ view.reset(response);
79
+ notice.setText(null);
80
+ view.reset(place.action);
81
+ }
82
+ });
83
+ if(!notice.isVisible()){
84
+ notice.setText("loading <%= class_name.humanize %> . . .");
85
+ }
86
+ }
87
+ <% unless options[:singleton] -%>
88
+ public void create() {
89
+ <%= class_name %> model = view.retrieve<%= class_name %>();
90
+ view.setEnabled(false);
91
+ service.create(model, new MethodCallback<<%= class_name %>>() {
92
+
93
+ public void onFailure(Method method, Throwable exception) {
94
+ notice.setText("error creating <%= class_name.humanize %>: "
95
+ + exception.getMessage());
96
+ }
97
+
98
+ public void onSuccess(Method method, <%= class_name %> response) {
99
+ goTo(new <%= class_name %>Place(response.id,
100
+ RestfulActionEnum.EDIT));
101
+ }
102
+ });
103
+ notice.setText("creating <%= class_name.humanize %> . . .");
104
+ }
105
+
106
+ public void delete() {
107
+ <%= class_name %> model = view.retrieve<%= class_name %>();
108
+ view.setEnabled(false);
109
+ service.destroy(model, new MethodCallback<Void>() {
110
+
111
+ public void onFailure(Method method, Throwable exception) {
112
+ notice.setText("error deleting <%= class_name.humanize %>: "
113
+ + exception.getMessage());
114
+ }
115
+
116
+ public void onSuccess(Method method, Void response) {
117
+ goTo(new <%= class_name %>Place(RestfulActionEnum.INDEX));
118
+ }
119
+ });
120
+ notice.setText("deleting <%= class_name.humanize %> . . .");
121
+ }
122
+ <% end -%>
123
+ public void save() {
124
+ <%= class_name %> model = view.retrieve<%= class_name %>();
125
+ view.setEnabled(false);
126
+ service.update(model, new MethodCallback<<%= class_name %>>() {
127
+
128
+ public void onFailure(Method method, Throwable exception) {
129
+ notice.setText("error loading <%= class_name.humanize %>: "
130
+ + exception.getMessage());
131
+ }
132
+
133
+ public void onSuccess(Method method, <%= class_name %> response) {
134
+ goTo(new <%= class_name %>Place(<% unless options[:singleton] -%>response.id,
135
+ <% end -%>RestfulActionEnum.EDIT));
136
+ }
137
+ });
138
+ notice.setText("saving <%= class_name.humanize %> . . .");
139
+ }
140
+ }
@@ -0,0 +1,24 @@
1
+ package <%= views_package %>;
2
+
3
+ import java.util.ArrayList;
4
+
5
+ import <%= gwt_rails_package %>.ColumnDefinition;
6
+ import <%= models_package %>.<%= class_name %>;
7
+
8
+ @SuppressWarnings("serial")
9
+ public class <%= class_name.pluralize %>ColumnDefinitionsImpl extends
10
+ ArrayList<ColumnDefinition<<%= class_name %>>> {
11
+
12
+ protected <%= class_name.pluralize %>ColumnDefinitionsImpl() {
13
+
14
+ this.add(new ColumnDefinition<<%= class_name %>>() {
15
+ public void render(<%= class_name %> c, StringBuilder sb) {
16
+ sb.append("<div id='" + c.id + "'>" + "TODO" + "</div>");
17
+ }
18
+
19
+ public boolean isClickable() {
20
+ return true;
21
+ }
22
+ });
23
+ }
24
+ }
@@ -1,23 +1,29 @@
1
- package <%= models_base_package %>;
1
+ package <%= models_package %>;
2
+
3
+ <% if options[:timestamps] %>
4
+ import java.util.Date;
5
+ <% end -%>
2
6
 
3
7
  public class <%= class_name %> {
4
8
 
9
+ <% unless options[:singleton] -%>
10
+ public int id;
11
+
12
+ <% end -%>
5
13
  <% for attribute in attributes -%>
6
14
  <% if attribute.type == :has_one -%>
7
15
  <%= attribute.name.classify %> <%= attribute.name %>;
8
16
  <% elsif attribute.type == :has_many -%>
9
17
  public java.util.List<<%= attribute.name.classify %>> <%= attribute.name %>;
10
18
  <% else -%>
11
- public <%= type_map[attribute.type] || attribute.type.to_s.classify %> <%= attribute.name.classify.sub(/^(.)/){ $1.downcase } %>;
19
+ public <%= type_map[attribute.type] || attribute.type.to_s.classify %> <%= attribute.name.classify.underscore.sub(/^(.)/){ $1 } %>;
12
20
  <% end -%>
13
-
14
21
  <% end -%>
15
22
  <% if options[:timestamps] %>
16
- //TODO timestamps
17
-
23
+ public Date created_at;
24
+ public Date updated_at;
18
25
  <% end -%>
19
26
  <% if options[:modified_by] %>
20
- //TODO modified_by
21
-
27
+ public options[:modified_by].classify.underscore modified_by
22
28
  <% end -%>
23
29
  }
@@ -0,0 +1,27 @@
1
+ package <%= places_package %>;
2
+
3
+ import <%= gwt_rails_package %>.RestfulAction;
4
+
5
+ import <%= managed_package %>.ActivityFactory;
6
+ import <%= base_package %>.ActivityPlace;
7
+
8
+ import com.google.gwt.activity.shared.Activity;
9
+
10
+ public class <%= class_name %>Place extends ActivityPlace {
11
+
12
+ public Activity create(ActivityFactory factory){
13
+ return factory.create(this);
14
+ }
15
+
16
+ public <%= class_name %>Place(RestfulAction restfulAction) {
17
+ super(restfulAction);
18
+ }
19
+
20
+ public <%= class_name %>Place(int id, RestfulAction restfulAction) {
21
+ super(id, restfulAction);
22
+ }
23
+
24
+ public <%= class_name %>Place(String id, RestfulAction restfulAction) {
25
+ super(id, restfulAction);
26
+ }
27
+ }