Class: Resty::Generators::SetupGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/generators/resty/setup/setup_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_gemsObject



106
107
108
# File 'lib/generators/resty/setup/setup_generator.rb', line 106

def add_gems
  gem 'ixtlan-core'
end

#add_raketaskObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/generators/resty/setup/setup_generator.rb', line 110

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

#base_packageObject



212
213
214
# File 'lib/generators/resty/setup/setup_generator.rb', line 212

def base_package
  name + '.client'
end

#create_entry_point_fileObject



36
37
38
# File 'lib/generators/resty/setup/setup_generator.rb', line 36

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

#create_htmlObject



96
97
98
99
# File 'lib/generators/resty/setup/setup_generator.rb', line 96

def create_html
  template 'page.html', File.join('public', "#{application_name}.html")
  template 'gwt.css', File.join('public', 'stylesheets', "#{application_name.underscore}.css")
end

#create_managed_filesObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/resty/setup/setup_generator.rb', line 40

def create_managed_files
  path = managed_package.gsub(/\./, '/')
  template 'PlaceHistoryMapper.java', 
                  File.join(java_root, path, 
                            "#{application_name}PlaceHistoryMapper.java")
  template 'GinModule.java', 
                  File.join(java_root, path, 
                            "#{application_name}Module.java")
  template 'ActivityFactory.java', 
                  File.join(java_root, path, 
                            'ActivityFactory.java')
  if options[:menu]
    template 'MenuPanel.java', 
                  File.join(java_root, path, 
                            "#{application_name}MenuPanel.java")
  end
end

#create_maven_fileObject



26
27
28
29
30
31
32
33
34
# File 'lib/generators/resty/setup/setup_generator.rb', line 26

def create_maven_file
  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' }
  end
end

#create_module_fileObject



22
23
24
# File 'lib/generators/resty/setup/setup_generator.rb', line 22

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

#create_rails_session_filesObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/generators/resty/setup/setup_generator.rb', line 125

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')
    development = File.read(file)
    changed = false
    unless development =~ /config.remote_service_url/
      changed = true
      development.sub! /^end\s*$/, <<ENV

  if ENV['SSO'] == 'true' || ENV['SSO'] == ''
    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
    else
      log 'unchanged', file
    end
    file = File.join('app', 'controllers', 'application_controller.rb')
    app_controller = File.read(file)
    changed = false
    unless app_controller =~ /def\s+current_user/
      changed = true
      app_controller.sub! /^end\s*$/, <<SESSION

  protected

  def current_user(user = nil)
    session['user'] = user if user
    session['user']
  end
end
SESSION
    end
    unless app_controller =~ /def\s+csrf/
      changed = true
      app_controller.sub! /^end\s*$/, <<SESSION

  private

  after_filter :csrf

  def csrf
    response.header['X-CSRF-Token'] = form_authenticity_token if current_user
  end
end
SESSION
    end
    if changed
      File.open(file, 'w') { |f| f.print app_controller }
      log 'changed', file
    else
      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
    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
post :reset_password
    end
  end
ROUTE
    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
  end
end

#create_scaffolded_filesObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/resty/setup/setup_generator.rb', line 58

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

#create_session_filesObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/generators/resty/setup/setup_generator.rb', line 73

def create_session_files
  if options[:session]
    template 'LoginActivity.java',
                  File.join(java_root, activities_package.gsub(/\./, '/'),
                            'LoginActivity.java')
    template 'User.java',
                  File.join(java_root, models_package.gsub(/\./, '/'),
                            'User.java')
    template 'LoginPlace.java',
                  File.join(java_root, places_package.gsub(/\./, '/'),
                            'LoginPlace.java')
    template 'SessionRestService.java',
                  File.join(java_root, restservices_package.gsub(/\./, '/'),
                            'SessionRestService.java')
    template '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')
  end
end

#create_web_xmlObject



101
102
103
104
# File 'lib/generators/resty/setup/setup_generator.rb', line 101

def create_web_xml
  template 'web.xml', File.join('public', 'WEB-INF', 'web.xml')
  template 'gitignore', File.join('public', 'WEB-INF', '.gitignore')
end

#nameObject



18
19
20
# File 'lib/generators/resty/setup/setup_generator.rb', line 18

def name
  gwt_module_name
end