caterpillar 1.4.4 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/ChangeLog +27 -0
- data/MIT-LICENSE +0 -4
- data/README.rdoc +3 -3
- data/Rakefile +6 -22
- data/caterpillar.gemspec +28 -0
- data/generators/caterpillar/caterpillar_generator.rb +12 -4
- data/generators/caterpillar/templates/config/portlets.rb +10 -2
- data/generators/caterpillar/templates/stylesheets/portlet_test_bench/main.css +2 -2
- data/init.rb +20 -8
- data/lib/caterpillar.rb +33 -27
- data/lib/caterpillar/config.rb +3 -1
- data/lib/caterpillar/helpers/liferay.rb +129 -132
- data/lib/caterpillar/helpers/portlet.rb +41 -0
- data/lib/caterpillar/liferay.rb +2 -3
- data/lib/caterpillar/navigation.rb +2 -4
- data/lib/caterpillar/parser.rb +1 -5
- data/lib/caterpillar/portlet.rb +20 -19
- data/lib/caterpillar/portlet_support.rb +9 -22
- data/lib/caterpillar/security.rb +20 -42
- data/lib/caterpillar/task.rb +17 -36
- data/lib/caterpillar/usage.rb +14 -10
- data/lib/caterpillar/util.rb +1 -1
- data/lib/java/rails-portlet-0.12.0.jar +0 -0
- data/lib/rails_gem_chooser.rb +14 -7
- data/lib/web/portlet.rb +1 -1
- data/portlet_test_bench/controllers/caterpillar/application.rb +0 -5
- data/portlet_test_bench/controllers/caterpillar/junit_controller.rb +30 -9
- data/portlet_test_bench/controllers/caterpillar/liferay_controller.rb +13 -3
- data/portlet_test_bench/controllers/caterpillar/session_controller.rb +3 -0
- data/portlet_test_bench/controllers/caterpillar/xhr_controller.rb +12 -1
- data/portlet_test_bench/views/caterpillar/application/_back_to_menu.html.erb +1 -1
- data/portlet_test_bench/views/caterpillar/application/index.html.erb +8 -1
- data/portlet_test_bench/views/caterpillar/application/portlet_test_bench.html.erb +26 -8
- data/portlet_test_bench/views/caterpillar/css/background.html.erb +4 -1
- data/portlet_test_bench/views/caterpillar/css/simple.html.erb +13 -9
- data/portlet_test_bench/views/caterpillar/liferay/session_variables.html.erb +3 -12
- data/portlet_test_bench/views/caterpillar/session/cookies.html.erb +5 -0
- data/portlet_test_bench/views/caterpillar/session/namespace.html.erb +14 -0
- data/portlet_test_bench/views/caterpillar/xhr/resource.html.erb +15 -0
- data/portlet_test_bench/views/caterpillar/xhr/time.html.erb +7 -6
- data/spec/app1/config/routes.rb +3 -0
- data/spec/app2/config/routes.rb +7 -0
- data/spec/app3/config/routes.rb +5 -0
- data/spec/caterpillar/helper_spec.rb +69 -0
- data/spec/caterpillar/task_spec.rb +192 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +44 -0
- data/test/README +4 -0
- data/test/dtd/liferay-display_5_1_0.dtd +44 -44
- data/test/dtd/liferay-display_5_2_0.dtd +44 -44
- data/test/dtd/liferay-display_6_0_0.dtd +44 -44
- data/test/dtd/liferay-portlet-app_5_1_0.dtd +582 -582
- data/test/dtd/liferay-portlet-app_5_2_0.dtd +642 -642
- data/test/dtd/liferay-portlet-app_6_0_0.dtd +730 -730
- data/test/dtd/portlet-app_2_0.xsd +830 -830
- data/test/liferay_helpers_test.rb +94 -7
- data/test/portlet_support_test.rb +0 -18
- data/test/portlets_test.rb +6 -11
- data/test/xml_test.rb +4 -14
- metadata +53 -31
- data/lib/java/rails-portlet-0.10.1.jar +0 -0
data/.gitignore
ADDED
data/ChangeLog
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
= 1.6.0
|
2
|
+
Tested with Rails 2 and Liferay 5 and 6.
|
3
|
+
- upgrade to Rails-portlet jar 0.12, which supports both Liferay5 and Liferay6
|
4
|
+
- use most recent Liferay version (6.0.6) in the default config template, although container version in configuration is now obsolete
|
5
|
+
- remove parsing of :uid and :gid path variables
|
6
|
+
- update portlet test bench to get Liferay UID and GID from a cookie, and move the helper methods to Caterpillar::Helpers::Liferay
|
7
|
+
- refactor shared secret to portlets.rb - requires config file update for existing installations - see the portlets.rb config template
|
8
|
+
- removed useless and broken link_to_liferay() method
|
9
|
+
- cleaned up some of the init process
|
10
|
+
- update test bench cookie actions
|
11
|
+
- change test bench css colors to human-readable
|
12
|
+
|
13
|
+
= 1.5.0
|
14
|
+
This version contains a number of changes over a long period of time.
|
15
|
+
Tested to work on Rails 2.3.8 and 2.3.10.
|
16
|
+
Major changes include:
|
17
|
+
- compatibility with rails 2.3.10
|
18
|
+
- added PortletSupport#ajax_response method
|
19
|
+
- introduce ResourceUrl
|
20
|
+
|
21
|
+
Smaller changes include:
|
22
|
+
|
23
|
+
- fixed return link in test bench
|
24
|
+
- some new test cases
|
25
|
+
- removed rake related libraries from gemspec
|
26
|
+
- pruning of the Rakefile: removing the RDoc task that was broken, add a 'gem' task
|
27
|
+
|
1
28
|
= 1.4.4
|
2
29
|
- XML fixes
|
3
30
|
- added /caterpillar view
|
data/MIT-LICENSE
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
= Caterpillar
|
2
|
-
|
3
1
|
Caterpillar is provided under the terms of the MIT license.
|
4
2
|
|
5
|
-
(c) Copyright 2008,2009 Mikael Lammentausta for Cel'Amanzi Ltd
|
6
|
-
|
7
3
|
Permission is hereby granted, free of charge, to any person
|
8
4
|
obtaining a copy of this software and associated documentation files
|
9
5
|
(the "Software"), to deal in the Software without restriction,
|
data/README.rdoc
CHANGED
@@ -138,12 +138,12 @@ For example:
|
|
138
138
|
:preferences_route => '/my_portlet/test/preferences'
|
139
139
|
}
|
140
140
|
|
141
|
-
Rails-portlet will provide us a hash with all saved preferences, to access this method we need to include the Caterpillar::
|
142
|
-
include Caterpillar::
|
141
|
+
Rails-portlet will provide us a hash with all saved preferences, to access this method we need to include the Caterpillar::Helpers::Liferay module, like:
|
142
|
+
include Caterpillar::Helpers::Liferay
|
143
143
|
|
144
144
|
This module will provide <b>get_liferay_preferences</b> method which returns the preferences hash. A good approach is to include this module on <i>ApplicationController</i>, like:
|
145
145
|
class ApplicationController < ActionController::Base
|
146
|
-
include Caterpillar::
|
146
|
+
include Caterpillar::Helpers::Liferay
|
147
147
|
|
148
148
|
helper :all # include all helpers, all the time
|
149
149
|
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
data/Rakefile
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
require 'rake/gempackagetask'
|
5
|
-
load 'caterpillar.gemspec'
|
6
|
-
|
7
|
-
# gem install rspec -v 1.3.0
|
8
3
|
require 'spec/rake/spectask'
|
9
|
-
# gem install rcov
|
10
4
|
require 'spec/rake/verify_rcov'
|
11
5
|
|
12
6
|
desc 'Default: create API doc.'
|
13
7
|
task :default => :rdoc
|
14
8
|
|
9
|
+
desc "Create the caterpillar gem file"
|
10
|
+
task :gem do
|
11
|
+
spec = eval(IO.read("caterpillar.gemspec"))
|
12
|
+
Gem::Builder.new(spec).build
|
13
|
+
end
|
14
|
+
|
15
15
|
Spec::Rake::SpecTask.new do |t|
|
16
16
|
t.spec_opts ||= []
|
17
17
|
t.spec_opts << "--options" << "spec/spec.opts"
|
@@ -21,21 +21,5 @@ Spec::Rake::SpecTask.new("spec:rcov") do |t|
|
|
21
21
|
t.spec_opts ||= []
|
22
22
|
t.spec_opts << "--options" << "spec/spec.opts"
|
23
23
|
t.rcov = true
|
24
|
-
# t.rcov_opts = ['--text-report', '--exclude', "gems/,spec/,rcov.rb,#{File.expand_path(File.join(File.dirname(__FILE__),'../../..'))}"]
|
25
24
|
t.rcov_opts = ['--exclude', 'diff-lcs,rake,spec,rcov,active_support,action_controller,action_view,json,rack']
|
26
25
|
end
|
27
|
-
|
28
|
-
RCov::VerifyTask.new(:rcov => "spec:rcov") do |t|
|
29
|
-
t.threshold = 100
|
30
|
-
end
|
31
|
-
|
32
|
-
desc 'Generate documentation for the example plugin.'
|
33
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
34
|
-
rdoc.rdoc_dir = 'rdoc'
|
35
|
-
rdoc.title = 'Caterpillar'
|
36
|
-
rdoc.main = 'README.rdoc'
|
37
|
-
rdoc.rdoc_files.include('README.rdoc')
|
38
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
-
rdoc.rdoc_files.include('generators/**/*.rb')
|
40
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '-U'
|
41
|
-
end
|
data/caterpillar.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'lib/caterpillar'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = %q{caterpillar}
|
6
|
+
s.authors = ["Mikael Lammentausta"]
|
7
|
+
s.email = %q{mikael.lammentausta@gmail.com}
|
8
|
+
s.homepage = %q{http://github.com/lamikae/caterpillar}
|
9
|
+
s.version = Caterpillar::VERSION
|
10
|
+
|
11
|
+
s.add_dependency("hpricot", ">= 0.6.164")
|
12
|
+
s.add_dependency("jrexml")
|
13
|
+
s.add_dependency("rake")
|
14
|
+
|
15
|
+
s.description = %q{= Caterpillar}
|
16
|
+
|
17
|
+
s.executables = ["caterpillar"]
|
18
|
+
s.default_executable = %q{caterpillar}
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
|
22
|
+
s.extra_rdoc_files = ["README.rdoc","MIT-LICENSE","ChangeLog"]
|
23
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
24
|
+
s.rdoc_options << '--line-numbers' << '--inline-source'
|
25
|
+
s.rubyforge_project = %q{rails-portlet}
|
26
|
+
s.summary = %q{Caterpillar helps building Rails applications for JSR286 portlets.}
|
27
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
+
end
|
@@ -18,6 +18,16 @@ class CaterpillarGenerator < Rails::Generator::Base
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def after_generate
|
21
|
+
# generate random shared secret
|
22
|
+
msg(
|
23
|
+
"Generating new random shared secret to config/portlets.rb"
|
24
|
+
)
|
25
|
+
File.open(File.join('config','portlets.rb'), "r+") do |f|
|
26
|
+
newconf = f.read().sub('somereallylongrandomkey', Caterpillar::Security::random_secret)
|
27
|
+
f.seek 0
|
28
|
+
f.write newconf
|
29
|
+
end
|
30
|
+
|
21
31
|
msg(
|
22
32
|
"If you want to use the portlet test bench,\n" + \
|
23
33
|
"put the following line in your config/routes.rb before other routes.\n" + \
|
@@ -37,10 +47,8 @@ class CaterpillarGenerator < Rails::Generator::Base
|
|
37
47
|
record do |m|
|
38
48
|
|
39
49
|
### config ###
|
40
|
-
|
41
|
-
|
42
|
-
# m.file(File.join('config',file), File.join('config',file))
|
43
|
-
m.template('config/portlets.rb','config/portlets.rb')
|
50
|
+
file = File.join('config','portlets.rb')
|
51
|
+
m.template(file,file)
|
44
52
|
|
45
53
|
### Navigation ###
|
46
54
|
target = File.join('public','images')
|
@@ -5,7 +5,7 @@ Caterpillar::Config.new do |portlet|
|
|
5
5
|
# By default only portlet.xml is created.
|
6
6
|
# Currently only Liferay is supported. You may optionally define the version.
|
7
7
|
portlet.container = Liferay
|
8
|
-
# portlet.container.version = '
|
8
|
+
# portlet.container.version = '6.0.6'
|
9
9
|
|
10
10
|
# If you want to install the Rails-portlet JAR into the container, the container
|
11
11
|
# WEB-INF will be used.
|
@@ -15,7 +15,7 @@ Caterpillar::Config.new do |portlet|
|
|
15
15
|
#
|
16
16
|
# No changes are made to any of the files in this directory while making XML,
|
17
17
|
# only the deploy and install tasks make any changes.
|
18
|
-
# portlet.container.root = '/usr/local/liferay/tomcat
|
18
|
+
# portlet.container.root = '/usr/local/liferay-portal-6.0.6/tomcat-6.0.29'
|
19
19
|
|
20
20
|
# The server that the container is running on.
|
21
21
|
# Possible values:
|
@@ -87,6 +87,14 @@ Caterpillar::Config.new do |portlet|
|
|
87
87
|
:title => 'Rails-portlet test bench',
|
88
88
|
:category => 'Caterpillar'
|
89
89
|
}
|
90
|
+
|
91
|
+
# This secret string is shared between the portlets and the Rails server,
|
92
|
+
# and passed in a cookie with every request.
|
93
|
+
# It is used to prevent spoofed requests from unauthorized clients.
|
94
|
+
portlet.session_secret = {
|
95
|
+
:key => '_rails_portlet',
|
96
|
+
:secret => 'somereallylongrandomkey'
|
97
|
+
}
|
90
98
|
|
91
99
|
# this will include all named routes without further configuration
|
92
100
|
portlet.include_all_named_routes = true
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/* main.css */
|
2
2
|
|
3
3
|
body {
|
4
|
-
background-color:
|
4
|
+
background-color: gray;
|
5
5
|
}
|
6
6
|
|
7
7
|
/* testing leading whitespaces */
|
@@ -38,7 +38,7 @@ font: 14px Times New Roman;
|
|
38
38
|
|
39
39
|
/* used on css test page */
|
40
40
|
#simple_content {
|
41
|
-
margin: 25px; padding: 10px; border: 1px solid #000000; background:
|
41
|
+
margin: 25px; padding: 10px; border: 1px solid #000000; background: purple; color: white;
|
42
42
|
}
|
43
43
|
|
44
44
|
/* resource test page */
|
data/init.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
2
|
#--
|
5
|
-
# (c) Copyright 2008
|
3
|
+
# (c) Copyright 2008 - 2011 Mikael Lammentausta
|
4
|
+
# 2010 - 2011 Tulio Ornelas dos Santos
|
6
5
|
#
|
7
6
|
# See the file MIT-LICENSE included with the distribution for
|
8
7
|
# software license details.
|
9
8
|
#++
|
10
9
|
|
11
|
-
###
|
10
|
+
### Initializes the Rails2 plugin
|
12
11
|
|
13
12
|
file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
14
13
|
this_dir = File.dirname(File.expand_path(file))
|
@@ -16,21 +15,34 @@ this_dir = File.dirname(File.expand_path(file))
|
|
16
15
|
# load the main file
|
17
16
|
require File.join(this_dir, 'lib', 'caterpillar')
|
18
17
|
|
19
|
-
#STDERR.puts 'Caterpillar: version %s' % Caterpillar::VERSION
|
20
|
-
|
21
18
|
# Add Caterpillar portlet navigation to views paths
|
22
19
|
ActionController::Base.append_view_path File.join(this_dir, 'views')
|
23
20
|
|
21
|
+
# Detect Rails version to use proper load commands
|
22
|
+
v = RailsGemChooser.version
|
23
|
+
raise 'Unable to detect available Rails version' unless v
|
24
|
+
rails_version = v.gsub('.','').to_i
|
25
|
+
|
24
26
|
### Initialize the portlet test bench
|
25
27
|
|
26
28
|
# Adding directories to the load path makes them appear just like files in the the main app directory.
|
27
29
|
%w{ controllers helpers }.each do |path|
|
28
|
-
|
30
|
+
if rails_version > 238
|
31
|
+
# this changed between 2.3.8 and 2.3.10
|
32
|
+
ActiveSupport::Dependencies.autoload_paths << File.join(this_dir, 'portlet_test_bench', path)
|
33
|
+
else
|
34
|
+
ActiveSupport::Dependencies.load_paths << File.join(this_dir, 'portlet_test_bench', path)
|
35
|
+
end
|
29
36
|
end
|
30
37
|
|
31
38
|
# Removing a directory from the load once paths allow changes
|
32
39
|
# to be picked up as soon as you save the file – without having to restart the web server.
|
33
|
-
|
40
|
+
if rails_version > 238
|
41
|
+
# this changed between 2.3.8 and 2.3.10
|
42
|
+
ActiveSupport::Dependencies.autoload_once_paths.delete(File.join(this_dir, 'portlet_test_bench'))
|
43
|
+
else
|
44
|
+
ActiveSupport::Dependencies.load_once_paths.delete(File.join(this_dir, 'portlet_test_bench'))
|
45
|
+
end
|
34
46
|
|
35
47
|
# Add views
|
36
48
|
ActionController::Base.append_view_path File.join(this_dir, 'portlet_test_bench','views')
|
data/lib/caterpillar.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#--
|
3
|
-
# (c) Copyright 2008-
|
4
|
-
#
|
3
|
+
# (c) Copyright 2008 - 2011 Mikael Lammentausta
|
4
|
+
# 2010 Tulio Ornelas dos Santos
|
5
5
|
#
|
6
6
|
# See the file MIT-LICENSE included with the distribution for
|
7
7
|
# software license details.
|
8
8
|
#++
|
9
9
|
|
10
|
-
module Caterpillar
|
11
|
-
VERSION = '1.
|
10
|
+
module Caterpillar
|
11
|
+
VERSION = '1.6.0' unless defined? Caterpillar::VERSION
|
12
12
|
end
|
13
13
|
|
14
|
+
STDOUT.puts 'Caterpillar: version %s' % Caterpillar::VERSION
|
15
|
+
|
14
16
|
this_file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
15
17
|
this_dir = File.dirname(File.expand_path(this_file))
|
16
18
|
|
@@ -32,30 +34,34 @@ require 'find'
|
|
32
34
|
require 'rake'
|
33
35
|
require 'rake/tasklib'
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
require File.join(this_dir,'rails_gem_chooser')
|
38
|
+
|
39
|
+
if (defined? RAILS_ROOT)
|
40
|
+
# ActiveRecord should be loaded at this point, before loading any of the models.
|
41
|
+
# However, this may conflict later when Rails' rake task activates the boot process.
|
42
|
+
# The correct versions should be loaded at this point.
|
43
|
+
RailsGemChooser.__load # detects the Rails config file from RAILS_ROOT
|
42
44
|
end
|
43
45
|
|
44
46
|
# include all ruby files
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
47
|
+
%w{
|
48
|
+
config
|
49
|
+
util
|
50
|
+
usage
|
51
|
+
task
|
52
|
+
security
|
53
|
+
portlet_support
|
54
|
+
portlet
|
55
|
+
parser
|
56
|
+
navigation
|
57
|
+
liferay
|
58
|
+
}.each do |src|
|
59
|
+
require File.join(this_dir, 'caterpillar', src+'.rb')
|
60
|
+
end
|
61
|
+
|
62
|
+
# these are used in Rails environment
|
63
|
+
if (defined? RAILS_ENV)
|
64
|
+
require File.join(this_dir, 'web', 'portlet.rb')
|
65
|
+
require File.join(this_dir, 'caterpillar', 'helpers', 'portlet.rb')
|
66
|
+
require File.join(this_dir, 'caterpillar', 'helpers', 'liferay.rb')
|
61
67
|
end
|
data/lib/caterpillar/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#--
|
3
3
|
# (c) Copyright 2008 Mikael Lammentausta
|
4
|
-
# See the file
|
4
|
+
# See the file MIT-LICENSE included with the distribution for
|
5
5
|
# software license details.
|
6
6
|
#++
|
7
7
|
|
@@ -41,6 +41,8 @@ module Caterpillar
|
|
41
41
|
attr_accessor :warbler_conf
|
42
42
|
|
43
43
|
attr_accessor :logger
|
44
|
+
|
45
|
+
attr_accessor :session_secret
|
44
46
|
|
45
47
|
# Sets sane defaults that are overridden in the config file.
|
46
48
|
def initialize(detect_configuration_file = true)
|
@@ -1,35 +1,129 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
2
|
+
#--
|
3
|
+
# Copyright (c) 2007-2011 Mikael Lammmentausta
|
4
|
+
# 2010 Tulio Ornelas dos Santos
|
5
|
+
#
|
6
|
+
# See the file MIT-LICENSE included with the distribution for
|
7
|
+
# software license details.
|
8
|
+
#++
|
3
9
|
|
4
10
|
require 'rubygems'
|
5
11
|
require 'action_controller'
|
6
12
|
|
7
|
-
module Caterpillar
|
8
|
-
module Helpers
|
13
|
+
module Caterpillar # :nodoc:
|
14
|
+
module Helpers # :nodoc:
|
9
15
|
|
10
16
|
# This module contains Rails helpers that provide methods to deal with various aspects
|
11
17
|
# of portlet functionality in Liferay.
|
12
|
-
#
|
13
|
-
# Currently this consists of things that were constructed whenever needed during development,
|
14
|
-
# and concidered general enough to be included here.
|
15
|
-
#
|
16
|
-
# link_to_liferay is deprecated, and is clearly a wrong way to solve the problem in question.
|
17
|
-
# A better way has been constructed, but it is not perfect due to its dependency on a specific portlet.
|
18
18
|
module Liferay
|
19
|
-
include ActionView::Helpers::UrlHelper
|
20
19
|
include ActionView::Helpers::TagHelper
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
include Portlet
|
21
|
+
|
22
|
+
class ResourceUrl
|
23
|
+
include ActionController::UrlWriter
|
24
|
+
|
25
|
+
require 'uri'
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
attr_accessor :resource_uri
|
28
|
+
attr_accessor :namespace
|
29
|
+
attr_accessor :options
|
30
|
+
attr_accessor :params
|
27
31
|
|
28
|
-
|
29
|
-
|
32
|
+
def initialize(base_url, namespace = '', options = {}, params = {})
|
33
|
+
@resource_uri = URI.parse(base_url)
|
34
|
+
@namespace = namespace
|
35
|
+
@options = options
|
36
|
+
@params = params
|
37
|
+
end
|
30
38
|
|
31
|
-
|
39
|
+
def to_s()
|
40
|
+
uri = @resource_uri.dup
|
41
|
+
if @options.values.compact.empty?
|
42
|
+
# pass
|
43
|
+
else
|
44
|
+
query = {}
|
45
|
+
# unpack query
|
46
|
+
unless uri.query.nil?
|
47
|
+
uri.query.split('&').map do |p| p.split('=').reduce {|k,v| query.update({k => v})} end
|
48
|
+
end
|
49
|
+
# since url_for can't handle modularized controllers at this point,
|
50
|
+
# offer an explicit route as a workaround.
|
51
|
+
if @options[:route]
|
52
|
+
route = @options[:route]
|
53
|
+
else
|
54
|
+
# need controller and action
|
55
|
+
options = @options.dup
|
56
|
+
options.update(:host => 'localhost') unless options[:host]
|
57
|
+
options.update(:only_path => true)
|
58
|
+
if options[:action].nil? then options.update(:action => 'index') end
|
59
|
+
route = url_for(options)
|
60
|
+
end
|
61
|
+
query.update('_%s_%s' % [@namespace,'railsRoute'] => route)
|
62
|
+
@params.each_pair do |k,v|
|
63
|
+
query.update('_%s_%s' % [@namespace,k] => v)
|
64
|
+
end
|
65
|
+
# pack query
|
66
|
+
uri.query = query.each_pair.map{|k,v| '%s=%s' % [k,v]}.join('&')
|
67
|
+
end
|
68
|
+
return '%s://%s:%i%s' % [uri.scheme, uri.host, uri.port, uri.request_uri]
|
69
|
+
end
|
32
70
|
|
71
|
+
end
|
72
|
+
|
73
|
+
def resource_url_cookie
|
74
|
+
cookies[:Liferay_resourceUrl]
|
75
|
+
end
|
76
|
+
|
77
|
+
def preferences_cookie
|
78
|
+
cookies[:Liferay_preferences]
|
79
|
+
end
|
80
|
+
|
81
|
+
# Get the Liferay UID from cookie.
|
82
|
+
def get_liferay_uid
|
83
|
+
uid_key = 'Liferay_UID'
|
84
|
+
unless cookies.nil? or cookies[uid_key].nil?
|
85
|
+
@uid = cookies[uid_key]
|
86
|
+
logger.debug("Liferay UID %s" % @uid)
|
87
|
+
else
|
88
|
+
logger.debug("UID key is not present in cookies %s" % cookies.inspect)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Get the Liferay GID from cookie.
|
93
|
+
def get_liferay_gid
|
94
|
+
gid_key = 'Liferay_GID'
|
95
|
+
unless cookies.nil? or cookies[gid_key].nil?
|
96
|
+
@gid = cookies[gid_key]
|
97
|
+
logger.debug("Liferay GID %s" % @gid)
|
98
|
+
else
|
99
|
+
logger.debug("GID key is not present in cookies %s" % cookies.inspect)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Formulate resource URL for Liferay.
|
104
|
+
# The request will be handled by serveResource().
|
105
|
+
# The cookie "Liferay_resourceUrl" should be automatically included into
|
106
|
+
# available cookies by "rails-portlet".
|
107
|
+
def liferay_resource_url(_params, resource_url=resource_url_cookie)
|
108
|
+
if resource_url.nil? then return raise "resource_url is needed!" end
|
109
|
+
params = _params.dup # create duplicate params, do not modify originals!
|
110
|
+
|
111
|
+
options = {
|
112
|
+
:controller => params.delete(:controller),
|
113
|
+
:action => params.delete(:action),
|
114
|
+
:route => params.delete(:route)
|
115
|
+
}
|
116
|
+
|
117
|
+
res = ResourceUrl.new(resource_url)
|
118
|
+
res.options = options
|
119
|
+
res.namespace = @namespace || namespace_cookie
|
120
|
+
res.params = params
|
121
|
+
#p res
|
122
|
+
return res.to_s
|
123
|
+
=begin
|
124
|
+
if options[:controller].nil? then return resource_url end
|
125
|
+
#if route_params[:action].nil? then action = :index end
|
126
|
+
url = "#{resource_url}&#{namespace}railsRoute=/#{path}"
|
33
127
|
unless params.empty?
|
34
128
|
url += '?'
|
35
129
|
params.keys.each do |key|
|
@@ -37,127 +131,30 @@ module Helpers
|
|
37
131
|
end
|
38
132
|
url.gsub!(/&$/, '')
|
39
133
|
end
|
40
|
-
|
41
134
|
url
|
135
|
+
=end
|
42
136
|
end
|
43
137
|
|
44
|
-
#
|
45
|
-
|
46
|
-
link_to(name, url_to_exit_portlet(options), html_options)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Formulates a link to Liferay. DEPRECATED.
|
138
|
+
# Gets portlet preferences from a cookie (Liferay_preferences) and generates
|
139
|
+
# a hash with it. Returns nil if cookie do not exists or the value is nil.
|
50
140
|
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
redirect = 'javascript: history.go(-1)'
|
59
|
-
|
60
|
-
title = 'n/a' # link title
|
61
|
-
begin
|
62
|
-
logger.debug "Formulating Liferay link for #{obj}"
|
63
|
-
case obj.liferay_class
|
64
|
-
|
65
|
-
### group
|
66
|
-
when 'com.liferay.portal.model.Group'
|
67
|
-
STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
|
68
|
-
|
69
|
-
|
70
|
-
when 'com.liferay.portal.model.Layout'
|
71
|
-
STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
|
72
|
-
|
73
|
-
|
74
|
-
### user
|
75
|
-
when 'com.liferay.portal.model.User'
|
76
|
-
STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
|
77
|
-
|
78
|
-
|
79
|
-
### blog
|
80
|
-
when 'com.liferay.portlet.blogs.model.BlogsEntry'
|
81
|
-
STDERR.puts 'FIXME: %s.path' % obj
|
82
|
-
|
83
|
-
### document library file
|
84
|
-
#
|
85
|
-
# tämä toimii hiukan eri logiikalla kuin toiset, koska
|
86
|
-
# sama malli joutuu mallintamaan myös tyyppinsä tiedostopäätteestä
|
87
|
-
when 'com.liferay.portlet.documentlibrary.model.DLFileEntry'
|
88
|
-
STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
|
89
|
-
redirect_link=request.env["PATH_INFO"] # ei toimi portletissa
|
90
|
-
|
91
|
-
label = 'Tiedostotyyppiä %s ei vielä tueta' % obj.type[:name]
|
92
|
-
#_('Lataa tiedosto "%s"') % obj.asset.title
|
93
|
-
case obj.type[:uuid]
|
94
|
-
when :video
|
95
|
-
label = _('Linkki videoon "%s"') % obj.asset.title
|
96
|
-
link_to_exit_portlet( label, url_for(
|
97
|
-
{ :controller => :video,
|
98
|
-
:action => :asset,
|
99
|
-
:id => obj.asset.id,
|
100
|
-
:uid => @user.id,
|
101
|
-
:redirect => redirect_link
|
102
|
-
}))
|
103
|
-
|
104
|
-
when :pdf
|
105
|
-
label = _('Linkki dokumenttiin "%s"') % obj.asset.title
|
106
|
-
redirect = ''
|
107
|
-
url = LiferayUrl.new(obj,nil,redirect).static_url
|
108
|
-
link_to_exit_portlet( label, url )
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
### galleriakuva
|
114
|
-
when 'com.liferay.portlet.imagegallery.model.IGImage'
|
115
|
-
STDERR.puts 'FIXME: %s.path' % obj
|
116
|
-
base_url = "#{$LIFERAY_SERVER}/image/image_gallery"
|
117
|
-
options.update(:use_large_igpreview => false) unless options[:use_large_igpreview]
|
118
|
-
img_id = (options[:use_large_igpreview] == true ? obj.large.id : obj.small.id)
|
119
|
-
|
120
|
-
img = link_to_exit_portlet(
|
121
|
-
image_tag( "#{base_url}?img_id=#{img_id}", :alt => obj.description, :class => 'asset_image' ),
|
122
|
-
"#{base_url}?img_id=#{obj.large.id}"
|
123
|
-
)
|
124
|
-
logger.debug img
|
125
|
-
return img
|
126
|
-
|
127
|
-
|
128
|
-
when 'com.liferay.portlet.journal.model.JournalArticle'
|
129
|
-
STDERR.puts 'FIXME: %s.path' % obj
|
130
|
-
url = LiferayUrl.new(obj,@user,redirect).instance_url
|
131
|
-
link_to_exit_portlet( _('Lue koko artikkeli "%s"') % obj.asset.title, url )
|
132
|
-
|
133
|
-
when 'com.liferay.portlet.messageboards.model.MBCategory'
|
134
|
-
STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
|
135
|
-
|
136
|
-
|
137
|
-
when 'com.liferay.portlet.messageboards.model.MBMessage'
|
138
|
-
STDERR.puts 'FIXME: %s.path' % obj
|
139
|
-
url = LiferayUrl.new(obj,@user,redirect).instance_url
|
140
|
-
link_to_exit_portlet( _('Lue viesti "%s"') % obj.asset.title, url )
|
141
|
-
|
142
|
-
# when 'com.liferay.portlet.messageboards.model.MBThread'
|
143
|
-
|
144
|
-
when 'com.liferay.portlet.wiki.model.WikiPage'
|
145
|
-
STDERR.puts 'FIXME: %s.path' % obj
|
146
|
-
url = LiferayUrl.new(obj,@user,redirect).instance_url
|
147
|
-
link_to_exit_portlet( _('Lue sivu "%s"') % obj.asset.title, url )
|
148
|
-
|
149
|
-
else
|
150
|
-
STDERR.puts 'Called DEPRECATED method, but no method can handle %s' % obj
|
151
|
-
raise _('This type of link cannot be handled.')
|
152
|
-
|
141
|
+
def get_liferay_preferences(value = preferences_cookie)
|
142
|
+
preferences = {}
|
143
|
+
if value and (not value.empty?)
|
144
|
+
value.split(";").each do |pair|
|
145
|
+
if pair.nil? or pair.empty? then next end
|
146
|
+
result = pair.split("=")
|
147
|
+
preferences[result[0].intern] = result[1]
|
153
148
|
end
|
154
|
-
|
155
|
-
rescue Exception => err
|
156
|
-
logger.error '*** ERROR ***: %s' % err.message
|
157
|
-
link_to_function( _('Cannot link to resource.'), "alert('#{err.message}')" )
|
149
|
+
return preferences
|
158
150
|
end
|
151
|
+
nil
|
159
152
|
end
|
160
153
|
|
154
|
+
# Link that the rails-portlet will leave unparsed.
|
155
|
+
def link_to_exit_portlet(name, options = {}, html_options = {})
|
156
|
+
link_to(name, url_to_exit_portlet(options), html_options)
|
157
|
+
end
|
161
158
|
|
162
159
|
# Appends parameters "exit_portlet=true" into the url.
|
163
160
|
# Url might be either Hash or String.
|
@@ -182,4 +179,4 @@ module Helpers
|
|
182
179
|
|
183
180
|
end
|
184
181
|
end
|
185
|
-
end
|
182
|
+
end
|