caterpillar 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,25 @@
1
+ = 1.4.0
2
+ - create Liferay XML with REXML
3
+ - Caterpillar works outside of RAILS_ROOT
4
+ - accept Ruby config file as the first parameter, for generating the XML (undocumented feature)
5
+ - write XML files to working directory
6
+ - create and deploy XML files with the task deploy:xml
7
+ - rename xml task to makexml
8
+ - update pluginize task (rename versioned caterpillar directory, accept FORCE env variable)
9
+ - introduced rspec and rcov tests
10
+ - set default Liferay version to 5.2.3
11
+ - small change to route parsing
12
+ - fix some deprecation warnings
13
+ - updated JBoss configuration handling
14
+ - fix the preferences route generation (by tulios)
15
+ - numerous small updates to portlet test bench
16
+
17
+ = 1.3.2
18
+ - Adding public render parameters, to control liferay portlets
19
+ - Fixing a bug in edit_mode that caused the "rails-portlet" received 404 to access the method preferences
20
+ - New preferences_route option for portlet, allowing the route configuration
21
+ - Some small fixes and improvements
22
+
1
23
  = 1.3.1
2
24
  - rename xml task to makexml, and call it with deploy:xml
3
25
  - many small fixes to various tasks
@@ -7,7 +29,8 @@
7
29
  = 1.3.0
8
30
  - New helpers to generate resource urls (download) and get_liferay_preferences, to get the preferences
9
31
  - edit_mode and instanceable working on portlet configuration
10
- - Modifications on portlet-ext.xml (new filter and RESOURCE_PHASE)
32
+ - Modifications on portlet-ext.xml (new filter and RESOURCE_PHASE)
33
+ - The new task rails (caterpillar rails project_name)
11
34
 
12
35
  = 1.2.5
13
36
  - Ruby 1.9 compatibility fix
data/README.rdoc CHANGED
@@ -86,7 +86,7 @@ Maybe caterpillar could have an upgrade task to handle this?
86
86
  == Useful tasks
87
87
  Here are the most useful tasks; see the rdoc documentation and caterpillar --describe for the full feature list.
88
88
 
89
- <tt>xml</tt>:: processes the portlet XML configuration in accordance with the named routes
89
+ <tt>makexml</tt>:: processes the portlet XML configuration in accordance with the named routes
90
90
 
91
91
  <tt>xml:deploy</tt>:: deploys the created XML to the J2EE portlet container
92
92
 
@@ -134,13 +134,22 @@ We have two kinds of portlets, the instanceable ones and not instaceables ones.
134
134
  :instanceable => false
135
135
  }
136
136
 
137
- Each mapped portlet requires a <b>preferences</b> method which will handle the edit mode features.
137
+ Each mapped portlet requires a <b>preferences</b> method, by convention, which will handle the edit mode features.
138
138
  For example:
139
139
  def preferences
140
140
  if request.post?
141
141
  flash[:notice] = 'Success!'
142
142
  end
143
143
  end
144
+
145
+ If you want is possible to set the <b>preferences_route</b> in <b>portlets.rb</b> file.
146
+ For example:
147
+ portlet.instances << {
148
+ :name => 'test',
149
+ :edit_mode => true,
150
+ :instanceable => true,
151
+ :preferences_route => '/my_portlet/test/preferences'
152
+ }
144
153
 
145
154
  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
155
  include Caterpillar::PortletSupport
@@ -162,7 +171,7 @@ This module will provide <b>get_liferay_preferences</b> method which returns the
162
171
 
163
172
  end
164
173
 
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:
174
+ In your erb file you will have a form like this, where each attribute (that has to be saved) needs to have sufix <b>_preference</b> on its name. For example:
166
175
  <% form_tag :controller => :test , :action => :preferences do %>
167
176
  <p>
168
177
  Cor de fundo: <%= text_field_tag :background_color_preference, @preferences[:background_color_preference] %>
