Permalink
Browse files

second import

  • Loading branch information...
1 parent e59f82e commit 3b393436eb2401b4794913f4e23854f679f91278 @mkristian committed Feb 28, 2011
Showing with 212 additions and 136 deletions.
  1. +2 −0 .gitignore
  2. +39 −37 resty-generators/lib/generators/resty/base.rb
  3. +10 −8 resty-generators/lib/generators/resty/controller/controller_generator.rb
  4. +0 −29 resty-generators/lib/generators/resty/gwt/gwt_generator.rb
  5. +13 −8 resty-generators/lib/generators/resty/model/model_generator.rb
  6. +29 −15 resty-generators/lib/generators/resty/scaffold/scaffold_generator.rb
  7. +37 −0 resty-generators/lib/generators/resty/setup/setup_generator.rb
  8. 0 resty-generators/lib/generators/resty/{templates/entry_point.java → setup/templates/EntryPoint.java}
  9. +1 −0 resty-generators/lib/generators/resty/{templates/maven.rb → setup/templates/Mavenfile}
  10. +3 −0 resty-generators/lib/generators/resty/setup/templates/initializer.rb
  11. 0 resty-generators/lib/generators/resty/{ → setup}/templates/module.gwt.xml
  12. +12 −12 resty-generators/lib/generators/resty/templates/{controller.java → Controller.java}
  13. +23 −0 resty-generators/lib/generators/resty/templates/Model.java
  14. +0 −13 resty-generators/lib/generators/resty/templates/model.java
  15. +12 −0 resty-generators/lib/generators/trash/model/model_generator.rb
  16. +4 −4 resty-generators/lib/generators/{resty → trash/rails}/templates/controller.rb
  17. 0 resty-generators/lib/generators/{ → trash}/scaffold/scaffold_generator.rb
  18. +7 −8 resty-generators/lib/generators/{resty → trash}/scaffold_controller/scaffold_controller_generator.rb
  19. +18 −0 resty-generators/lib/resty/child_path.rb
  20. +1 −1 resty-generators/lib/resty/resty_railtie.rb
  21. +1 −1 resty-generators/resty-generators.gemspec.pom
