caterpillar 0.9.8 → 0.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,44 +1,67 @@
1
+ = 0.9.15
2
+ - use rails-portlet 0.6.0 in Liferay 5.1.1
3
+ - moved all migrations to lportal, now executes lportal migrations
4
+ - db:rollback and db:migrate required!!
5
+ - detect the version of Liferay from Lportal::Schema
6
+ - option to set JRUBY_HOME in the config file
7
+ - collect data whether portlet is instanceable
8
+ - exit on error when installing the JAR
9
+ - notify if the config file does not exist
10
+ - use Liferay as the default container
11
+ - load helpers only in Rails environment
12
+ - Web::Portlet.find_caterpillar_portlet
13
+ - moved some portlet methods to lportal
14
+
15
+
16
+ = 0.9.11
17
+ - fixed a gem loading bug with Ruby 1.8.5
18
+ - load helpers only in Rails environment
19
+ - small random fixes
20
+
21
+
1
22
  = 0.9.8
2
- - fix problem with subcategories in liferay-display.xml
3
- - model Rails portlets as Web::Portlets
23
+ - fix problem with subcategories in liferay-display.xml
24
+ - model Rails portlets as Web::Portlets
4
25
 
5
26
 
6
27
  = 0.9.7
7
- - display version in navigation view
8
- - comply link_to_exit_portlet with link_to api
28
+ - display version in navigation view
29
+ - comply link_to_exit_portlet with link_to api
9
30
 
10
31
 
11
32
  = 0.9.6
12
- - added some tables and a notice to sequence migrations
13
- - no longer installs css and javascript files, everything is cramped inline into the view
14
- - upgrade lportal dependency to version 1.0.9
33
+ - added some tables and a notice to sequence migrations
34
+ - no longer installs css and javascript files, everything is cramped inline into the view
35
+ - upgrade lportal dependency to version 1.0.9
15
36
 
16
37
 
17
38
  = 0.9.5
18
- - portlet xml definition to Liferay 5.2.0 standards
19
- - liferay xml files are tagged by selection based on the configured version
20
- - portlet jar installation based on Liferay version
21
- - Upgrade to rails-portlet 0.6.1 for Liferay 5.2.x
22
- - Fixed the sequences migration
23
- - include ActionView helpers, raise an error if given exit_portlet url is nil
24
- - fixed a small bug with inline JS parsing
39
+ - portlet xml definition to Liferay 5.2.0 standards
40
+ - liferay xml files are tagged by selection based on the configured version
41
+ - portlet jar installation based on Liferay version
42
+ - Upgrade to rails-portlet 0.6.1 for Liferay 5.2.x
43
+ - Fixed the sequences migration
44
+ - include ActionView helpers, raise an error if given exit_portlet url is nil
45
+ - fixed a small bug with inline JS parsing
25
46
 
26
47
 
27
48
  = 0.9.4
28
- - Web::PortletNames migrations + model
29
- - random small fixes
49
+ - Web::PortletNames migrations + model
50
+ - random small fixes
30
51
 
31
52
 
32
53
  = 0.9.2
33
- - fixed a problem with navigation; enhanced css
34
- - deployment task
54
+ - fixed a problem with navigation; enhanced css
55
+ - deployment task
35
56
 
36
57
 
37
58
  = 0.9.1
38
59
  Released at 2008-12-18
39
- - task to install the Rails-portlet
60
+ - task to install the Rails-portlet
40
61
 
41
62
 
42
63
  = 0.9.0
43
64
  Released at 2008-12-17
44
- - the initial release
65
+ - the initial release
66
+
67
+
File without changes
@@ -1,5 +1,8 @@
1
1
  Caterpillar::Config.new do |portlet|
2
2
 
3
+ # JRUBY_HOME can be set here, unless the environment variable can be used.
4
+ # portlet.class::JRUBY_HOME = '/usr/local/jruby'
5
+
3
6
  # The portlet container.
4
7
  # By default only portlet.xml is created.
5
8
  # Currently only Liferay is supported. You may optionally define the version.
@@ -43,19 +46,19 @@ Caterpillar::Config.new do |portlet|
43
46
  # - :name -- named route
44
47
  # - :category -- portlet category (Liferay only)
45
48
  # - :title -- the title in portlet container's category (Liferay only)