@@ -176,10 +185,28 @@ In your erb file you will have a form like this, where each attribute (that has
176
185
  <%= submit_tag "Salve" %>
177
186
  <% end %>
178
187
 
188
+ == Public Render Parameters
179
189
 
190
+ To enable public parameters to your portlets, you must create the array <b>public_render_parameters</b>, in your <em>portlets.rb</em> instance configuration, where you will add the public variables (in our example, <b>param1</b> and <b>param2</b>).
191
+ portlet.instances << {
192
+ :name => 'home',
193
+ :public_render_parameters => [:param1, :param2]
194
+ }
180
195
 
196
+ In your erb file, for each public parameter, you must use the sufix <b>_prp</b> in it's name . For example, to use the public variable param1 in a textfield:
197
+ <%= text_field_tag :param1_prp, '' %>
181
198
 
182
199
 
200
+ <b> Watch it! </b>
201
+ * You should <b>not</b> use the sufix <b>_prp</b> in <em>portlets.rb</em>.
202
+ * You must use the public render parameters in your erb file, <b>in a form</b>, using POST method. [It has to go through processAction]
203
+ * Even if you've got only one variable to add to <b>public_render_parameters</b>, you <b>have</b> to use the brackets.
204
+
205
+ portlet.instances << {
206
+ :name => 'home',
207
+ :public_render_parameters => [:param1]
208
+ }
209
+ * And remember, the <b>_prp</b> sufix is <b>removed</b> when the param is published, so "tag_prp" become just "tag" for the portlets that are listening to this parameter.
183
210
 
184
211
 
185
212
 
data/Rakefile CHANGED
@@ -4,9 +4,31 @@ require 'rake/rdoctask'
4
4
  require 'rake/gempackagetask'
5
5
  load 'caterpillar.gemspec'
6
6
 
7
+ # gem install rspec -v 1.3.0
8
+ require 'spec/rake/spectask'
9
+ # gem install rcov
10
+ require 'spec/rake/verify_rcov'
11
+
7
12
  desc 'Default: create API doc.'
8
13
  task :default => :rdoc
9
14
 
15
+ Spec::Rake::SpecTask.new do |t|
16
+ t.spec_opts ||= []
17
+ t.spec_opts << "--options" << "spec/spec.opts"
18
+ end
19
+
20
+ Spec::Rake::SpecTask.new("spec:rcov") do |t|
21
+ t.spec_opts ||= []
22
+ t.spec_opts << "--options" << "spec/spec.opts"
23
+ t.rcov = true
24
+ # t.rcov_opts = ['--text-report', '--exclude', "gems/,spec/,rcov.rb,#{File.expand_path(File.join(File.dirname(__FILE__),'../../..'))}"]
25
+ t.rcov_opts = ['--exclude', 'diff-lcs,rake,spec,rcov,active_support,action_controller,action_view,json,rack']
26
+ end
27
+
28
+ RCov::VerifyTask.new(:rcov => "spec:rcov") do |t|
29
+ t.threshold = 100
30
+ end
31
+
10
32
  desc 'Generate documentation for the example plugin.'
11
33
  Rake::RDocTask.new(:rdoc) do |rdoc|
12
34
  rdoc.rdoc_dir = 'rdoc'
data/bin/caterpillar CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
2
  #--
4
- # (c) Copyright 2008 Mikael Lammentausta, Cel'Amanzi Ltd
5
- # 2010 Mikael Lammentausta, Youleaf Ltd
3
+ # (c) Copyright 2008-2010 Mikael Lammentausta
6
4
  #
7
5
  # Constructed heavily upon Warbler's structure.
8
6
  # Thanks to Nick Sieger!
@@ -31,8 +29,11 @@ Rake.application = application
31
29
  application.standard_exception_handling do
32
30
  application.init
33
31
 
34
- # Load the main tasks - choose the namespace
35
- Caterpillar::Task.new(ARGV[0] ? ARGV[0].gsub(/:.*/,'') : :usage)
32
+ # Load the main tasks -
33
+ # if first argument is a Ruby (config) file, take the task name from second arg
34
+ config = ARGV[0][/.rb$/] ? File.expand_path(ARGV.shift) : nil
35
+ name = ARGV[0] ? ARGV[0].gsub(/:.*/,'') : nil
36
+ Caterpillar::Task.new(name, config)
36
37
 
37
38
  task :default => :usage
38
39
 
@@ -4,6 +4,9 @@
4
4
  # This generator installs the required files into the main Rails application.
5
5
  # This generator should always be run after upgrading the plugin.
6
6
  class CaterpillarGenerator < Rails::Generator::Base
7
+
8
+ attr_accessor :project_name
9
+
7
10
  def msg(txt)
8
11
  _txt = " *\n"
9
12
  txt.split("\n").each do |line|
@@ -28,15 +31,16 @@ class CaterpillarGenerator < Rails::Generator::Base
28
31
  this_dir = File.dirname(File.expand_path(file))
29
32
  tmpl = File.join(this_dir,'templates')
30
33
 
34
+ @project_name = RAILS_ROOT.split('/')[-1]
31
35
  msg 'Installing configuration file with images, stylesheets and javascripts.'
32
36
 
33
37
  record do |m|
34
38
 
35
39
  ### config ###
36
- m.directory('config')
37
- file = 'portlets.rb'
38
- m.file(File.join('config',file), File.join('config',file))
39
-
40
+ # m.directory('config')
41
+ # file = 'portlets.rb'
42
+ # m.file(File.join('config',file), File.join('config',file))
43
+ m.template('config/portlets.rb','config/portlets.rb')
40
44
 
41
45
  ### Navigation ###
42
46
  target = File.join('public','images')
@@ -44,9 +48,9 @@ class CaterpillarGenerator < Rails::Generator::Base
44
48
  file = 'caterpillar.gif'
45
49
  m.file(File.join('images','caterpillar',file), File.join(target,file))
46
50
 
47
-
48
51
  ### Test bench ###
49
52
  testb = 'portlet_test_bench'
53
+
50
54
  #
51
55
  # images
52
56
  #
@@ -61,6 +65,7 @@ class CaterpillarGenerator < Rails::Generator::Base
61
65
  m.file(File.join('images',testb,img), File.join(target,img))
62
66
  end
63
67
  end
68
+
64
69
  #
65
70
  # stylesheets
66
71
  #
@@ -68,6 +73,7 @@ class CaterpillarGenerator < Rails::Generator::Base
68
73
  m.directory(target)
69
74
  file = 'main.css'
70
75
  m.file(File.join('stylesheets',testb,file), File.join(target,file))
76
+
71
77
  #
72
78
  # javascripts
73
79
  #
@@ -1,9 +1,6 @@
1
1
  # encoding: utf-8
2
2
  Caterpillar::Config.new do |portlet|
3
3
 
4
- # JRUBY_HOME can be set here, unless the environment variable can be used.
5
- # portlet.class::JRUBY_HOME = '/usr/local/jruby'
6
-
7
4
  # The portlet container.
8
5
  # By default only portlet.xml is created.
9
6
  # Currently only Liferay is supported. You may optionally define the version.
@@ -26,24 +23,28 @@ Caterpillar::Config.new do |portlet|
26
23
  # - 'JBoss/Tomcat'
27
24
  # portlet.container.server = 'JBoss/Tomcat'
28
25
 
29
- # The server dir is only meaningful with JBoss.
30
- # This is the name of the directory in server/.
31
- # By default the first entry in the directory is chosen.
32
- # portlet.container.server_dir = 'default'
26
+ # The server dir is only meaningful with JBoss, and is ignored with Tomcat.
27
+ # This should be set to the tree starting from container.root set above,
28
+ # and the top level should contain the WEB-INF directory.
29
+ # portlet.container.server_dir = 'server/default/deploy/ROOT.war'
33
30
 
34
- # Allow to defining the deploy_dir - just the WAR file will be deployed under this directory.
35
- # Since version 1.3.0
31
+ # Deploy directory for the WAR file.
32
+ # Please use absolute path.
33
+ # Not needed for Tomcat unless you have a complex setup.
36
34
  # portlet.container.deploy_dir = '/opt/myDeployDir'
37
35
 
36
+ # JRUBY_HOME can be set here, unless the environment variable can be used.
37
+ # portlet.class::JRUBY_HOME = '/usr/local/jruby'
38
+
38
39
  # The hostname and port.
39
40
  # By default the values are taken from the request.
40
- portlet.host = 'http://0.0.0.0:3000'
41
+ portlet.host = 'http://localhost:3000'
41
42
 
42
43
  # If the Rails is running inside a servlet container such as Tomcat,
43
44
  # you can define the servlet here.
44
45
  # By default the servlet is the name of the Rails app.
45
46
  # Without Warbler this should be an empty string.
46
- portlet.servlet = ''
47
+ portlet.servlet = '<%= project_name %>-portlet'
47
48
 
48
49
  # Portlet category. This is only available for Liferay.
49
50
  # By default this is the same as the servlet.
@@ -59,18 +60,25 @@ Caterpillar::Config.new do |portlet|
59
60
  # Most likely you will want to let ActionController::Routing to set the route.
60
61
  #
61
62
  # Available keys are:
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
63
+ # - :name -- named route
64
+ # - :category -- portlet category (Liferay only)
65
+ # - :title -- the title in portlet container's category (Liferay only)
66
+ # - :edit_mode -- enables edit mode for the portlet, adds <portlet-mode>edit</portlet-mode>
67
+ # to portlet-ext.xml. Default value is false
68
+ # - :instanceable -- enables instanceable for the portlet, add <instanceable>true</instanceable> to
69
+ # liferay-portlet-ext.xml. Default value is false
70
+ # - :preferences_route -- To customize the preferences route for the portlet
71
+ # - :public_render_parameters -- enables public render parameters. The variables should not have the sufix '_prp',
72
+ # they have to be the same as requested by portlets.
73
+ # Ex: portlets.instances << {
74
+ # :name => 'portlet_name',
75
+ # :public_render_parameters => [:tag, :param2, :param3]
76
+ # }
77
+ # - :javascripts -- portlet-specific javascripts that are included at
78
+ # the head of master HTML, such as body onload functions (Liferay only)
79
+ # - :host -- hostname:port of the deployment server
80
+ # - :servlet -- by default, the name of the Rails app (= name of the WAR package)
81
+ # - :path -- unless you're using named routes, you can define the path here
74
82
 
75
83
  # Rails-portlet testing application.
76
84
  # NOTE: this needs to be activated by 'map.caterpillar' in RAILS_ROOT/config/routes.rb
@@ -78,18 +78,18 @@ padding: 30px;
78
78
  padding-top: 0px;
79
79
  }
