Skip to content

Commit

Permalink
follow the generators to the changes in rails-gwt and other changes i…
Browse files Browse the repository at this point in the history
…n dependent gems
  • Loading branch information
mkristian committed Jan 13, 2012
1 parent 56bed94 commit bdf8048
Show file tree
Hide file tree
Showing 30 changed files with 421 additions and 89 deletions.
20 changes: 10 additions & 10 deletions resty-generators/features/generators.feature
Expand Up @@ -14,30 +14,30 @@ Feature: Generators for Resty
Then the output should contain "src/main/java/com/example/Simple.gwt.xml" and "Mavenfile" and "src/main/java/com/example/client/SimpleEntryPoint.java" and "public/Simple.html" and "public/stylesheets/simple.css"

Given me an existing rails application "simple"
And I execute "compile gwt:compile"
Then the output should contain "Compilation succeeded"
And I execute "compile"
Then the output should contain "BUILD SUCCESS"

Given me an existing rails application "simple"
And I execute "rails generate scaffold user name:string"
Then the output should contain "src/main/java/com/example/client/models/User.java" and "src/main/java/com/example/client/restservices/UsersRestService.java"

Given me an existing rails application "simple"
And I execute "compile gwt:compile"
Then the output should contain "Compilation succeeded"
And I execute "compile"
Then the output should contain "BUILD SUCCESS"

Given me an existing rails application "simple"
And I execute "rake db:migrate test"
Then the output should contain "1 tests, 1 assertions, 0 failures, 0 errors" and "7 tests, 10 assertions, 0 failures, 0 errors"

Given me an existing rails application "simple"
And I execute "rails generate scaffold project name:string children:number cars:fixnum age:integer weight:float activated:boolean expires_at:date fire_up_at:datetime --skip-timestamps"
And I execute "compile gwt:compile"
Then the output should contain "Compilation succeeded"
And I execute "compile"
Then the output should contain "BUILD SUCCESS"

Given me an existing rails application "simple"
And I execute "rails generate scaffold accounts name:string --timestamps --optimistic"
And I execute "compile gwt:compile"
Then the output should contain "Compilation succeeded"
And I execute "compile"
Then the output should contain "BUILD SUCCESS"

Given me an existing rails application "simple"
And I execute "rails generate model cars name:string"
Expand All @@ -52,8 +52,8 @@ Feature: Generators for Resty
Then the output should contain "src/main/java/com/example/client/SessionActivityPlaceActivityMapper.java" and "src/main/java/com/example/client/managed/CompleteMenuPanel.java" and "src/main/java/com/example/client/activities/LoginActivity.java"

Given me an existing rails application "complete"
And I execute "compile gwt:compile"
Then the output should contain "Compilation succeeded"
And I execute "compile"
Then the output should contain "BUILD SUCCESS"