46
- # - :javascripts -- portlet-specific javascripts that are not in the HTML head section (Liferay only)
47
- # - :host
48
- # - :servlet
49
+ # - :javascripts -- portlet-specific javascripts that are included at
50
+ # the head of master HTML, such as body onload functions (Liferay only)
51
+ # - :host -- hostname:port of the deployment server
52
+ # - :servlet -- by default, the name of the Rails app (= name of the WAR package)
49
53
  # - :path -- unless you're using named routes, you can define the path here
50
54
 
51
- # example:
52
- # portlet.instances << {
53
- # :name => 'rails286_test',
54
- # :title => 'Rails-portlet testing application',
55
- # :category => 'Testing',
56
- # :servlet => 'RailsTestBench',
57
- # :path => '/'
58
- # }
55
+ # Rails-portlet testing application:
56
+ portlet.instances << {
57
+ :name => 'test',
58
+ :title => 'Rails-portlet testing application',
59
+ :category => 'Caterpillar',
60
+ :path => '/RailsTestBench'
61
+ }
59
62
 
60
63
  # this will include all named routes without further configuration
61
64
  portlet.include_all_named_routes = true
@@ -1,17 +1,17 @@
1
1
  #--
2
- # (c) Copyright 2008 Mikael Lammentausta
2
+ # (c) Copyright 2008,2009 Mikael Lammentausta
3
3
  # See the file LICENSES.txt included with the distribution for
4
4
  # software license details.
5
5
  #++
6
6
 
7
7
  module Caterpillar
8
- VERSION='0.9.8'
8
+ VERSION='0.9.15'
9
9
  end
10
10
 
11
11
  this_file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
12
12
  this_dir = File.dirname(File.expand_path(this_file))
13
13
 
14
- CATERPILLAR_LIBS=this_dir
14
+ CATERPILLAR_LIBS=this_dir unless defined?(CATERPILLAR_LIBS)
15
15
 
16
16
  require 'find'
17
17
 
@@ -20,6 +20,11 @@ Find.find(this_dir) do |file|
20
20
  if FileTest.directory?(file)
21
21
  if File.basename(file) == 'deprecated'
22
22
  Find.prune # Don't look any further into this directory.
23
+
24
+ # load helpers only in Rails environment
25
+ elsif (!defined?(RAILS_ENV) and (File.basename(file) == 'helpers'))
26
+ Find.prune
27
+
23
28
  else
24
29
  next
25
30
  end
@@ -7,7 +7,8 @@
7
7
  module Caterpillar
8
8
  # Portlet configuration. The config file 'config/portlets.rb' should be installed in your Rails application. See the comments in the configuration file for more specific information about each option.
9
9
  class Config
10
- FILE = "config/portlets.rb"
10
+ FILE = File.join('config','portlets.rb')
11
+ JRUBY_HOME = nil # override in the config file if necessary
11
12
 
12
13
  # Are all named routes used, or only the ones specifically defined in the config FILE?
13
14
  attr_accessor :include_all_named_routes
@@ -30,6 +31,8 @@ module Caterpillar
30
31
 
31
32
  attr_accessor :warbler_conf
32
33
 
34
+ attr_accessor :logger
35
+
33
36
  # Sets sane defaults that are overridden in the config file.
34
37
  def initialize
35
38
  @rails_root = File.expand_path(defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.getwd)
@@ -39,15 +42,17 @@ module Caterpillar
39
42
  @javascripts = []
40
43
  @include_all_named_routes = true
41
44
  @warbler_conf = File.join(@rails_root,'config','warble.rb')
45
+ STDERR.puts 'Warbler configuration file could not be found' unless File.exists?(@warbler_conf)
46
+ #@logger = (defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new)
42
47
 
43
48
  yield self if block_given?
44
49
  end
45
50
 
46
51
  # The container class is used for parsing XML files.
47
52
  #
48
- # Possible values: Liferay
53
+ # Possible values: Liferay (default)
49
54
  def container
50
- self._container
55
+ self._container || Caterpillar::Liferay.new
51
56
  end
52
57
 
53
58
  # Accepts the configuration option, and instantates the container class.
@@ -1,15 +1,31 @@
1
+ require 'rubygems'
2
+ require 'action_controller'
3
+
1
4
  module Caterpillar
2
5
  module Helpers
6
+ # This module contains Rails helpers that provide methods to deal with various aspects
7
+ # of portlet functionality in Liferay.
8
+ #
9
+ # Currently this consists of things that were constructed whenever needed during development,
10
+ # and concidered general enough to be included here.
11
+ #
12
+ # link_to_liferay is deprecated, and is clearly a wrong way to solve the problem in question.
13
+ # A better way has been constructed, but it is not perfect due to its dependency on a specific portlet.
3
14
  module Liferay