80
80
  /* form input label */
81
- #http_postform span {
81
+ .http_postform span {
82
82
  margin-left: 10px;
83
83
  margin-right: 5px;
84
84
  }
85
85
  /* form input paragraph */
86
- #http_postform p {
86
+ .http_postform p {
87
87
  padding: 4px;
88
88
  margin: 3px;
89
89
  /* border: 1px dotted gray; */
90
90
  }
91
91
  /* form submit */
92
- #submit_tags {
92
+ .submit_tags {
93
93
  margin-left: 10px;
94
94
  margin-right: 5px;
95
95
  }
@@ -97,21 +97,22 @@ margin-right: 5px;
97
97
  #http_post h1 {
98
98
  font: 21px Times New Roman;
99
99
  padding: 3px;
100
+ border-bottom: 1px dotted gray;
100
101
  }
101
102
  #http_post h2 {
102
- font: 12px Times New Roman;
103
+ font: 15px Times New Roman;
103
104
  border-bottom: 1px dashed gray;
104
105
  padding: 3px;
105
106
  }
106
107
  #post_msg {
107
108
  font: 21px Arial;
108
109
  font-style: italic;
109
- padding-left: 20px;
110
+ padding-left: 0px;
110
111
  }
111
112
  #post_info {
112
113
  font: 14px Arial;
