caterpillar 0.9.16 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +9 -1
- data/README +36 -6
- data/generators/caterpillar/USAGE +1 -1
- data/generators/caterpillar/caterpillar_generator.rb +44 -25
- data/generators/caterpillar/templates/config/portlets.rb +5 -5
- data/generators/caterpillar/templates/images/portlet_test_bench/Leafy_Sea_Dragon_1.jpg +0 -0
- data/generators/caterpillar/templates/images/portlet_test_bench/debug.jpg +0 -0
- data/generators/caterpillar/templates/images/portlet_test_bench/java.png +0 -0
- data/generators/caterpillar/templates/images/portlet_test_bench/rails.png +0 -0
- data/generators/caterpillar/templates/images/portlet_test_bench/ruby.gif +0 -0
- data/generators/caterpillar/templates/javascripts/portlet_test_bench/main.js +3 -0
- data/generators/caterpillar/templates/stylesheets/portlet_test_bench/main.css +163 -0
- data/init.rb +30 -3
- data/lib/caterpillar.rb +36 -1
- data/lib/caterpillar/config.rb +12 -2
- data/lib/caterpillar/liferay.rb +70 -14
- data/lib/caterpillar/portlet.rb +9 -0
- data/lib/caterpillar/task.rb +3 -12
- data/lib/web/portlet.rb +0 -7
- data/portlet_test_bench/controllers/caterpillar/application.rb +13 -0
- data/portlet_test_bench/controllers/caterpillar/css_controller.rb +9 -0
- data/portlet_test_bench/controllers/caterpillar/http_methods_controller.rb +35 -0
- data/portlet_test_bench/controllers/caterpillar/js_controller.rb +74 -0
- data/portlet_test_bench/controllers/caterpillar/login_controller.rb +41 -0
- data/portlet_test_bench/controllers/caterpillar/resource_controller.rb +23 -0
- data/portlet_test_bench/controllers/caterpillar/session_controller.rb +57 -0
- data/portlet_test_bench/controllers/caterpillar/user_controller.rb +6 -0
- data/portlet_test_bench/helpers/caterpillar/application_helper.rb +3 -0
- data/portlet_test_bench/routing.rb +43 -0
- data/portlet_test_bench/views/caterpillar/application/_back_to_menu.html.erb +13 -0
- data/portlet_test_bench/views/caterpillar/application/index.html.erb +70 -0
- data/portlet_test_bench/views/caterpillar/css/background.html.erb +30 -0
- data/portlet_test_bench/views/caterpillar/css/simple.html.erb +53 -0
- data/portlet_test_bench/views/caterpillar/http_methods/back.html.erb +2 -0
- data/portlet_test_bench/views/caterpillar/http_methods/parameter.html.erb +21 -0
- data/portlet_test_bench/views/caterpillar/http_methods/post.html.erb +43 -0
- data/portlet_test_bench/views/caterpillar/http_methods/post_and_redirect.html.erb +25 -0
- data/portlet_test_bench/views/caterpillar/http_methods/redirect.html.erb +4 -0
- data/portlet_test_bench/views/caterpillar/js/_scriptaculous_jquery.html.erb +19 -0
- data/portlet_test_bench/views/caterpillar/js/dragndrop.html.erb +40 -0
- data/portlet_test_bench/views/caterpillar/js/jquery.html.erb +5 -0
- data/portlet_test_bench/views/caterpillar/js/link_to_post.html.erb +5 -0
- data/portlet_test_bench/views/caterpillar/js/prototype.html.erb +5 -0
- data/portlet_test_bench/views/caterpillar/js/scriptaculous.html.erb +10 -0
- data/portlet_test_bench/views/caterpillar/js/simple.html.erb +34 -0
- data/portlet_test_bench/views/caterpillar/login/index.html.erb +52 -0
- data/portlet_test_bench/views/caterpillar/resource/exit_portlet.html.erb +3 -0
- data/portlet_test_bench/views/caterpillar/resource/images.html.erb +13 -0
- data/portlet_test_bench/views/caterpillar/user/home.html.erb +3 -0
- data/portlet_test_bench/views/layouts/basic.html.erb +20 -0
- metadata +61 -3
data/lib/caterpillar/config.rb
CHANGED
@@ -35,14 +35,24 @@ module Caterpillar
|
|
35
35
|
|
36
36
|
# Sets sane defaults that are overridden in the config file.
|
37
37
|
def initialize
|
38
|
-
|
38
|
+
# RAILS_ROOT is at least defined in Caterpillar initialization
|
39
|
+
@rails_root = File.expand_path(RAILS_ROOT)
|
39
40
|
@servlet = File.basename(@rails_root)
|
40
41
|
@category = @servlet
|
41
42
|
@instances = []
|
42
43
|
@javascripts = []
|
43
44
|
@include_all_named_routes = true
|
45
|
+
|
46
|
+
rails_conf = File.join(@rails_root,'config','environment.rb')
|
47
|
+
unless File.exists?(rails_conf)
|
48
|
+
STDERR.puts 'Rails configuration file could not be found'
|
49
|
+
end
|
50
|
+
|
44
51
|
@warbler_conf = File.join(@rails_root,'config','warble.rb')
|
45
|
-
|
52
|
+
unless File.exists?(@warbler_conf)
|
53
|
+
STDERR.puts 'Warbler configuration file could not be found'
|
54
|
+
end
|
55
|
+
|
46
56
|
#@logger = (defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new)
|
47
57
|
|
48
58
|
yield self if block_given?
|
data/lib/caterpillar/liferay.rb
CHANGED
@@ -7,6 +7,33 @@
|
|
7
7
|
module Caterpillar
|
8
8
|
# Creates liferay-portlet XML and liferay-display XML.
|
9
9
|
# The latter optionally combines your production portlet display configuration.
|
10
|
+
#
|
11
|
+
# See http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Liferay-portlet.xml
|
12
|
+
#
|
13
|
+
# Supported portlet.xml tags:
|
14
|
+
# (*) stands for non-configurable
|
15
|
+
#
|
16
|
+
# <portlet-name>
|
17
|
+
# <icon> (*)
|
18
|
+
# <instanceable> (*; always true)
|
19
|
+
#
|
20
|
+
# 5.1.x -specific:
|
21
|
+
# <header-portal-javascript>
|
22
|
+
#
|
23
|
+
# 5.2.0 -specific:
|
24
|
+
# <footer-portal-javascript>
|
25
|
+
# <control-panel-entry-category>
|
26
|
+
# <control-panel-entry-weight> (*; always 99.0)
|
27
|
+
#
|
28
|
+
# TODO:
|
29
|
+
# <footer-portlet-javascript>
|
30
|
+
# <header-portlet-css>
|
31
|
+
# <use-default-template>
|
32
|
+
# <private-request-attributes>
|
33
|
+
# <private-session-attributes>
|
34
|
+
# <render-weight>
|
35
|
+
# <restore-current-view>
|
36
|
+
#
|
10
37
|
class Liferay
|
11
38
|
|
12
39
|
# Liferay version
|
@@ -16,9 +43,8 @@ module Caterpillar
|
|
16
43
|
attr_accessor :root
|
17
44
|
|
18
45
|
# Liferay version is given as a String, eg. '5.2.2'.
|
19
|
-
#
|
46
|
+
# Defaults to +Lportal::Schema.version+.
|
20
47
|
def initialize(version=nil)
|
21
|
-
|
22
48
|
@version = version
|
23
49
|
@root = '/usr/local/liferay'
|
24
50
|
end
|
@@ -103,12 +129,12 @@ module Caterpillar
|
|
103
129
|
# liferay-portlet XML
|
104
130
|
def portletapp_xml(portlets)
|
105
131
|
doctype = 'liferay-portlet-app'
|
106
|
-
xml =
|
132
|
+
xml = xml_header(doctype)
|
107
133
|
portlets.each do |p|
|
108
|
-
xml <<
|
134
|
+
xml << portletapp_template(p)
|
109
135
|
end
|
110
|
-
xml <<
|
111
|
-
|
136
|
+
xml << roles
|
137
|
+
xml << portlet_xml_footer(doctype)
|
112
138
|
end
|
113
139
|
|
114
140
|
# liferay-display XML
|
@@ -181,41 +207,71 @@ module Caterpillar
|
|
181
207
|
'5.1.0'
|
182
208
|
elsif @version[/5.2/]
|
183
209
|
'5.2.0'
|
210
|
+
else
|
211
|
+
@version
|
184
212
|
end
|
185
213
|
when 'display'
|
186
214
|
if @version[/5.1/]
|
187
215
|
'5.1.0'
|
188
216
|
elsif @version[/5.2/]
|
189
217
|
'5.2.0'
|
218
|
+
else
|
219
|
+
@version
|
190
220
|
end
|
191
221
|
end
|
192
222
|
end
|
193
223
|
|
224
|
+
# the actual portlet definition
|
194
225
|
def portletapp_template(portlet)
|
195
226
|
xml = " <portlet>\n"
|
196
227
|
xml << " <portlet-name>%s</portlet-name>\n" % portlet[:name]
|
197
|
-
xml << " <icon>/%s/
|
228
|
+
xml << " <icon>/%s/favicon.ico</icon>\n" % portlet[:servlet]
|
198
229
|
# can there be several portlet instances on the same page?
|
199
230
|
xml << " <instanceable>true</instanceable>\n"
|
231
|
+
# define the control panel category for 5.2 and newer
|
232
|
+
unless @version[/5.1/]
|
233
|
+
xml << " <control-panel-entry-category>#{portlet[:category]}</control-panel-entry-category>\n"
|
234
|
+
xml << " <control-panel-entry-weight>99.0</control-panel-entry-weight>\n"
|
235
|
+
end
|
200
236
|
# include javascripts?
|
237
|
+
js_tag = (@version[/5.1/] ? 'header' : 'footer') + '-portal-javascript'
|
201
238
|
portlet[:javascripts].each do |js|
|
202
|
-
xml << "
|
203
|
-
xml << "
|
204
|
-
xml << "
|
239
|
+
xml << " <#{js_tag}>"
|
240
|
+
xml << "/#{portlet[:servlet]}/javascripts/#{js}"
|
241
|
+
xml << "</#{js_tag}>\n"
|
205
242
|
end
|
206
243
|
xml << " </portlet>\n\n"
|
207
244
|
end
|
208
245
|
|
209
246
|
def display_template(category,portlets)
|
210
247
|
xml = ' <category name="%s">' % category +"\n"
|
211
|
-
|
212
248
|
portlets.each do |p|
|
213
|
-
xml << ' <portlet id="%s" />' % p[:name]
|
214
|
-
xml << "\n"
|
249
|
+
xml << ' <portlet id="%s" />' % p[:name] + "\n"
|
215
250
|
end
|
216
251
|
xml << " </category>\n\n"
|
252
|
+
end
|
217
253
|
|
218
|
-
|
254
|
+
private
|
255
|
+
|
256
|
+
# XML role-mapper.
|
257
|
+
# Has to be duplicated in -ext.xml
|
258
|
+
def roles
|
259
|
+
xml = " <role-mapper>\n"
|
260
|
+
xml << " <role-name>administrator</role-name>\n"
|
261
|
+
xml << " <role-link>Administrator</role-link>\n"
|
262
|
+
xml << " </role-mapper>\n"
|
263
|
+
xml << " <role-mapper>\n"
|
264
|
+
xml << " <role-name>guest</role-name>\n"
|
265
|
+
xml << " <role-link>Guest</role-link>\n"
|
266
|
+
xml << " </role-mapper>\n"
|
267
|
+
xml << " <role-mapper>\n"
|
268
|
+
xml << " <role-name>power-user</role-name>\n"
|
269
|
+
xml << " <role-link>Power User</role-link>\n"
|
270
|
+
xml << " </role-mapper>\n"
|
271
|
+
xml << " <role-mapper>\n"
|
272
|
+
xml << " <role-name>user</role-name>\n"
|
273
|
+
xml << " <role-link>User</role-link>\n"
|
274
|
+
xml << " </role-mapper>\n"
|
219
275
|
end
|
220
276
|
|
221
277
|
public
|
data/lib/caterpillar/portlet.rb
CHANGED
@@ -55,6 +55,10 @@ module Caterpillar
|
|
55
55
|
|
56
56
|
# portlet.xml template.
|
57
57
|
def template(portlet)
|
58
|
+
# add roles
|
59
|
+
# TODO: move into portlet hash
|
60
|
+
# administrator, power-user, user
|
61
|
+
roles = %w{ administrator }
|
58
62
|
xml = " <!-- %s -->\n" % portlet[:title]
|
59
63
|
|
60
64
|
xml << " <portlet>\n"
|
@@ -74,6 +78,11 @@ module Caterpillar
|
|
74
78
|
xml << " <portlet-info>\n"
|
75
79
|
xml << " <title>%s</title>\n" % portlet[:title]
|
76
80
|
xml << " </portlet-info>\n"
|
81
|
+
roles.each do |role|
|
82
|
+
xml << " <security-role-ref>\n"
|
83
|
+
xml << " <role-name>#{role}</role-name>\n"
|
84
|
+
xml << " </security-role-ref>\n"
|
85
|
+
end
|
77
86
|
xml << " </portlet>\n\n"
|
78
87
|
|
79
88
|
### portlet filters
|
data/lib/caterpillar/task.rb
CHANGED
@@ -7,15 +7,6 @@
|
|
7
7
|
# software license details.
|
8
8
|
#++
|
9
9
|
|
10
|
-
require 'rake'
|
11
|
-
require 'rake/tasklib'
|
12
|
-
|
13
|
-
# these are required for Caterpillar to work on Ruby 1.8.5.
|
14
|
-
# you shouldn't have more than one Rails installed at a time, or you should
|
15
|
-
# use the latest with Caterpillar.
|
16
|
-
require 'actionpack'
|
17
|
-
require 'action_controller'
|
18
|
-
|
19
10
|
# --
|
20
11
|
# Rake task. Allows defining multiple configurations inside the same
|
21
12
|
# Rakefile by using different task names.
|
@@ -127,7 +118,7 @@ module Caterpillar
|
|
127
118
|
end
|
128
119
|
|
129
120
|
# print produced portlets
|
130
|
-
tasks << :portlets
|
121
|
+
#tasks << :portlets
|
131
122
|
|
132
123
|
task :xml => tasks
|
133
124
|
end
|
@@ -136,7 +127,7 @@ module Caterpillar
|
|
136
127
|
def define_portlets_task
|
137
128
|
desc 'Prints portlet configuration'
|
138
129
|
task :portlets => :parse do
|
139
|
-
portal_info
|
130
|
+
#portal_info
|
140
131
|
info 'Portlet configuration ***********************'
|
141
132
|
print_portlets(@portlets)
|
142
133
|
end
|
@@ -208,7 +199,7 @@ module Caterpillar
|
|
208
199
|
with_namespace_and_config do |name, config|
|
209
200
|
desc 'Create JSR286 portlet XML'
|
210
201
|
task :portlet do
|
211
|
-
portal_info
|
202
|
+
#portal_info
|
212
203
|
|
213
204
|
exit 1 unless system('touch %s' % file)
|
214
205
|
f=File.open(file,'w')
|
data/lib/web/portlet.rb
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
unless defined?(RAILS_ENV)
|
2
|
-
# this should load an appropriate version, there are problems when using an older Rails
|
3
|
-
# than the latest stable.
|
4
|
-
require 'rubygems'
|
5
|
-
require 'active_record'
|
6
|
-
end
|
7
|
-
|
8
1
|
module Web # :nodoc:
|
9
2
|
# Adds Caterpillar portlets to available portlets.
|
10
3
|
class Portlet < ActiveRecord::Base
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Caterpillar::ApplicationController < ActionController::Base
|
2
|
+
|
3
|
+
layout 'basic'
|
4
|
+
|
5
|
+
helper 'Caterpillar::Application'
|
6
|
+
|
7
|
+
before_filter :is_test_selected
|
8
|
+
|
9
|
+
def is_test_selected
|
10
|
+
@test_is_selected = self.class.to_s[/Application/].nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Caterpillar::HttpMethodsController < Caterpillar::ApplicationController
|
2
|
+
|
3
|
+
def post
|
4
|
+
@msg = params[:msg] if request.post?
|
5
|
+
@checkbox = params[:checkbox]
|
6
|
+
render :action => :post
|
7
|
+
end
|
8
|
+
|
9
|
+
def post_and_redirect
|
10
|
+
@msg = '"%s" passed from POST to GET' % params[:msg_get] if request.get? and params[:msg_get]
|
11
|
+
if request.post?
|
12
|
+
redirect_to :action => :post_and_redirect, :msg_get => params[:msg]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def parameter
|
17
|
+
@params = params
|
18
|
+
@params.delete :action
|
19
|
+
@params.delete :controller
|
20
|
+
end
|
21
|
+
|
22
|
+
def redirect_back
|
23
|
+
redirect_to :back
|
24
|
+
end
|
25
|
+
|
26
|
+
def redirect_action
|
27
|
+
flash[:info] = 'This message was set in the action before redirect'
|
28
|
+
redirect_to :action => :redirect, :x => true
|
29
|
+
end
|
30
|
+
|
31
|
+
# def redirect_target
|
32
|
+
# render :action => :redirect
|
33
|
+
# end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class Caterpillar::JsController < Caterpillar::ApplicationController
|
2
|
+
|
3
|
+
def simple
|
4
|
+
@javascripts = false
|
5
|
+
render :layout => false
|
6
|
+
end
|
7
|
+
|
8
|
+
# the :defaults JavaScripts in javascript_include_tag
|
9
|
+
def defaults
|
10
|
+
@javascripts = false # do not include any javascripts
|
11
|
+
id = params[:id]
|
12
|
+
if id then
|
13
|
+
render :template => "js/#{id}"
|
14
|
+
else
|
15
|
+
render :template => 'js/defaults'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def prototype
|
20
|
+
@javascripts = ['prototype']
|
21
|
+
end
|
22
|
+
|
23
|
+
def scriptaculous
|
24
|
+
@javascripts = ['prototype','effects','controls']
|
25
|
+
end
|
26
|
+
|
27
|
+
def jquery
|
28
|
+
@javascripts = ['jquery','jquery-ui','jrails']
|
29
|
+
end
|
30
|
+
|
31
|
+
def dragndrop
|
32
|
+
#@javascript = ['prototype','scriptaculous']
|
33
|
+
# @javascripts = ['prototype','effects','dragdrop','controls']
|
34
|
+
# @javascripts = ['jquery','jquery-ui','jrails']
|
35
|
+
@javascripts = :defaults
|
36
|
+
end
|
37
|
+
|
38
|
+
def link_to_post
|
39
|
+
@msg = params[:msg] || 'method was GET'
|
40
|
+
end
|
41
|
+
|
42
|
+
def link_to_post_action
|
43
|
+
msgs = ['successful','ok','it works','dandy']
|
44
|
+
redirect_to :action => :link_to_post, :msg => msgs[rand(msgs.size)]
|
45
|
+
end
|
46
|
+
|
47
|
+
#######
|
48
|
+
|
49
|
+
def highlight_test
|
50
|
+
render :update do |page|
|
51
|
+
page[:highlight_test].visual_effect(:highlight)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def appear_test
|
56
|
+
render :update do |page|
|
57
|
+
page.visual_effect 'toggle_appear', "appear_test"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def toggle_blind_test
|
62
|
+
render :update do |page|
|
63
|
+
page.visual_effect 'toggle_blind', "toggle_blind_test"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def receive_drop
|
68
|
+
render :update do |page|
|
69
|
+
page[:drop_status].appear
|
70
|
+
page[:drop_status].replace_html('Received: %s' % params[:id])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Caterpillar::LoginController < Caterpillar::ApplicationController
|
2
|
+
|
3
|
+
before_filter :authorize, :except => [ :login, :index, :logout ]
|
4
|
+
|
5
|
+
# def initialize
|
6
|
+
# end
|
7
|
+
|
8
|
+
def index
|
9
|
+
@user = session[:username]
|
10
|
+
render :action => :index
|
11
|
+
end
|
12
|
+
|
13
|
+
def login
|
14
|
+
if request.post?
|
15
|
+
user = User.authenticate(params[:username],params[:password])
|
16
|
+
if user
|
17
|
+
session[:username] = user[:username]
|
18
|
+
# STDERR.puts user.inspect
|
19
|
+
flash[:notice] = "Logged in"
|
20
|
+
redirect_to :action => :index
|
21
|
+
else
|
22
|
+
flash[:notice] = "Invalid credentials"
|
23
|
+
render :action => :index
|
24
|
+
end
|
25
|
+
else
|
26
|
+
render :action => :index
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def logout
|
31
|
+
session[:username] = nil
|
32
|
+
flash[:notice] = "Logged out"
|
33
|
+
redirect_to :action => :index
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def authorize
|
38
|
+
redirect_to :action => :index
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Caterpillar::ResourceController < Caterpillar::ApplicationController
|
2
|
+
|
3
|
+
def images
|
4
|
+
@images = [
|
5
|
+
{ :description => "Rails logo", :file => 'portlet_test_bench/rails.png' }
|
6
|
+
# { :description => "Image from a subdirectory", :file => 'lolcat/lolcat-monorail.jpg' }
|
7
|
+
]
|
8
|
+
end
|
9
|
+
|
10
|
+
# Inline text
|
11
|
+
def inline
|
12
|
+
render :inline => "Inline text"
|
13
|
+
end
|
14
|
+
|
15
|
+
# link to outside the portlet
|
16
|
+
def exit_portlet
|
17
|
+
@links = ['http://www.rubyonrails.org', 'http://www.google.fi/search?q=jsr286', {:action => :exit_portlet}]
|
18
|
+
if params.include? :exit_portlet
|
19
|
+
render :inline => 'portlet should now be exited'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|