caterpillar 1.2.5 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,7 +1,17 @@
1
+ = 1.3.1
2
+ - rename xml task to makexml, and call it with deploy:xml
3
+ - many small fixes to various tasks
4
+ - XML is validated with Liferay DTD and portlet-app XSD
5
+ - silence deprecation warnings from Rails gem chooser
6
+
7
+ = 1.3.0
8
+ - New helpers to generate resource urls (download) and get_liferay_preferences, to get the preferences
9
+ - edit_mode and instanceable working on portlet configuration
10
+ - Modifications on portlet-ext.xml (new filter and RESOURCE_PHASE)
11
+
1
12
  = 1.2.5
2
13
  - Ruby 1.9 compatibility fix
3
14
  - define utf8 encoding (thanks to Hendie Dijkman for mentioning about it)
4
-
5
15
  = 1.2.4
6
16
  - use standalone Rails defaults in the installed config file
7
17
  - updated xUnit tests in the portlet test bench
data/README.rdoc CHANGED
@@ -14,11 +14,23 @@ For developers:
14
14
  * a Rails view helper which lists portlets during development
15
15
 
16
16
 
17
- == Quickstart
18
- NOTE: *Rubygems does not seem to get the most uptodate version.* The release should be >= 1.2.3.
19
- Please download the latest release from Rubyforge.
17
+ = Quickstart
18
+ == The new path
19
+ You'll need at least the version 1.3.0.
20
20
 
21
- $ gem install caterpillar-1.2.3.gem
21
+ $ gem install caterpillar-1.3.0.gem
22
+
23
+ Start up a new Rails project:
24
+
25
+ $ caterpillar rails example
26
+
27
+ It's all you need =].
28
+
29
+
30
+ == The old way
31
+ Rubygems is fixed, but the most recent stable release is 1.2.5.
32
+
33
+ $ gem install caterpillar
22
34
 
23
35
  Start up a new Rails project:
24
36
 
@@ -88,4 +100,116 @@ Here are the most useful tasks; see the rdoc documentation and caterpillar --des
88
100
 
89
101
 