113
114
  font-style: italic;
114
- padding-left: 20px;
115
+ padding: 0 0.1em 1.5em;
115
116
  }
116
117
 
117
118
  /* login */
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ class HtmlTemplateGenerator < Rails::Generator::Base
4
+
5
+ attr_accessor :project_name
6
+
7
+ def after_generate
8
+ STDOUT.puts "Done!"
9
+ end
10
+
11
+ def manifest
12
+ record do |m|
13
+ @project_name = RAILS_ROOT.split('/')[-1]
14
+ m.template('application.html.erb', 'app/views/layouts/application.html.erb')
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml">
5
+ <head>
6
+ <title><%= project_name %></title>
7
+ </head>
8
+ <body>
9
+ <%%= yield %>
10
+ </body>
11
+ </html>
data/lib/caterpillar.rb CHANGED
@@ -1,34 +1,45 @@
1
1
  # encoding: utf-8
2
2
  #--
3
3
  # (c) Copyright 2008-2010 Mikael Lammentausta
4
- # 2010 Túlio Ornelas
4
+ # 2010 Tulio Ornelas
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.3.1'
10
+ module Caterpillar
11
+ VERSION = '1.4.0'
12
12
  end
13
13
 
14
14
  this_file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
15
15
  this_dir = File.dirname(File.expand_path(this_file))