Given me an existing rails application "complete"
And I execute "rails generate scaffold accounts name:string"
Expand Down
Expand Up @@ -18,6 +18,12 @@ def create_model_file
template 'Model.java', File.join(java_root, models_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
end

def create_cache_file
if !options[:singleton] && !options[:read_only]
template 'Cache.java', File.join(java_root, caches_package.gsub(/\./, "/"), class_path, "#{class_name.pluralize}Cache.java")
end
end

def create_event_files
template 'Event.java', File.join(java_root, events_package.gsub(/\./, "/"), class_path, "#{class_name}Event.java")
template 'EventHandler.java', File.join(java_root, events_package.gsub(/\./, "/"), class_path, "#{class_name}EventHandler.java")
Expand All @@ -28,7 +34,7 @@ def create_rest_service_file
end

def controller_class_name
@controller_class_name ||= class_name
@controller_class_name ||= class_name.pluralize
end

def actions
Expand Down
Expand Up @@ -61,7 +61,7 @@ def add_to_activity_factory
if factory =~ /@Named\(.#{table_name}.\)/
log 'keep', factory_file
else
factory.sub! /interface\s+ActivityFactory\s+\{/, "interface ActivityFactory {\n @Named(\"#{table_name}\") Activity create(#{places_package}.#{class_name}Place place);"
factory.sub! /interface\s+ActivityFactory\s+\{/, "interface ActivityFactory {\n @Named(\"#{table_name}\") Activity create(#{places_package}.#{class_name}Place place);"
File.open(factory_file, 'w') { |f| f.print factory }
log "added to", factory_file
end
Expand Down Expand Up @@ -112,7 +112,7 @@ def add_to_module

content.sub! /new GinFactoryModuleBuilder\(\)/, "new GinFactoryModuleBuilder()\n .implement(Activity.class, Names.named(\"#{table_name}\"), #{activities_package}.#{class_name}Activity.class)"

content.sub! /^}/, <<-EOF
content.sub! /^\}/, <<-EOF
@Singleton
public static class #{class_name.pluralize}RestServiceProvider implements Provider<#{restservices_package}.#{class_name.pluralize}RestService> {
Expand Down
111 changes: 68 additions & 43 deletions resty-generators/lib/generators/resty/setup/setup_generator.rb
Expand Up @@ -13,30 +13,32 @@ class SetupGenerator < Base

class_option :menu, :type => :boolean, :default => false

class_option :remote_users, :type => :boolean, :default => false

def name
gwt_module_name
end

def create_module_file
template 'module.gwt.xml', File.join(java_root, name.gsub(/\./, "/"), "#{application_name}.gwt.xml")
template 'module.gwt.xml', File.join(java_root, name.gsub(/\./, '/'), "#{application_name}.gwt.xml")
end

def create_maven_file
template 'Mavenfile', "Mavenfile"
unless File.read(".gitignore") =~ /^target/
File.open(".gitignore", "a") { |f| f.puts "target/" }
template 'Mavenfile', 'Mavenfile'
unless File.read('.gitignore') =~ /^target/
File.open('.gitignore', 'a') { |f| f.puts 'target/' }
end
unless File.read(".gitignore") =~ /^*pom/
File.open(".gitignore", "a") { |f| f.puts "*pom" }
unless File.read('.gitignore') =~ /^\*pom/
File.open('.gitignore', 'a') { |f| f.puts '*pom' }
end
end

def create_entry_point_file
template 'EntryPoint.java', File.join(java_root, base_package.gsub(/\./, "/"), "#{application_name}EntryPoint.java")
template 'EntryPoint.java', File.join(java_root, base_package.gsub(/\./, '/'), "#{application_name}EntryPoint.java")
end

def create_managed_files
path = managed_package.gsub(/\./, "/")
path = managed_package.gsub(/\./, '/')
template 'PlaceHistoryMapper.java',
File.join(java_root, path,
"#{application_name}PlaceHistoryMapper.java")
Expand All @@ -45,7 +47,7 @@ def create_managed_files
"#{application_name}Module.java")
template 'ActivityFactory.java',
File.join(java_root, path,
"ActivityFactory.java")
'ActivityFactory.java')
if options[:menu]
template 'MenuPanel.java',
File.join(java_root, path,
Expand All @@ -54,43 +56,40 @@ def create_managed_files
end

def create_scaffolded_files
path = base_package.gsub(/\./, "/")
#template 'ActivityPlace.java',
# File.join(java_root, path,
# "ActivityPlace.java")
path = base_package.gsub(/\./, '/')
template 'ActivityPlaceActivityMapper.java',
File.join(java_root, path,
"ActivityPlaceActivityMapper.java")
'ActivityPlaceActivityMapper.java')
if options[:session]
template 'SessionActivityPlaceActivityMapper.java',
File.join(java_root, path,
"SessionActivityPlaceActivityMapper.java")
'SessionActivityPlaceActivityMapper.java')
template 'BreadCrumbsPanel.java',
File.join(java_root, path,
"BreadCrumbsPanel.java")
'BreadCrumbsPanel.java')
end
end

def create_session_files
if options[:session]
template 'LoginActivity.java',
File.join(java_root, activities_package.gsub(/\./, "/"),
"LoginActivity.java")
File.join(java_root, activities_package.gsub(/\./, '/'),
'LoginActivity.java')
template 'User.java',
File.join(java_root, models_package.gsub(/\./, "/"),
"User.java")
File.join(java_root, models_package.gsub(/\./, '/'),
'User.java')
template 'LoginPlace.java',
File.join(java_root, places_package.gsub(/\./, "/"),
"LoginPlace.java")
File.join(java_root, places_package.gsub(/\./, '/'),
'LoginPlace.java')
template 'SessionRestService.java',
File.join(java_root, restservices_package.gsub(/\./, "/"),
"SessionRestService.java")
File.join(java_root, restservices_package.gsub(/\./, '/'),
'SessionRestService.java')
template 'LoginViewImpl.java',
File.join(java_root, views_package.gsub(/\./, "/"),
"LoginViewImpl.java")
File.join(java_root, views_package.gsub(/\./, '/'),
'LoginViewImpl.java')
template 'LoginView.ui.xml',
File.join(java_root, views_package.gsub(/\./, "/"),
"LoginView.ui.xml")
File.join(java_root, views_package.gsub(/\./, '/'),
'LoginView.ui.xml')
end
end

Expand All @@ -108,29 +107,45 @@ def add_gems
gem 'ixtlan-core'
end

def add_raketask
prepend_file 'Rakefile', '#-*- mode: ruby -*-\n'
append_file 'Rakefile', <<-EOF
desc 'triggers the heartbeat request (user updates)'
task :heartbeat => [:environment] do
heartbeat = Heartbeat.new
heartbeat.beat
puts "\#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S')} - \#{heartbeat}"
end
# vim: syntax=Ruby
EOF
end