4
15
  include ActionView::Helpers::UrlHelper
5
16
  include ActionView::Helpers::TagHelper
6
17
 
7
- # Formulates a link to Liferay.
18
+ # Link that the rails-portlet will leave unparsed.
19
+ def link_to_exit_portlet(name, options = {}, html_options = {})
20
+ link_to(name, url_to_exit_portlet(options), html_options)
21
+ end
22
+
23
+ # Formulates a link to Liferay. DEPRECATED.
24
+ #
8
25
  # Parameters:
9
26
  # - obj is an instance of a model from the lportal library.
10
27
  # - options
11
28
  def link_to_liferay(obj,options={})
12
- options.update(:use_large_igpreview => false) unless options[:use_large_igpreview]
13
29
 
14
30
  # Rails-portlet cannot pass the actual redirect parameter.
15
31
  # Workaround with JavaScript.
@@ -17,68 +33,33 @@ module Helpers
17
33
 
18
34
  title = 'n/a' # link title
19
35
  begin
20
- STDERR.puts 'This method is DEPRECATED - use obj.path instead'
21
36
  logger.debug "Formulating Liferay link for #{obj}"
22
37
  case obj.liferay_class
23
38
 
24
39
  ### group
25
40
  when 'com.liferay.portal.model.Group'
26
- # title = (obj.name.empty? ? obj.owner.fullname : obj.name)
27
- # urls = LiferayUrl.new(obj,nil,nil).static_url
28
- # logger.debug urls
29
- # if options[:private]
30
- # label = _('yksityiset sivut')
31
- # urls[:private] ?
32
- # link_to_exit_portlet( label, urls[:private] ) :
33
- # link_to_function(
34
- # label, "alert('%s')" % _('Yhteisöllä ei ole yksityisiä sivuja'))
35
- # else
36
- # label = _('julkiset sivut')
37
- # urls[:public] ?
38
- # link_to_exit_portlet( label, urls[:public] ) :
39
- # link_to_function(
40
- # label, "alert('%s')" % _('Yhteisöllä ei ole julkisia sivuja'))
41
- # end
42
-
43
-
44
- # siirretty malliin
45
- # when 'com.liferay.portal.model.Layout'
46
- # url = LiferayUrl.new(obj).static_url
47
- # return url_to_exit_portlet(url)
41
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
42
+
43
+
44
+ when 'com.liferay.portal.model.Layout'
45
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
48
46
 
49
47
 
50
48
  ### user
51
49
  when 'com.liferay.portal.model.User'
52
- # urls = LiferayUrl.new(obj,nil,nil).static_url
53
- # #logger.debug urls
54
- # if options[:private]
55
- # label = options[:label]
56
- # label ||= _('yksityiset sivut')
57
- # urls[:private] ?
58
- # link_to_exit_portlet( label, urls[:private] ) :
59
- # link_to_function(
60
- # label, "alert('%s')" % _('Tunnuksella ei ole yksityisiä sivuja'))
61
- # else
62
- # label = options[:label] || _('julkiset sivut')
63
- # urls[:public] ?
64
- # link_to_exit_portlet( label, urls[:public] ) :
65
- # link_to_function(
66
- # label, "alert('%s')" % _('Tunnuksella ei ole julkisia sivuja'))
67
- # end
50
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
68
51
 
69
52
 
70
53
  ### blog
71
54
  when 'com.liferay.portlet.blogs.model.BlogsEntry'
72
- # title = _('Linkki blogimerkintään "%s"') % obj.title
73
- # url = LiferayUrl.new(obj,@user,redirect).instance_url
74
- # link_to_exit_portlet( title, url )
75
-
55
+ STDERR.puts 'FIXME: %s.path' % obj
76
56
 
77
57
  ### document library file
78
58
  #
79
59
  # tämä toimii hiukan eri logiikalla kuin toiset, koska
80
60
  # sama malli joutuu mallintamaan myös tyyppinsä tiedostopäätteestä
81
61
  when 'com.liferay.portlet.documentlibrary.model.DLFileEntry'
62
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
82
63
  redirect_link=request.env["PATH_INFO"] # ei toimi portletissa
83
64
 
84
65
  label = 'Tiedostotyyppiä %s ei vielä tueta' % obj.type[:name]
@@ -105,7 +86,9 @@ module Helpers
105
86
 
106
87
  ### galleriakuva
107
88
  when 'com.liferay.portlet.imagegallery.model.IGImage'