16
16
 
17
- CATERPILLAR_LIBS=this_dir unless defined?(CATERPILLAR_LIBS)
18
-
19
- RAILS_ROOT = Dir.pwd unless defined? RAILS_ROOT
17
+ CATERPILLAR_LIBS = this_dir unless defined? CATERPILLAR_LIBS
18
+
19
+ # detect if running in Rails directory
20
+ if not defined? RAILS_ROOT
21
+ rails_conf = File.join(Dir.pwd,'config','environment.rb')
22
+ if File.exists?(rails_conf)
23
+ # read from Rails config file
24
+ f=File.open(rails_conf)
25
+ _config = f.read
26
+ f.close
27
+ RAILS_ROOT = Dir.pwd if _config[/RAILS/]
28
+ end
29
+ end
20
30
 
21
31
  require 'find'
22
32
  require 'rake'
23
33
  require 'rake/tasklib'
24
34
 
25
- # NOTE: During normal startup (not while building the gem),
26
- # ActiveRecord should be loaded at this point, before loading any of the models.
27
- # However, this may conflict later when Rails' rake task activates the boot process.
28
- # The correct versions should be loaded at this point.
29
- # Maybe this is too heavy, as some tasks do not need any Rails modules.
30
- require File.join(this_dir,'rails_gem_chooser')
31
- RailsGemChooser.__load # detects the Rails config file from RAILS_ROOT
35
+ if defined? RAILS_ROOT
36
+ # NOTE: During normal startup (not while building the gem),
37
+ # ActiveRecord should be loaded at this point, before loading any of the models.
38
+ # However, this may conflict later when Rails' rake task activates the boot process.
39
+ # The correct versions should be loaded at this point.
40
+ require File.join(this_dir,'rails_gem_chooser')
41
+ RailsGemChooser.__load # detects the Rails config file from RAILS_ROOT
42
+ end
32
43
 
33
44
  # include all ruby files
34
45
  Find.find(this_dir) do |file|
@@ -37,7 +48,7 @@ Find.find(this_dir) do |file|
37
48
  Find.prune # Don't look any further into this directory.
38
49
 
39
50
  # load helpers only in Rails environment
40
- elsif (!defined?(RAILS_ENV) and (File.basename(file) == 'helpers'))
51
+ elsif (not defined?(RAILS_ENV) and %w{web helpers}.include?(File.basename(file)))
41
52
  Find.prune
42
53
 
43
54
  else