def create_rails_session_files
if options[:session]
template 'sessions_controller.rb', File.join('app', 'controllers', "sessions_controller.rb")
file = File.join('config', 'environments', "development.rb")
template 'sessions_controller.rb', File.join('app', 'controllers', 'sessions_controller.rb')
file = File.join('config', 'environments', 'development.rb')
development = File.read(file)
changed = false
unless development =~ /config.remote_sso_url/
unless development =~ /config.remote_service_url/
changed = true
development.sub! /^end\s*$/, <<ENV
if ENV['SSO'] == 'true' || ENV['SSO'] == ''
config.remote_sso_url = "http://localhost:3000"
config.remote_service_url = 'http://localhost:3000'
config.remote_token = 'be happy'
end
end
ENV
end
if changed
File.open(file, 'w') { |f| f.print development }
log "changed", file
log 'changed', file
else
log "unchanged", file
log 'unchanged', file
end
file = File.join('app', 'controllers', "application_controller.rb")
file = File.join('app', 'controllers', 'application_controller.rb')
app_controller = File.read(file)
changed = false
unless app_controller =~ /def\s+current_user/
Expand Down Expand Up @@ -162,14 +177,24 @@ def csrf
end
if changed
File.open(file, 'w') { |f| f.print app_controller }
log "changed", file
log 'changed', file
else
log "unchanged", file
log 'unchanged', file
end
template 'authentication.rb', File.join('app', 'models', 'authentication.rb')
template 'group.rb', File.join('app', 'models', 'group.rb')
template 'session.rb', File.join('app', 'models', 'session.rb')
template 'user.rb', File.join('app', 'models', 'user.rb')
if options[:remote_users]
template 'remote_user.rb', File.join('app', 'models', 'remote_user.rb')
template 'application.rb', File.join('app', 'models', 'application.rb')
template 'ApplicationLinksPanel.java', File.join(java_root, base_package.gsub(/\./, '/'), 'ApplicationLinksPanel.java')
template 'Application.java', File.join(java_root, models_package.gsub(/\./, '/'), 'Application.java')
template 'create_users.rb', File.join('db', 'migrate', '0_create_users.rb')
template 'heartbeat.rb', File.join('lib', 'heartbeat.rb')
end
template 'authentication.rb', File.join('app', 'models', "authentication.rb")
template 'group.rb', File.join('app', 'models', "group.rb")
template 'session.rb', File.join('app', 'models', "session.rb")
template 'user.rb', File.join('app', 'models', "user.rb")
FileUtils.mv(File.join('db', 'seeds.rb'), File.join('db', 'seeds-old.rb'))
template 'seeds.rb', File.join('db', 'seeds.rb')
route <<ROUTE
resource :session do
member do
Expand All @@ -180,12 +205,12 @@ def csrf
gem 'ixtlan-session-timeout'
gem 'ixtlan-guard'
# needs to be in Gemfile to have jruby find the gem
gem "jruby-openssl", "~> 0.7.4", :platforms => :jruby
gem 'jruby-openssl', '~> 0.7.4', :platforms => :jruby
end
end

def base_package
name + ".client"
name + '.client'
end

end
Expand Down
Expand Up @@ -27,7 +27,7 @@ public Activity getActivity(Place place) {
GWT.log(place.toString());
return ((RestfulPlace<?, ActivityFactory>) place).create(factory);
}
notice.setText("nothing to see");
notice.warn("nothing to see");
return null;
}
}
@@ -0,0 +1,31 @@
package <%= models_package %>;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;

import org.fusesource.restygwt.client.Json;
import org.fusesource.restygwt.client.Json.Style;

@Json(style = Style.RAILS)
public class Application {

private final String name;

private final String url;

@JsonCreator
public Application(@JsonProperty("name") String name,
@JsonProperty("url") String url){
this.url = url;
this.name = name;
}

public String getName(){
return name;
}

public String getUrl(){
return url;
}

}
@@ -0,0 +1,29 @@
package <%= base_package %>;

import javax.inject.Singleton;

import <%= models_package %>.Application;
import <%= models_package %>.User;
import com.google.inject.Inject;

import de.mkristian.gwt.rails.session.SessionManager;
import de.mkristian.gwt.rails.views.LinksPanel;

@Singleton
public class ApplicationLinksPanel extends LinksPanel<User> {

@Inject
ApplicationLinksPanel(SessionManager<User> sessionManager) {
super(sessionManager);
}

@Override
protected void initUser(User user) {
for(Application app: user.applications){
addLink(app.getName().equals("THIS") ?
"users" :
app.getName(), app.getUrl());
}
}

}
Expand Up @@ -33,7 +33,7 @@ public BreadCrumbsPanel(final SessionManager<User> sessionManager, final Session
sessionManager.addSessionHandler(new SessionHandler<User>() {

public void timeout() {
notice.setText("timeout");
notice.info("timeout");
logout();
}

Expand All @@ -52,7 +52,7 @@ public void login(User user) {
}

public void accessDenied() {
notice.setText("access denied");
notice.error("access denied");
}
});
logout = new Button("logout");
Expand Down

0 comments on commit bdf8048

Please sign in to comment.