89
+ STDERR.puts 'FIXME: %s.path' % obj
108
90
  base_url = "#{$LIFERAY_SERVER}/image/image_gallery"
91
+ options.update(:use_large_igpreview => false) unless options[:use_large_igpreview]
109
92
  img_id = (options[:use_large_igpreview] == true ? obj.large.id : obj.small.id)
110
93
 
111
94
  img = link_to_exit_portlet(
@@ -117,48 +100,47 @@ module Helpers
117
100
 
118
101
 
119
102
  when 'com.liferay.portlet.journal.model.JournalArticle'
103
+ STDERR.puts 'FIXME: %s.path' % obj
120
104
  url = LiferayUrl.new(obj,@user,redirect).instance_url
121
105
  link_to_exit_portlet( _('Lue koko artikkeli "%s"') % obj.asset.title, url )
122
106
 
123
107
  when 'com.liferay.portlet.messageboards.model.MBCategory'
124
- # url = LiferayUrl.new(obj,@user,redirect).static_url
125
- # link_to_exit_portlet( obj.name, url )
108
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
126
109
 
127
110
 
128
111
  when 'com.liferay.portlet.messageboards.model.MBMessage'
112
+ STDERR.puts 'FIXME: %s.path' % obj
129
113
  url = LiferayUrl.new(obj,@user,redirect).instance_url
130
114
  link_to_exit_portlet( _('Lue viesti "%s"') % obj.asset.title, url )
131
115
 
132
116
  # when 'com.liferay.portlet.messageboards.model.MBThread'
133
117
 
134
- when 'com.liferay.portlet.wiki.model.WikiNode'
135
- logger.debug "WikiNode"
136
- # url = LiferayUrl.new(obj,@user,redirect).instance_url
137
- # link_to_exit_portlet( _('Lue sivu "%s"') % obj.asset.title, url )
138
-
139
118
  when 'com.liferay.portlet.wiki.model.WikiPage'
140
- logger.debug "WikiPage"
119
+ STDERR.puts 'FIXME: %s.path' % obj
141
120
  url = LiferayUrl.new(obj,@user,redirect).instance_url
142
121
  link_to_exit_portlet( _('Lue sivu "%s"') % obj.asset.title, url )
143
122
 
144
123
  else
145
- logger.debug obj.liferay_class
146
- raise _('Tämän tyyppistä linkkiä ei vielä hallita')
124
+ STDERR.puts 'Called DEPRECATED method, but no method can handle %s' % obj
125
+ raise _('This type of link cannot be handled.')
147
126
 
148
127
  end
149
128
 
150
129
  rescue Exception => err
151
130
  logger.error '*** ERROR ***: %s' % err.message
152
- link_to_function( _('Kohteeseen ei voi linkittää.'), "alert('#{err.message}')" )
131
+ link_to_function( _('Cannot link to resource.'), "alert('#{err.message}')" )
153
132
  end
154
133
  end
155
134
 
156
135
 
136
+ # Appends parameters "exit_portlet=true" into the url.
137
+ # Url might be either Hash or String.
157
138
  def url_to_exit_portlet(url)
158
- directive = { :exit_portlet => 'true' }
139
+ parameters = { :exit_portlet => 'true' }
159
140
 
141
+ # append parameters to the url
160
142
  if url.is_a? Hash
161
- url.update directive
143
+ url.update parameters
162
144
 
163
145
  elsif url.is_a? String
164
146
  if url[/\?[\w]*\=/] # url has parameters
@@ -166,18 +148,12 @@ module Helpers
166
148
  else # no parameters
167
149
  delimiter = '?'
168
150
  end
169
- url += "#{delimiter}#{directive.keys.first}=#{directive.values.first}"
151
+ url += "#{delimiter}#{parameters.keys.first}=#{parameters.values.first}"
170
152
 
171
153
  end
172
154
  return url
173
155
  end
174
156
 
175
-
176
- # formulates a link that the rails286-portlet will leave unparsed.
177
- def link_to_exit_portlet(name, options = {}, html_options = {})
178
- link_to(name, url_to_exit_portlet(options), html_options)
179
- end
180
-
181
157
  end
182
158
  end
183
159
  end
@@ -15,8 +15,17 @@ module Caterpillar
15
15
  # the installation directory
16
16
  attr_accessor :root
17
17
 
18
- def initialize(version='5.1.1')
18
+ # Liferay version is given as a String, eg. '5.2.2'.
19
+ # Unless given, the latest buildnumber value in the release_ table is used to decipher the version.
20
+ def initialize(version=nil)
21
+
19
22
  @version = version
23
+ @root = '/usr/local/liferay'
24
+ end
25
+
26
+ # The name of the portal. Used in STDOUT messages.
27
+ def name
28
+ 'Liferay'
20
29
  end
21
30
 
22
31
  # The location of Liferay's WEB-INF folder for XML analyzation.
@@ -51,9 +60,15 @@ module Caterpillar
51
60
  :title => (portlet/'display-name').innerHTML
52
61
  }