View
@@ -0,0 +1,2 @@
+target
+*~
@@ -1,52 +1,54 @@
-require 'rails/generators/resource_helpers'
+require 'rails/generators/named_base'
module Resty
- class Base < Rails::Generators::NamedBase
+ module Generators
+ class Base < Rails::Generators::NamedBase
- protected
+ protected
- def application_name
- @application_name ||= Rails.application.class.to_s.gsub(/::/,'').sub(/Application$/, '')
- end
+ def application_name
+ @application_name ||= Rails.application.class.to_s.gsub(/::/,'').sub(/Application$/, '')
+ end
- def java_root
- @java_root ||= File.join('src', 'main', 'java')
- end
+ def java_root
+ @java_root ||= File.join('src', 'main', 'java')
+ end
- def base_package
- @base_package ||=
- begin
- fullpath = find_gwt_xml(java_root)
- raise "no gwt module found" unless fullpath
- fullpath.sub(/#{java_root}./, '').sub(/.gwt.xml$/, '').gsub(/[\/\\]/, '.') + ".client"
- end
- end
+ def base_package
+ @base_package ||=
+ begin
+ fullpath = find_gwt_xml(java_root)
+ raise "no gwt module found - maybe run 'rails g resty:setup'" unless fullpath
+ fullpath.sub(/#{java_root}./, '').sub(/[a-zA-Z0-9_]+.gwt.xml$/, '').gsub(/[\/\\]/, '.') + "client"
+ end
+ end
- def models_base_package
- @models_base_package ||= base_package + ".models"
- end
+ def models_base_package
+ @models_base_package ||= base_package + ".models"
+ end
- def controllers_base_package
- @controllers_base_package ||= base_package + ".controllers"
- end
+ def controllers_base_package
+ @controllers_base_package ||= base_package + ".controllers"
+ end
- def action_map
- @action_map ||= {'index' => :get_all, 'show' => :get_single, 'create' => :post, 'update' => :put, 'destroy' => :delete}
- end
+ def action_map
+ @action_map ||= {'index' => :get_all, 'show' => :get_single, 'create' => :post, 'update' => :put, 'destroy' => :delete}
+ end
- def type_map
- @type_map ||= {:integer => 'int', :boolean => 'bool', :string => 'String', :float => 'Double', :date => 'java.util.Date', :datetime => 'java.util.Date', :number => 'long', :fixnum => 'long'}
- end
+ def type_map
+ @type_map ||= {:integer => 'int', :boolean => 'bool', :string => 'String', :float => 'Double', :date => 'java.util.Date', :datetime => 'java.util.Date', :number => 'long', :fixnum => 'long'}
+ end
- def find_gwt_xml(basedir)
- Dir[File.join(basedir, "*")].each do |path|
- if File.directory?(path)
- result = find_gwt_xml(path)
- return result if result
- elsif File.file?(path)
- return path if path =~ /.gwt.xml$/
+ def find_gwt_xml(basedir)
+ Dir[File.join(basedir, "*")].each do |path|
+ if File.directory?(path)
+ result = find_gwt_xml(path)
+ return result if result
+ elsif File.file?(path)
+ return path if path =~ /.gwt.xml$/
+ end
end
+ nil
end
- nil
end
end
end
@@ -1,16 +1,18 @@
require 'rails/generators/resource_helpers'
require 'generators/resty/base'
module Resty
- class ControllerGenerator < Base
- include Rails::Generators::ResourceHelpers
+ module Generators
+ class ControllerGenerator < Base
+ include Rails::Generators::ResourceHelpers
- source_root File.expand_path('../../templates', __FILE__)
-
- argument :actions, :type => :array, :default => [], :banner => "action action"
+ source_root File.expand_path('../../templates', __FILE__)
+
+ argument :actions, :type => :array, :default => [], :banner => "action action"
- def create_controller_file
- template 'controller.java', File.join(java_root, controllers_base_package.gsub(/\./, "/"), class_path, "#{controller_class_name}Controller.java")
- end
+ def create_controller_file
+ template 'Controller.java', File.join(java_root, controllers_base_package.gsub(/\./, "/"), class_path, "#{controller_class_name}Controller.java")
+ end
+ end
end
end
@@ -1,29 +0,0 @@
-require 'generators/resty/base'
-module Resty
- class GwtGenerator < Base
-
- source_root File.expand_path('../../templates', __FILE__)
-
- arguments.clear # clear name argument from NamedBase
-
- def name # set alias so NamedBase uses the model as its name
- "gwt_module_name"
- end
-
- def create_module_file
- template 'module.gwt.xml', File.join(java_root, name.gsub(/\./, "/"), "#{application_name.underscore}.gwt.xml")
- end
-
- def create_maven_file
- template 'maven.rb', File.join("maven.rb")
- end
-
- def create_entry_point_file
- template 'entry_point.java', File.join(java_root, base_package.gsub(/\./, "/"), "#{application_name}.java")
- end
-
- def base_package
- name + ".client"
- end
- end
-end
@@ -1,18 +1,23 @@
require 'rails/generators/resource_helpers'
require 'generators/resty/base'
module Resty
- class ModelGenerator < Base
+ module Generators
+ class ModelGenerator < Base
- source_root File.expand_path('../../templates', __FILE__)
+ source_root File.expand_path('../../templates', __FILE__)
+
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
+ if defined? ::Ixtlan::ModifiedBy
+ class_option :modified_by, :type => :boolean
+ end
+ class_option :timestamps, :type => :boolean
+ class_option :parent, :type => :string, :desc => "The parent class for the generated model"
- class_option :timestamps, :type => :boolean
- class_option :parent, :type => :string, :desc => "The parent class for the generated model"
+ def create_model_file
+ template 'Model.java', File.join(java_root, models_base_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
+ end
- def create_model_file
- template 'model.java', File.join(java_root, models_base_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
end
-
end
end
@@ -1,26 +1,40 @@
require 'rails/generators/resource_helpers'
require 'generators/resty/base'
module Resty
- class ScaffoldGenerator < Base
- include Rails::Generators::ResourceHelpers
+ module Generators
+ class ScaffoldGenerator < Base
+ include Rails::Generators::ResourceHelpers
- source_root File.expand_path('../../templates', __FILE__)
-
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
+ source_root File.expand_path('../../templates', __FILE__)
+
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
- class_option :timestamps, :type => :boolean
- class_option :parent, :type => :string, :desc => "The parent class for the generated model"
+ if defined? ::Ixtlan::ModifiedBy
+ class_option :modified_by, :type => :boolean
+ end
+ class_option :timestamps, :type => :boolean
+ class_option :parent, :type => :string, :desc => "The parent class for the generated model"
+ class_option :singleton, :type => :boolean
- def create_model_file
- template 'model.java', File.join(java_root, models_base_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
- end
+ def create_model_file
+ template 'Model.java', File.join(java_root, models_base_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
+ end
- def create_controller_file
- template 'controller.java', File.join(java_root, controllers_base_package.gsub(/\./, "/"), class_path, "#{controller_class_name}Controller.java")
- end
+ def create_controller_file
+ template 'Controller.java', File.join(java_root, controllers_base_package.gsub(/\./, "/"), class_path, "#{controller_class_name}Controller.java")
+ end
- def actions
- action_map.keys
+ def actions
+ if options[:singleton]
+ keys = action_map.keys
+ keys.delete('index')
+ keys.delete('create')
+ keys.delete('destroy')
+ keys
+ else
+ action_map.keys
+ end
+ end
end
end
end
@@ -0,0 +1,37 @@
+require 'generators/resty/base'
+module Resty
+ module Generators
+ class SetupGenerator < Base
+
+ source_root File.expand_path('../templates', __FILE__)
+
+ arguments.clear # clear name argument from NamedBase
+
+ argument :gwt_module_name, :type => :string, :required => true
+
+ def name
+ gwt_module_name
+ end
+
+ def create_module_file
+ template 'module.gwt.xml', File.join(java_root, name.gsub(/\./, "/"), "#{application_name.underscore}.gwt.xml")
+ end
+
+ def create_maven_file
+ template 'Mavenfile', File.join("Mavenfile")
+ end
+
+ def create_entry_point_file
+ template 'EntryPoint.java', File.join(java_root, base_package.gsub(/\./, "/"), "#{application_name}.java")
+ end
+
+ def create_initializer
+ template 'initializer.rb', File.join('config', 'initializers', 'resty.rb')
+ end
+
+ def base_package
+ name + ".client"
+ end
+ end
+ end
+end
@@ -1,3 +1,4 @@
+jar('org.fusesource.restygwt:restygwt', '1.1').scope = :provided
plugin('org.codehaus.mojo.gwt-maven-plugin', '2.1.0') do |gwt|
gwt.with({ :logLevel => "INFO",
:style => "DETAILED",
@@ -0,0 +1,3 @@
+require 'resty/child_path'
+
+Rails.application.config.middleware.use Resty::ChildPath, '<%= application_name.underscore %>'
@@ -6,42 +6,42 @@
import javax.ws.rs.*;
-import org.fusesource.restygwt.examples.client.*;
+import org.fusesource.restygwt.client.*;
<% if name -%>
-import <%= models_base_package %>.<%= class_name %>;
+import <%= models_base_package %>.*;
<% end -%>
-@Path("/<%= table_name %>")
+@Path("/<%= table_name %><%= options[:singleton] ? '.json' : '' %>")
public interface <%= controller_class_name %>Controller extends RestService {
<% actions.each do |action|
case action_map[action]
when :get_all -%>
- @GET
+ @GET @Path('.json')
void <%= action %>(MethodCallback<List<<%= class_name %>>> callback);
-// @GET
+// @GET @Path('.json')
// void <%= action %>(MethodCallback<List<<%= class_name %>>> callback, @QueryParam("limit") int limit, @QueryParam("offset") int offset);
//
<% when :get_single -%>
- @GET @Path("/{id}")
- void <%= action %>(@PathParam("id") int id, MethodCallback<<%= class_name %>> callback);
+ @GET<% unless options[:singleton] -%> @Path("/{id}.json")<% end %>
+ void <%= action %>(<% unless options[:singleton] -%>@PathParam("id") int id, <% end -%>MethodCallback<<%= class_name %>> callback);
<% when :post -%>
- @POST
+ @POST @Path('.json')
void <%= action %>(<%= class_name %> value, MethodCallback<<%= class_name %>> callback);
<% when :put -%>
- @PUT @Path("/{id}")
- void <%= action %>(@PathParam("id") @Attribute("id") <%= class_name %> value, MethodCallback<<%= class_name %>> callback);
+ @PUT<% unless options[:singleton] -%> @Path("/{id}.json")<% end %>
+ void <%= action %>(<% unless options[:singleton] -%>@PathParam("id") @Attribute("id") <% end -%><%= class_name %> value, MethodCallback<<%= class_name %>> callback);
<% when :delete -%>
- @DELETE @Path("/{id}")
+ @DELETE @Path("/{id}.json")
void <%= action %>(@PathParam("id") @Attribute("id") <%= class_name %> value, MethodCallback<Void> callback);
<% else -%>
- @GET
+ @GET @Path("/<%= action %>.json")
void <%= action %>(MethodCallback<Void> callback);
<% end
@@ -0,0 +1,23 @@
+package <%= models_base_package %>;
+
+public class <%= class_name %> {
+
+<% for attribute in attributes -%>
+<% if attribute.type == :has_one -%>
+ <%= attribute.name.classify %> <%= attribute.name %>;
+<% elsif attribute.type == :has_many -%>
+ public java.util.List<<%= attribute.name.classify %>> <%= attribute.name %>;
+<% else -%>
+ public <%= type_map[attribute.type] || attribute.type.to_s.classify %> <%= attribute.name.classify.sub(/^(.)/){ $1.downcase } %>;
+<% end -%>
+
+<% end -%>
+<% if options[:timestamps] %>
+ //TODO timestamps
+
+<% end -%>
+<% if options[:modified_by] %>
+ //TODO modified_by
+
+<% end -%>
+}
@@ -1,13 +0,0 @@
-package <%= models_base_package %>;
-
-public class <%= class_name %> {
-<% for attribute in attributes -%>
-
- <%= type_map[attribute.type] || attribute.type %> <%= attribute.name %>;
-<% end -%>
-<% if options[:timestamps] %>
-
- //TODO timestamps
-<% end -%>
-
-}
@@ -0,0 +1,12 @@
+module Rails
+ module Generators
+ class ModelGenerator < NamedBase #metagenerator
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
+ hook_for :orm, :required => true
+
+ hook_for :resty, :type => :boolean, :default => true do |controller|
+ invoke controller, [class_name]
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 3b39343

Please sign in to comment.