90
102
  Join the bugs mailing list (http://rubyforge.org/mailman/listinfo/rails-portlet-bugs) to request help.
103
+
104
+ = How to implement
105
+
106
+ == File Download
107
+
108
+ In order to use download links in your webpages, you need to use the method:
109
+ send_file(file_path, :filename=>"filename")
110
+
111
+ For example, on DownloadController, 'start' method allows the download of 'image.jpg' file.
112
+ def start
113
+ send_file('../images/image.jpg', :filename => "image.jpg")
114
+ end
115
+
116
+ In your webpage, you should use the following method which will manage your urls:
117
+ liferay_resource_url(:controller=> :controllerName, :action=> :methodName)
118
+
119
+ It should look like:
120
+ <%= link_to "Download", liferay_resource_url(:controller => :download , :action => :start) %>
121
+
122
+ To access the +liferay_resource_url+ method you will need to include the Liferay module in your application_helper
123
+ include Caterpillar::Helpers::Liferay
124
+
125
+ This method will generate a valid url for +serveResource+ method in liferay
126
+
127
+ == Portlet Preferences
128
+
129
+ To enable portlet preferences we need to set <b>:edit_mode</b> as true on <em>portlet.rb</em> file.
130
+ We have two kinds of portlets, the instanceable ones and not instaceables ones. Each instaceable portlet holds it's own preferences otherwise not instanceable has just one definition, keeping the same data into all portlets of the kind.
131
+ portlet.instances << {
132
+ :name => 'test',
133
+ :edit_mode => true,
134
+ :instanceable => false
135
+ }
136
+
137
+ Each mapped portlet requires a <b>preferences</b> method which will handle the edit mode features.
138
+ For example:
139
+ def preferences
140
+ if request.post?
141
+ flash[:notice] = 'Success!'
142
+ end
143
+ end
144
+
145
+ Rails-portlet will provide us a hash with all saved preferences, to access this method we need to include the Caterpillar::PortletSupport module, like:
146
+ include Caterpillar::PortletSupport
147
+
148
+ 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:
149
+ class ApplicationController < ActionController::Base
150
+ include Caterpillar::PortletSupport
151
+
152
+ helper :all # include all helpers, all the time
153
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
154
+
155
+ before_filter :get_preferences
156
+
157
+ protected
158
+ def get_preferences
159
+ preferences = get_liferay_preferences
160
+ @preferences = preferences ? preferences : {}
161
+ end
162
+
163
+ end
164
+
165
+ In your erb file you will have a form like this, where each attribute (that has to be saved) needs to have prefix <b>_preference</b> on its name. For example:
166
+ <% form_tag :controller => :test , :action => :preferences do %>
167
+ <p>
168
+ Cor de fundo: <%= text_field_tag :background_color_preference, @preferences[:background_color_preference] %>
169
+ </p>
170
+ <p>
171
+ Tamanho fonte: <%= text_field_tag :font_size_preference, @preferences[:font_size_preference] %>
172
+ </p>
173
+ <p>
174
+ Cor da fonte: <%= text_field_tag :font_color_preference, @preferences[:font_color_preference] %>
175
+ </p>
176
+ <%= submit_tag "Salve" %>
177
+ <% end %>
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
+
211
+
212
+
213
+
214
+
91
215
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+ load 'caterpillar.gemspec'
4
6
 
5
7
  desc 'Default: create API doc.'
6
8
  task :default => :rdoc
@@ -15,5 +17,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
15
17
  rdoc.rdoc_files.include('generators/**/*.rb')
16
18
  rdoc.options << '--line-numbers' << '--inline-source' << '-U'
17
19
  end
18
-
19
-
data/bin/caterpillar CHANGED
@@ -33,7 +33,7 @@ application.standard_exception_handling do
33
33
 
34
34
  # Load the main tasks - choose the namespace
35
35
  Caterpillar::Task.new(ARGV[0] ? ARGV[0].gsub(/:.*/,'') : :usage)
36
-
36
+
37
37
  task :default => :usage
38
38
 
39
39
  application.top_level
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
-
3
-
4
2
  Caterpillar::Config.new do |portlet|
5
3
 
6
4
  # JRUBY_HOME can be set here, unless the environment variable can be used.
@@ -20,7 +18,7 @@ Caterpillar::Config.new do |portlet|
20
18
  #
21
19
  # No changes are made to any of the files in this directory while making XML,
22
20
  # only the deploy and install tasks make any changes.
23
- # portlet.container.root = '/usr/local/liferay/'
21
+ # portlet.container.root = '/usr/local/liferay/tomcat/'
24
22
 
25
23
  # The server that the container is running on.
26
24
  # Possible values:
@@ -33,8 +31,8 @@ Caterpillar::Config.new do |portlet|
33
31
  # By default the first entry in the directory is chosen.
34
32
  # portlet.container.server_dir = 'default'
35
33
 
36
- # Allow to defining the deploy_dir - both the WAR file and the XML files
37
- # are deployed under this directory.
34
+ # Allow to defining the deploy_dir - just the WAR file will be deployed under this directory.
35
+ # Since version 1.3.0
38
36
  # portlet.container.deploy_dir = '/opt/myDeployDir'
39
37
 
40
38
  # The hostname and port.
@@ -61,14 +59,18 @@ Caterpillar::Config.new do |portlet|
61
59
  # Most likely you will want to let ActionController::Routing to set the route.
62
60
  #
63
61
  # Available keys are:
64
- # - :name -- named route
65
- # - :category -- portlet category (Liferay only)
66
- # - :title -- the title in portlet container's category (Liferay only)
67
- # - :javascripts -- portlet-specific javascripts that are included at
68
- # the head of master HTML, such as body onload functions (Liferay only)
69
- # - :host -- hostname:port of the deployment server
70
- # - :servlet -- by default, the name of the Rails app (= name of the WAR package)
71
- # - :path -- unless you're using named routes, you can define the path here
62
+ # - :name -- named route
63
+ # - :category -- portlet category (Liferay only)
64
+ # - :title -- the title in portlet container's category (Liferay only)
65
+ # - :edit_mode -- enables edit mode for the portlet, adds <portlet-mode>edit</portlet-mode> to portlet-ext.xml
66
+ # Default value is false
67
+ # - :instanceable -- enables instanceable for the portlet, add <instanceable>true</instanceable> to
68
+ # liferay-portlet-ext.xml. Default value is false
69
+ # - :javascripts -- portlet-specific javascripts that are included at
70
+ # the head of master HTML, such as body onload functions (Liferay only)
71
+ # - :host -- hostname:port of the deployment server
72
+ # - :servlet -- by default, the name of the Rails app (= name of the WAR package)
73
+ # - :path -- unless you're using named routes, you can define the path here
72
74
 
73
75
  # Rails-portlet testing application.
74
76
  # NOTE: this needs to be activated by 'map.caterpillar' in RAILS_ROOT/config/routes.rb
data/lib/caterpillar.rb CHANGED
@@ -1,15 +1,14 @@
1
1
  # encoding: utf-8
2
-
3
-
4
2
  #--
5
3
  # (c) Copyright 2008-2010 Mikael Lammentausta
4
+ # 2010 Túlio Ornelas
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
  module Caterpillar
12
- VERSION='1.2.5'
11
+ VERSION='1.3.1'
13
12
  end
14
13
 
15
14
  this_file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
@@ -18,6 +18,10 @@ module Caterpillar
18
18
 
19
19
  attr_accessor :category
20
20
 
21
+ attr_accessor :edit_mode
22
+
23
+ attr_accessor :instanceable
24
+
21
25
  attr_accessor :host
22
26
 
23
27
  attr_accessor :servlet
@@ -6,6 +6,7 @@ require 'action_controller'
6
6
 
7
7
  module Caterpillar
8
8
  module Helpers
9
+
9
10
  # This module contains Rails helpers that provide methods to deal with various aspects
10
11
  # of portlet functionality in Liferay.
11
12
  #
@@ -18,6 +19,28 @@ module Helpers
18
19
  include ActionView::Helpers::UrlHelper
19
20
  include ActionView::Helpers::TagHelper
20
21
 
22
+ def liferay_resource_url(params, resource_url = cookies[:Liferay_resourceUrl])
23
+ if resource_url.nil? then return raise "resource_url is needed!" end
24
+
25
+ controller = params.delete :controller
26
+ action = params.delete :action
27
+
28
+ if controller.nil? then return resource_url end
29
+ if action.nil? then action = :index end
30
+
31
+ url = "#{resource_url}&railsRoute=/#{controller}/#{action}"
32
+
33
+ unless params.empty?
34
+ url += '?'
35
+ params.keys.each do |key|
36
+ url += "#{key}=#{params[key]}&"
37
+ end
38
+ url.gsub!(/&$/, '')
39
+ end
40
+
41
+ url
42
+ end
43
+
21
44
  # Link that the rails-portlet will leave unparsed.
22
45
  def link_to_exit_portlet(name, options = {}, html_options = {})
23
46
  link_to(name, url_to_exit_portlet(options), html_options)
@@ -63,7 +63,7 @@ module Caterpillar # :nodoc:
63
63
  # Defaults to +Lportal::Schema.version+.
64
64
  def initialize(version=nil)
65
65
  @version = version
66
- @root = '/usr/local/liferay'
66
+ @root = '/usr/local/liferay-portal-5.2.3/tomcat-6.0.18' # as described in setup guide, when unpacked to /usr/local
67
67
  @server = 'Tomcat'
68
68
  @deploy_dir = nil
69
69
  end
@@ -137,8 +137,10 @@ module Caterpillar # :nodoc:
137
137
  # The @deploy_dir variable does not need checking,
138
138
  # as the method deploy_dir() does that.
139
139
  #if deploy_dir_defined?
140
-
141
- return File.join(self.deploy_dir(),root_dir,'WEB-INF')
140
+
141
+ #self.deploy_dir(),
142
+ # Xml files need to be in WEB-INF and not, for example, /opt/liferay/deploy
143
+ return File.join(File.join(self.root,'webapps'), root_dir,'WEB-INF')
142
144
  end
143
145
 
144
146
  # Reads Liferay portlet descriptor XML files and parses them with Hpricot.
@@ -278,26 +280,12 @@ module Caterpillar # :nodoc:
278
280
  '</%s>' % doctype
279
281
  end
280
282
 
281
- # TODO: DTD version detection based on self.version
283
+ # DTD version detection based on self.version
282
284
  def dtd_version(type)
283
- case type
284
- when 'liferay-portlet-app'
285
- if @version[/5.1/]
286
- '5.1.0'
287
- elsif @version[/5.2/]
288
- '5.2.0'
289
- else
290
- @version
291
- end
292
- when 'display'
293
- if @version[/5.1/]
294
- '5.1.0'
295
- elsif @version[/5.2/]
296
- '5.2.0'
297
- else
298
- @version
299
- end
300
- end
285
+ #case type
286
+ #when 'liferay-portlet-app'
287
+ #when 'display'
288
+ self.version[/.../] + '.0'
301
289
  end
302
290
 
303
291
  # liferay-portlet-ext definition
@@ -330,7 +318,7 @@ module Caterpillar # :nodoc:
330
318
  xml << " <use-default-template>true</use-default-template>\n"
331
319
 
332
320
  # can there be several portlet instances on the same page?
333
- xml << " <instanceable>false</instanceable>\n"
321
+ xml << " <instanceable>#{portlet[:instanceable]}</instanceable>\n"
334
322
 
335
323
  # The default value of ajaxable is true. If set to false, then this portlet can never be displayed via Ajax.
336
324
  xml << " <ajaxable>true</ajaxable>\n"
@@ -112,6 +112,9 @@ module Caterpillar
112
112
  title = _title.gsub(/ä/,'a').gsub(/ö/,'o').gsub(/Ä/,'A').gsub(/Ö/,'O')
113
113
  portlet.update( :title => title )
114
114
 
115
+ portlet[:edit_mode] ||= nil
116
+ portlet[:instanceable] ||= false
117
+
115
118
  ### unless defined, use default javascripts
116
119
  portlet[:javascripts] ||= @config.javascripts
117
120
 
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
-
3
-
4
2
  #--
5
3
  # (c) Copyright 2008, 2010 Mikael Lammentausta
6
4
  # See the file LICENSES.txt included with the distribution for
@@ -42,9 +40,9 @@ module Caterpillar
42
40
  'com.celamanzi.liferay.portlets.rails286.Rails286Portlet'
43
41
  end
44
42
 
45
- # Rails-portlet Java class
43
+ # Rails-portlet Java class for 0.10.0+
46
44
  def portlet_filter_class
47
- 'com.celamanzi.liferay.portlets.rails286.Rails286PortletRenderFilter'
45
+ 'com.celamanzi.liferay.portlets.rails286.Rails286PortletFilter'
48
46
  end
49
47
 
50
48
  # JSR 286 portlet XML header. Opens portlet-app.
@@ -80,8 +78,7 @@ module Caterpillar
80
78
  xml << " <supports>\n"
81
79
  xml << " <mime-type>text/html</mime-type>\n"
82
80
  xml << " <portlet-mode>view</portlet-mode>\n"
83
- # edit mode is not used. this is for development.
84
- if portlet[:edit]==true
81
+ if portlet[:edit_mode] == true
85
82
  xml << " <portlet-mode>edit</portlet-mode>\n"
86
83
  end
87
84
  xml << " </supports>\n"
@@ -89,6 +86,8 @@ module Caterpillar
89
86
  xml << " <portlet-info>\n"
90
87
  xml << " <title>%s</title>\n" % portlet[:title]
91
88
  xml << " </portlet-info>\n"
89
+ ### init parameters, XXX: fails xsd test
90
+ #=begin
92
91
  # insert session key
93
92
  unless session.nil?
94
93
  xml << " <init-param>\n"+\
@@ -103,6 +102,7 @@ module Caterpillar
103
102
  " <value>#{session[:secret]}</value>\n"+\
104
103
  " </init-param>\n"
105
104
  end
105
+ #=end
106
106
  roles.each do |role|
107
107
  xml << " <security-role-ref>\n"
108
108
  xml << " <role-name>#{role}</role-name>\n"
@@ -116,6 +116,8 @@ module Caterpillar
116
116
  xml << " <filter-name>%s_filter</filter-name>\n" % portlet[:name]
117
117
  xml << " <filter-class>%s</filter-class>\n" % self.portlet_filter_class
118
118
  xml << " <lifecycle>RENDER_PHASE</lifecycle>\n"
119
+ xml << " <lifecycle>RESOURCE_PHASE</lifecycle>\n"
120
+
119
121
  # define host, servlet and route (path to be more precise)
120
122
  xml << " <init-param>\n"
121
123
  xml << " <name>host</name>\n"
@@ -129,6 +131,7 @@ module Caterpillar
129
131
  xml << " <name>route</name>\n"
130
132
  xml << " <value>%s</value>\n" % portlet[:path].gsub(/&/,"&amp;")
131
133
  xml << " </init-param>\n"
134
+
132
135
  xml << " </filter>\n\n"
133
136
 
134
137
  xml << " <filter-mapping>\n"
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ module Caterpillar
4
+
5
+ # Add some portlet support
6
+ #
7
+ module PortletSupport
8
+
9
+ # Gets portlet preferences from a cookie (Liferay_preferences) and generates
10
+ # a hash with it. Returns nil if cookie do not exists or the value is nil.
11
+ #
12
+ def get_liferay_preferences(value = cookies[:Liferay_preferences])
13
+ preferences = {}
14
+ if value and (not value.empty?)
15
+ value.split(";").each do |pair|
16
+ if pair.nil? or pair.empty? then next end
17
+
18
+ result = pair.split("=")
19
+ preferences[result[0].intern] = result[1]
20
+
21
+ end
22
+ return preferences
23
+ end
24
+
25
+ nil
26
+ end
27
+
28
+ end
29
+ end