53
62
 
54
- # search the name
63
+ # search portlet metadata
55
64
  portlet_xml.search("//portlet-name").each do |p|
56
- _p.update(:name => (p/"../struts-path").text) if p.innerHTML==_p[:id]
65
+ if p.innerHTML==_p[:id]
66
+ _p.update(:name => (p/"../struts-path").text)
67
+
68
+ # is the portlet instanceable?
69
+ # it seems that if undefined, the default is "false"
70
+ _p.update(:instanceable => (p/"../instanceable").text=='true')
71
+ end
57
72
  end
58
73
 
59
74
  # search the category - horribly ineffective.
@@ -8,6 +8,8 @@ module Caterpillar
8
8
  # Portlet configuration and route parser.
9
9
  class Parser
10
10
 
11
+ # include ActionController::Assertions::RoutingAssertions
12
+
11
13
  def initialize(config)
12
14
  @config = config
13
15
  @routes = config.routes
@@ -30,10 +32,16 @@ module Caterpillar
30
32
  # parse the requirements - controller & action
31
33
  # ( this is too difficult -- no navigation for user-given paths )
32
34
  #
33
- # builder = ActionController::Routing::RouteBuilder.new
34
- # req_path = builder.segments_for_route_path(path)
35
- # r = ActionController::Routing::Routes.recognize_path(req_path, { :method => :get })
36
- # puts r.inspect
35
+ # begin
36
+ # #recognized_request_for(path)
37
+ # #builder = ActionController::Routing::RouteBuilder.new
38
+ # #r = ActionController::Routing::Routes.recognize_path(path, { :method => :get })
39
+ # #puts r.inspect
40
+ # #req_path = builder.segments_for_route_path(r)
41
+ # #STDERR.puts req_path.inspect
42
+ # rescue
43
+ # STDERR.puts $!.message
44
+ # end
37
45
 
38
46
  portlet.update( :reqs => {} )
39
47
  portlet.update( :vars => [] )
@@ -54,7 +62,13 @@ module Caterpillar
54
62
  portlet.update( :reqs => _r.first[:reqs] )
55
63
 
56
64
  ### variables
57
- portlet.update( :vars => _r.first[:vars] )
65
+ # take just the ones that are required in the path!
66
+ vars = []
67
+ _r.first[:vars].each do |var|
68
+ # variables that are not defined in reqs are required to be inserted by the rails-portlet
69
+ vars << var unless _r.first[:reqs][var]
70
+ end
71
+ portlet.update( :vars => vars )
58
72
 
59
73
  # delete the route from routes
60
74
  _r.each do |r|
@@ -81,13 +95,13 @@ module Caterpillar
81
95
  # sanity check
82
96
  portlets.each do |portlet|
83
97
  ### hostname
84
- portlet.update( :host => @config.host ) unless portlet[:host]
98
+ portlet[:host] ||= @config.host
85
99
 
86
100
  ### servlet
87
- portlet.update( :servlet => @config.servlet ) unless portlet[:servlet]
101
+ portlet[:servlet] ||= @config.servlet
88
102
 
89
103
  ### category
90
- portlet.update( :category => @config.category ) unless portlet[:category]
104
+ portlet[:category] ||= @config.category
91
105
 
92
106
  ### title
93
107
  _title = portlet[:title] || portlet[:name].to_s.gsub('_',' ').capitalize
@@ -95,8 +109,8 @@ module Caterpillar
95
109
  title = _title.gsub(/ä/,'a').gsub(/ö/,'o').gsub(/Ä/,'A').gsub(/Ö/,'O')
96
110
  portlet.update( :title => title )
97
111
 
98
- ### javascripts
99
- portlet.update( :javascripts => @config.javascripts ) unless portlet[:javascripts]
112
+ ### unless defined, use default javascripts
113
+ portlet[:javascripts] ||= @config.javascripts
100
114
 
101
115
  # fix path variables to be replaced by rails-portlet at runtime
102
116
  path = portlet[:path]