spiderfw 0.5.7 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/Rakefile +17 -6
  2. data/apps/cas_server/controllers/mixins/cas_login_mixin.rb +18 -5
  3. data/apps/cas_server/lib/cas.rb +1 -1
  4. data/apps/cms/models/content.rb +16 -0
  5. data/apps/cms/models/news_item.rb +7 -0
  6. data/apps/cms/models/translation.rb +14 -0
  7. data/apps/cms/views/admin/admin.shtml +16 -0
  8. data/apps/cms/views/admin/content.shtml +4 -0
  9. data/apps/core/acl/_init.rb +10 -0
  10. data/apps/core/acl/controllers/acl_controller.rb +14 -0
  11. data/apps/core/acl/models/permission.rb +11 -0
  12. data/apps/core/acl/views/acl.layout.shtml +8 -0
  13. data/apps/core/acl/views/index.shtml +3 -0
  14. data/apps/core/auth/controllers/mixins/auth_helper.rb +3 -3
  15. data/apps/core/auth/lib/authenticable.rb +4 -0
  16. data/apps/core/auth/models/super_user.rb +1 -0
  17. data/apps/core/auth/po/it/spider_auth.po +18 -10
  18. data/apps/core/auth/po/spider_auth.pot +13 -1
  19. data/apps/core/components/_init.rb +2 -1
  20. data/apps/core/components/po/it/spider_components.po +3 -3
  21. data/apps/core/components/po/spider_components.pot +3 -3
  22. data/apps/core/components/public/css/month_calendar.css +24 -0
  23. data/apps/core/components/public/js/jquery/jquery-1.4.2-min.js +154 -0
  24. data/apps/core/components/public/js/jquery/jquery-1.4.2.js +6240 -0
  25. data/apps/core/components/public/js/jquery/plugins/jquery.form.js +1 -1
  26. data/apps/core/components/public/js/spider.js +26 -20
  27. data/apps/core/components/widgets/admin/admin.rb +1 -1
  28. data/apps/core/components/widgets/crud/crud.rb +1 -1
  29. data/apps/core/components/widgets/list/list.rb +2 -2
  30. data/apps/core/components/widgets/month_calendar/month_calendar.rb +67 -0
  31. data/apps/core/components/widgets/month_calendar/month_calendar.shtml +21 -0
  32. data/apps/core/components/widgets/table/table.rb +4 -2
  33. data/apps/core/components/widgets/table/table.shtml +37 -31
  34. data/apps/core/forms/_init.rb +2 -1
  35. data/apps/core/forms/po/it/spider_forms.po +14 -2
  36. data/apps/core/forms/po/spider_forms.pot +13 -1
  37. data/apps/core/forms/public/css/file_input.css +15 -0
  38. data/apps/core/forms/public/{form.css → css/form.css} +8 -0
  39. data/apps/core/forms/public/file_input.js +37 -0
  40. data/apps/core/forms/tags/element_label.erb +4 -1
  41. data/apps/core/forms/tags/element_row.erb +7 -2
  42. data/apps/core/forms/tags/row.erb +10 -1
  43. data/apps/core/forms/widgets/form/form.rb +43 -10
  44. data/apps/core/forms/widgets/form/form.shtml +12 -5
  45. data/apps/core/forms/widgets/inputs/date_time/date_time.shtml +1 -0
  46. data/apps/core/forms/widgets/inputs/file_input/file_input.rb +43 -0
  47. data/apps/core/forms/widgets/inputs/file_input/file_input.shtml +12 -0
  48. data/apps/core/forms/widgets/inputs/input/input.rb +23 -1
  49. data/apps/core/forms/widgets/inputs/password/password.rb +1 -0
  50. data/apps/core/forms/widgets/inputs/text/text.shtml +1 -1
  51. data/apps/core/forms/widgets/inputs/text_area/text_area.shtml +2 -2
  52. data/apps/git_model_versioning/models/mixins/git_versioned.rb +91 -0
  53. data/apps/hippo/models/mixins/hippo_struct.rb +42 -26
  54. data/apps/master/controllers/git.rb +32 -0
  55. data/apps/messenger/_init.rb +1 -1
  56. data/apps/messenger/config/options.rb +2 -0
  57. data/apps/messenger/config/worker/queue.rb +3 -0
  58. data/apps/messenger/controllers/mixins/{messenger_controller_mixin.rb → messenger_helper.rb} +8 -6
  59. data/apps/messenger/messenger.rb +10 -3
  60. data/apps/messenger/models/message.rb +2 -2
  61. data/apps/messenger/po/it/spider_messenger.po +1 -1
  62. data/apps/messenger/po/spider_messenger.pot +1 -1
  63. data/apps/saml/_init.rb +13 -0
  64. data/apps/saml/controllers/saml2idp.rb +18 -0
  65. data/apps/saml/lib/bindings/http_redirect_binding.rb +14 -0
  66. data/apps/saml/lib/messages/authn_request.rb +52 -0
  67. data/apps/saml/lib/saml.rb +10 -0
  68. data/apps/soap/controllers/soap_controller.rb +12 -2
  69. data/apps/soap/lib/soap.rb +16 -1
  70. data/apps/soap/soap.gemspec +10 -0
  71. data/apps/webdav/lib/locking.rb +2 -2
  72. data/apps/worker/_init.rb +2 -0
  73. data/apps/worker/config/options.rb +1 -0
  74. data/apps/worker/worker.rb +17 -4
  75. data/blueprints/app/__APP__.appspec +4 -0
  76. data/blueprints/app/_init.rb +5 -8
  77. data/blueprints/app/controllers/__APP___controller.rb +2 -1
  78. data/blueprints/app/views/__APP__.layout.shtml +4 -1
  79. data/blueprints/install/config/config.yml +2 -4
  80. data/blueprints/model.rb +15 -0
  81. data/data/locale/it/LC_MESSAGES/spider.mo +0 -0
  82. data/data/locale/it/LC_MESSAGES/spider_auth.mo +0 -0
  83. data/data/locale/it/LC_MESSAGES/spider_components.mo +0 -0
  84. data/data/locale/it/LC_MESSAGES/spider_forms.mo +0 -0
  85. data/data/locale/it/LC_MESSAGES/spider_messenger.mo +0 -0
  86. data/lib/spiderfw/app.rb +93 -31
  87. data/lib/spiderfw/autoload.rb +1 -0
  88. data/lib/spiderfw/cmd/cmd.rb +8 -1
  89. data/lib/spiderfw/cmd/commands/config.rb +54 -0
  90. data/lib/spiderfw/config/configuration.rb +30 -0
  91. data/lib/spiderfw/config/options/spider.rb +18 -6
  92. data/lib/spiderfw/controller/controller.rb +12 -11
  93. data/lib/spiderfw/controller/dispatcher.rb +5 -4
  94. data/lib/spiderfw/controller/http_controller.rb +16 -2
  95. data/lib/spiderfw/controller/mixins/http_mixin.rb +3 -2
  96. data/lib/spiderfw/controller/mixins/static_content.rb +8 -2
  97. data/lib/spiderfw/controller/mixins/visual.rb +72 -52
  98. data/lib/spiderfw/controller/request.rb +7 -3
  99. data/lib/spiderfw/controller/scene.rb +6 -0
  100. data/lib/spiderfw/controller/session.rb +12 -8
  101. data/lib/spiderfw/env.rb +1 -1
  102. data/lib/spiderfw/http/adapters/mongrel.rb +1 -1
  103. data/lib/spiderfw/http/http.rb +48 -19
  104. data/lib/spiderfw/i18n/cldr.rb +53 -3
  105. data/lib/spiderfw/i18n/i18n.rb +52 -2
  106. data/lib/spiderfw/i18n/provider.rb +24 -0
  107. data/lib/spiderfw/i18n/rails.rb +24 -0
  108. data/lib/spiderfw/model/active_record.rb +3 -3
  109. data/lib/spiderfw/model/base_model.rb +45 -14
  110. data/lib/spiderfw/model/condition.rb +11 -2
  111. data/lib/spiderfw/model/data_type.rb +15 -7
  112. data/lib/spiderfw/model/datatypes/decimal.rb +15 -3
  113. data/lib/spiderfw/model/datatypes/file_path.rb +50 -0
  114. data/lib/spiderfw/model/datatypes/serialized_object.rb +0 -4
  115. data/lib/spiderfw/model/datatypes/uuid.rb +3 -3
  116. data/lib/spiderfw/model/datatypes.rb +1 -0
  117. data/lib/spiderfw/model/extended_models/managed.rb +11 -2
  118. data/lib/spiderfw/model/mappers/db_mapper.rb +116 -52
  119. data/lib/spiderfw/model/mappers/mapper.rb +36 -14
  120. data/lib/spiderfw/model/mixins/state_machine.rb +45 -9
  121. data/lib/spiderfw/model/mixins/versioned.rb +1 -1
  122. data/lib/spiderfw/model/model.rb +2 -1
  123. data/lib/spiderfw/model/query_set.rb +21 -3
  124. data/lib/spiderfw/model/request.rb +7 -0
  125. data/lib/spiderfw/model/storage/db/adapters/mssql.rb +2 -1
  126. data/lib/spiderfw/model/storage/db/adapters/mysql.rb +4 -1
  127. data/lib/spiderfw/model/storage/db/adapters/oci8.rb +35 -18
  128. data/lib/spiderfw/model/storage/db/adapters/sqlite.rb +68 -34
  129. data/lib/spiderfw/model/storage/db/connectors/odbc.rb +1 -1
  130. data/lib/spiderfw/model/storage/db/db_schema.rb +33 -4
  131. data/lib/spiderfw/model/storage/db/db_storage.rb +27 -8
  132. data/lib/spiderfw/requires.rb +2 -0
  133. data/lib/spiderfw/tag/tag.rb +1 -1
  134. data/lib/spiderfw/templates/blocks/attr_if.rb +7 -1
  135. data/lib/spiderfw/templates/blocks/each.rb +8 -3
  136. data/lib/spiderfw/templates/blocks/html.rb +12 -22
  137. data/lib/spiderfw/templates/blocks/render.rb +3 -3
  138. data/lib/spiderfw/templates/blocks/run.rb +47 -11
  139. data/lib/spiderfw/templates/blocks/tag_if.rb +2 -2
  140. data/lib/spiderfw/templates/blocks/text.rb +2 -1
  141. data/lib/spiderfw/templates/blocks/widget.rb +5 -3
  142. data/lib/spiderfw/templates/blocks/yield.rb +1 -1
  143. data/lib/spiderfw/templates/template.rb +27 -24
  144. data/lib/spiderfw/templates/template_blocks.rb +37 -14
  145. data/lib/spiderfw/utils/monkey/exception.rb +1 -1
  146. data/lib/spiderfw/utils/monkey/nil_class.rb +7 -0
  147. data/lib/spiderfw/utils/monkey/numeric.rb +15 -0
  148. data/lib/spiderfw/version.rb +1 -1
  149. data/lib/spiderfw/widget/widget.rb +36 -33
  150. data/lib/spiderfw/widget/widget_attributes.rb +1 -1
  151. data/lib/spiderfw.rb +18 -5
  152. data/spider.gemspec +5 -5
  153. metadata +44 -18
  154. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.1.0.js +0 -187
  155. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.1.0.min.js +0 -1
  156. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.spider.1.0.js +0 -193
  157. data/apps/core/forms/widgets/inputs/subform/subform.rb +0 -10
  158. data/apps/core/forms/widgets/inputs/subform/subform.shtml +0 -5
  159. data/apps/messenger/config/worker.rb +0 -3
  160. data/lib/spiderfw/controller/app_controller.rb +0 -14
  161. data/lib/spiderfw/utils/test_case.rb +0 -24
@@ -10,7 +10,16 @@ module Spider
10
10
 
11
11
  # Web server
12
12
  config_option 'http.server', _("The internal server to use"), {
13
- :default => 'mongrel'
13
+ :default => lambda{
14
+ begin
15
+ require 'rubygems'
16
+ require 'mongrel'
17
+ 'mongrel'
18
+ rescue LoadError
19
+ 'webrick'
20
+ end
21
+ },
22
+ :type => String, :choices => ['webrick', 'mongrel', 'thin']
14
23
  }
15
24
  config_option 'webserver.show_traces', _("Whether to show the stack trace on error"), {
16
25
  :default => Proc.new{ ['test', 'devel'].include?(Spider.config.get('runmode')) ? true : false }
@@ -18,7 +27,7 @@ module Spider
18
27
  config_option 'webserver.reload_sources', _("Reload application and spider sources on each request"), {
19
28
  :default => Proc.new{ Spider.config.get('runmode') == 'devel' ? true : false }
20
29
  }
21
- config_option 'webserver.port', _("Port to use for the http server"), :default => 8080
30
+ config_option 'webserver.port', _("Port to use for the http server"), :type => Fixnum, :default => 8080
22
31
  config_option 'webserver.force_threads', _("Force threading on non-threaded adapters"),
23
32
  :default => Proc.new{ RUBY_VERSION_PARTS[1] == '8' ? true : false }
24
33
  config_option 'webserver.timeout', _("Time allowed for each request (in seconds)"), :type=> Fixnum, :default => nil
@@ -47,6 +56,7 @@ module Spider
47
56
  config_option 'storages', _("A list of named storages"), :type => :conf
48
57
  config_option 'storages.x.url', _("Connection url to the storage"), :type => String, :required => true
49
58
  config_option 'storages.x.encoding', _("Encoding the DB uses"), :type => String
59
+ config_option 'storages.x.enable_transactions', _("Whether to enable transactions on the db"), :type => Spider::DataTypes::Bool, :default => true
50
60
 
51
61
  config_option 'debugger.start', _("Start the debugger")
52
62
  config_option 'profiling.enable', _("Enable on-request profiling")
@@ -69,17 +79,19 @@ module Spider
69
79
 
70
80
  config_option 'http.nonce_life', _("Life in seconds of HTTP Digest Authentication nonces"), :type => Fixnum, :default => 60
71
81
  # TODO: implement in webrick/others, check if has a performance gain
72
- config_option 'http.auto_headers', _("Automatically send headers on first output (breaks the debugger)"), :default => true
82
+ config_option 'http.auto_headers', _("Automatically send headers on first output"),
83
+ :type => Spider::DataTypes::Bool, :default => true
73
84
  config_option 'http.seize_stdout', _("Redirect standard output to the browser"), :default => false
74
85
  config_option 'http.proxy_mapping', _("If the request is proxyied, the urls used to reach spider, with the corresponding paths called by the proxy"),
75
86
  :type => Hash
76
87
  config_option 'http.charset', _("The charset to use for http requests"), :default => 'UTF-8'
77
88
 
78
89
  config_option 'debug.console.level', _("Level of debug output to console"), :default => :INFO,
79
- :process => lambda{ |opt| opt && opt != 'false' ? opt.to_s.upcase.to_sym : false }
80
- config_option 'log.errors', _("Log errors to file"), :default => true
90
+ :process => lambda{ |opt| opt && opt != 'false' ? opt.to_s.upcase.to_sym : false },
91
+ :choices => [false, :DEBUG, :WARN, :INFO, :ERROR]
92
+ config_option 'log.errors', _("Log errors to file"), :type => Spider::DataTypes::Bool, :default => true
81
93
  config_option 'log.debug.level', _("Log level to use for debug file (false for no debug)"), :default => false,
82
- :choices => [false, :DEBUG, :INFO],
94
+ :choices => [false, :DEBUG, :WARN, :INFO, :ERROR],
83
95
  :process => lambda{ |opt| opt && opt != 'false' ? opt.to_s.upcase.to_sym : false }
84
96
  config_option 'log.rotate.age', _("Number of old log files to keep, OR frequency of rotation (daily, weekly or monthly)"), :default => 'daily'
85
97
  config_option 'log.rotate.size', _("Maximum logfile size (only applies when log.rotate.age is a number)"), :default => 1048576
@@ -8,6 +8,7 @@ require 'spiderfw/controller/first_responder'
8
8
  require 'spiderfw/controller/mixins/visual'
9
9
  require 'spiderfw/controller/mixins/http_mixin'
10
10
  require 'spiderfw/controller/mixins/static_content'
11
+ require 'spiderfw/widget/widget'
11
12
 
12
13
  require 'spiderfw/controller/helpers/widget_helper'
13
14
 
@@ -108,13 +109,14 @@ module Spider
108
109
  define_annotation(:action) { |k, m| k.controller_actions(m) }
109
110
 
110
111
  attr_reader :request, :response, :executed_method, :scene
111
- attr_accessor :dispatch_action
112
+ attr_accessor :dispatch_action, :is_target
112
113
 
113
114
  def initialize(request, response, scene=nil)
114
115
  @request = request
115
116
  @response = response
116
117
  @scene = scene || get_scene
117
118
  @dispatch_path = ''
119
+ @is_target = true
118
120
  init
119
121
  #@parent = parent
120
122
  end
@@ -165,6 +167,11 @@ module Spider
165
167
  !@dispatch_next[@call_path] || @dispatch_next[@call_path].dest == self
166
168
  end
167
169
 
170
+ # Returns false if the target of the call is a widget, true otherwise
171
+ def is_target?
172
+ @is_target
173
+ end
174
+
168
175
 
169
176
  def execute(action='', *arguments)
170
177
  return if @__done
@@ -178,12 +185,9 @@ module Spider
178
185
  if (can_dispatch?(:execute, action))
179
186
  d_next = dispatch_next(action)
180
187
  #run_chain(:execute, action, *arguments)
181
- if d_next.dest != self # otherwise, shortcut route to self
182
- return do_dispatch(:execute, action)
183
- else
184
- arguments = d_next.params
185
- end
186
- # after(action, *arguments)
188
+ # shortcut route to self
189
+ return do_dispatch(:execute, action) if d_next.dest != self
190
+ arguments = d_next.params
187
191
  end
188
192
  if (@executed_method)
189
193
  meth = self.method(@executed_method)
@@ -264,7 +268,7 @@ module Spider
264
268
  klass = route.dest
265
269
  if klass.class != Class
266
270
  if (klass == self) # route to self
267
- @executed_method = route.action
271
+ @executed_method = route.action.to_sym
268
272
  @executed_method_arguments = []
269
273
  end
270
274
  return klass
@@ -273,9 +277,6 @@ module Spider
273
277
  obj.dispatch_action = route.matched || ''
274
278
  # FIXME: this is not clean
275
279
  obj.set_action(route.action)
276
- if (route.options[:do])
277
- obj.instance_eval &route.options[:do]
278
- end
279
280
  # obj.dispatch_path = @dispatch_path + route.path
280
281
  return obj
281
282
  end
@@ -40,11 +40,11 @@ module Spider
40
40
  obj = dispatched_object(route)
41
41
  obj.dispatch_previous = self if obj.respond_to?(:dispatch_previous=) && obj != self
42
42
  route.obj = obj
43
+ if (route.options[:do])
44
+ obj.instance_exec(*(route.params || []), &route.options[:do])
45
+ end
43
46
  end
44
- obj = route.obj
45
- if (route.options[:do])
46
- route.options[:do].call(obj, *(route.params || []))
47
- end
47
+ obj = route.obj
48
48
  new_arguments = arguments
49
49
  new_arguments += route.params unless route.options[:remove_params]
50
50
  return [obj, route.action, new_arguments]
@@ -138,6 +138,7 @@ module Spider
138
138
  match = try.match(path)
139
139
  if (match)
140
140
  action = action_index ? match[action_index] : match.post_match
141
+ action = action[0..-2] if action.length > 0 && action[-1].chr == '/'
141
142
  params = match[1..(match.length-1)]
142
143
  matched = match[0]
143
144
  end
@@ -31,12 +31,22 @@ module Spider
31
31
  @response.cookies['sid'] = @request.session.sid
32
32
  @response.cookies['sid'].path = '/'
33
33
  @request.params = {}
34
+ @uploaded_files = []
34
35
  if (@request.env['QUERY_STRING'])
35
36
  @request.params = Spider::HTTP.parse_query(@request.env['QUERY_STRING'])
36
37
  end
37
- if (@request.env['REQUEST_METHOD'] == 'POST' && @request.env['HTTP_CONTENT_TYPE'] && @request.env['HTTP_CONTENT_TYPE'].include?('application/x-www-form-urlencoded'))
38
- @request.params.merge!(Spider::HTTP.parse_query(@request.read_body))
38
+ if @request.env['REQUEST_METHOD'] == 'POST' && @request.env['HTTP_CONTENT_TYPE']
39
+ if @request.env['HTTP_CONTENT_TYPE'].include?('application/x-www-form-urlencoded')
40
+ @request.params.merge!(Spider::HTTP.parse_query(@request.read_body))
41
+ elsif @request.env['HTTP_CONTENT_TYPE'] =~ Spider::HTTP::MULTIPART_REGEXP
42
+ multipart_params, multipart_files = Spider::HTTP.parse_multipart(@request.body, $1, @request.env['CONTENT_LENGTH'].to_i)
43
+ @request.params.merge!(multipart_params)
44
+ @uploaded_files = multipart_files
45
+ end
39
46
  end
47
+
48
+ @request.http_method = @request.env['REQUEST_METHOD'].upcase.to_sym
49
+ @request.http_host = @request.env['HTTP_HOST']
40
50
  Locale.clear
41
51
  Locale.init(:driver => :cgi)
42
52
  Locale.set_request(@request.params['lang'], @request.cookies['lang'], @request.env['HTTP_ACCEPT_LANGUAGE'], @request.env['HTTP_ACCEPT_CHARSET'])
@@ -65,6 +75,9 @@ module Spider
65
75
  def ensure(action='', *arguments)
66
76
  dispatch(:ensure, action, *arguments)
67
77
  $stdout = @previous_stdout
78
+ @uploaded_files.each do |f|
79
+ f.close
80
+ end
68
81
  end
69
82
 
70
83
 
@@ -85,6 +98,7 @@ module Spider
85
98
  end
86
99
 
87
100
  module HTTPRequest
101
+ attr_accessor :http_method, :http_host
88
102
 
89
103
  # Returns PATH_INFO reversing any proxy mappings if needed.
90
104
  def path
@@ -1,5 +1,5 @@
1
1
  require 'base64'
2
- require 'uuid'
2
+ require 'uuidtools'
3
3
  require 'digest/md5'
4
4
  require 'macaddr'
5
5
  require 'spiderfw/http/http'
@@ -14,6 +14,7 @@ module Spider; module ControllerMixins
14
14
 
15
15
  def redirect(url, code=Spider::HTTP::MOVED_PERMANENTLY)
16
16
  debug "REDIRECTING TO #{url}"
17
+ @request.session.persist if @request.session # It might be too late afterwards
17
18
  @response.status = code
18
19
  @response.headers["Location"] = url
19
20
  @response.headers.delete("Content-Type")
@@ -130,7 +131,7 @@ module Spider; module ControllerMixins
130
131
  pk = Digest::MD5.hexdigest("#{now}:#{digest_instance_key}")[0,32]
131
132
  nonce = [now + ":" + pk].pack("m*").chop # it has 60 length of chars.
132
133
 
133
- opaque = [UUID.new.generate].pack("m*").chop
134
+ opaque = [UUIDTools::UUID.random_create.to_s].pack("m*").chop
134
135
  header = "Digest realm=\"#{realm}\", qop=\"auth\", nonce=\"#{nonce}\", opaque=\"#{opaque}\""
135
136
  @response.headers['WWW-Authenticate'] = header
136
137
  @response.status = Spider::HTTP::UNAUTHORIZED
@@ -20,7 +20,7 @@ module Spider; module ControllerMixins
20
20
  module ClassMethods
21
21
 
22
22
  def output_format?(method, format)
23
- return true if method == "serve_static"
23
+ return true if method == :serve_static
24
24
  return super
25
25
  end
26
26
 
@@ -68,7 +68,13 @@ module Spider; module ControllerMixins
68
68
  debug("Serving asset: #{full_path}")
69
69
  raise Spider::Controller::NotFound.new(full_path) unless File.exist?(full_path)
70
70
  stat = File.lstat(full_path)
71
- ct = File.directory?(full_path) ? "httpd/unix-directory" : WEBrick::HTTPUtils::mime_type(full_path, ::MIME::Types)
71
+ if File.directory?(full_path)
72
+ ct = "httpd/unix-directory"
73
+ else
74
+ ct = MIME::Types.type_for(full_path)
75
+ ct = ct.to_s if ct
76
+ ct ||= "application/octet-stream"
77
+ end
72
78
  @response.headers['Content-Type'] = ct
73
79
  @response.headers['Content-Length'] = stat.size
74
80
  @response.headers['Last-Modified'] = stat.mtime.httpdate
@@ -57,52 +57,62 @@ module Spider; module ControllerMixins
57
57
  end
58
58
  end
59
59
 
60
+ def visual_params
61
+ @visual_params ||= {}
62
+ end
63
+
64
+ def init_widgets(template)
65
+ widget_target = @request.params['_wt']
66
+ widget_execute = @request.params['_we']
67
+ if (widget_target && !@rendering_error)
68
+ first, rest = widget_target.split('/', 2)
69
+ @_widget = find_widget(first)
70
+ raise Spider::Controller::NotFound.new("Widget #{widget_target}") unless @_widget
71
+ @is_target = false
72
+ @_widget.is_target = true unless rest
73
+ @_widget.set_action(widget_execute) if widget_execute
74
+ @_widget.target_mode = true
75
+ @_widget.widget_target = rest
76
+ end
77
+ template.do_widgets_before
78
+ if @_widget
79
+ @_widget.execute
80
+ done
81
+ end
82
+ end
83
+
60
84
  def execute(action='', *params)
61
- format_params = @executed_format_params
85
+ @visual_params = @executed_format_params
62
86
  if (self.is_a?(Widget) && @is_target && @request.params['_wp'])
63
87
  params = @request.params['_wp']
64
- elsif (format_params.is_a?(Hash) && format_params[:params])
88
+ elsif (@visual_params.is_a?(Hash) && @visual_params[:params])
65
89
  p_first, p_rest = action.split('/')
66
90
  params = format_params[:params].call(p_rest) if p_rest
67
91
  end
68
92
  super(action, *params)
69
- return unless format_params.is_a?(Hash)
70
- if (format_params.is_a?(Hash) && format_params[:template])
71
- @template ||= init_template
72
- widget_target = @request.params['_wt']
73
- widget_execute = @request.params['_we']
74
- if (widget_target)
75
- first, rest = widget_target.split('/', 2)
76
- @_widget = find_widget(first)
77
- raise Spider::Controller::NotFound.new("Widget #{widget_target}") unless @_widget
78
- @_widget.is_target = true unless rest
79
- @_widget.set_action(widget_execute) if widget_execute
80
- @_widget.target_mode = true
81
- @_widget.widget_target = rest
82
- @template.do_widgets_before
83
- @_widget.execute
84
- end
93
+ return unless @visual_params.is_a?(Hash)
94
+ @template = init_template if !@template && @visual_params[:template]
95
+ init_widgets(@template) if @template
96
+ if @visual_params[:call]
97
+ send(@visual_params[:call], *params)
85
98
  end
86
- if (format_params.is_a?(Hash) && format_params[:template] && !@_widget)
99
+ if @visual_params[:template] && !@_widget && !done?
87
100
  if (@template)
88
- render(@template, format_params) # has been init'ed in before method
101
+ render(@template, @visual_params) # has been init'ed in before method
89
102
  else
90
- render(format_params[:template], format_params)
103
+ render(@visual_params[:template], @visual_params)
91
104
  end
92
105
  end
93
- return unless format_params.is_a?(Hash)
94
- if (format_params[:redirect])
95
- # red = format_params[:redirect] == true ? request_url : format_params[:redirect]
96
- # red = owner_controller.request_url if (self.is_a?(Widget))
97
- redirect(format_params[:redirect])
106
+ if @visual_params[:redirect]
107
+ redirect(@visual_params[:redirect])
98
108
  end
99
- if (@executed_format == :json && format_params[:scene] || format_params[:return]) # FIXME: move in JSON mixin?
100
- if (format_params[:return])
101
- $out << format_params[:return].to_json
102
- elsif (format_params[:scene].is_a?(Array))
109
+ if @executed_format == :json && @visual_params[:scene] || @visual_params[:return] # FIXME: move in JSON mixin?
110
+ if (@visual_params[:return])
111
+ $out << @visual_params[:return].to_json
112
+ elsif (@visual_params[:scene].is_a?(Array))
103
113
  h = @scene.to_hash
104
114
  res = {}
105
- format_params[:scene].each{ |k| res[k] = h[k] }
115
+ @visual_params[:scene].each{ |k| res[k] = h[k] }
106
116
  $out << res.to_json
107
117
  else
108
118
  $out << @scene.to_json
@@ -112,11 +122,15 @@ module Spider; module ControllerMixins
112
122
 
113
123
  def load_template(path, cur_path=nil, owner=nil, search_paths=nil)
114
124
  template = self.class.load_template(path, cur_path, owner, search_paths)
125
+ prepare_template(template)
126
+ @template = template
127
+ return template
128
+ end
129
+
130
+ def prepare_template(template)
115
131
  template.owner = self
116
132
  template.request = request
117
133
  template.response = response
118
- @template = template
119
- return template
120
134
  end
121
135
 
122
136
  def template_exists?(name)
@@ -129,15 +143,21 @@ module Spider; module ControllerMixins
129
143
  scene ||= @scene
130
144
  scene ||= get_scene
131
145
  if (!path)
132
- format_params = self.class.output_format_params(@executed_method, @executed_format)
146
+ format_params = @visual_params || self.class.output_format_params(@executed_method, @executed_format)
133
147
  return unless format_params && format_params[:template]
134
148
  path = format_params[:template]
135
149
  options = format_params.merge(options)
136
150
  end
137
151
  template = load_template(path)
138
- template.init(scene)
152
+ do_template_init(template, options)
139
153
  @template = template
140
154
  @loaded_template_path = path
155
+
156
+ return template
157
+ end
158
+
159
+ def do_template_init(template, options={})
160
+ template.init(scene)
141
161
  if (@request.params['_action'])
142
162
  template._widget_action = @request.params['_action']
143
163
  else
@@ -171,22 +191,21 @@ module Spider; module ControllerMixins
171
191
  else
172
192
  template = init_template(path, scene, options)
173
193
  end
174
- template.do_widgets_before
175
- unless (@_partial_render) # TODO: implement or remove
176
- chosen_layouts = options[:layout] || @layout
177
- chosen_layouts = [chosen_layouts] if chosen_layouts && !chosen_layouts.is_a?(Array)
178
- if (chosen_layouts)
179
- t = template
180
- l = nil
181
- (chosen_layouts.length-1).downto(0) do |i|
182
- l = init_layout(chosen_layouts[i])
183
- l.template = t
184
- t = l
185
- end
186
- l.render(scene)
187
- else
188
- template.render(scene)
194
+ init_widgets(template)
195
+ return template if done?
196
+ chosen_layouts = options[:layout] || @layout
197
+ chosen_layouts = [chosen_layouts] if chosen_layouts && !chosen_layouts.is_a?(Array)
198
+ if (chosen_layouts)
199
+ t = template
200
+ l = nil
201
+ (chosen_layouts.length-1).downto(0) do |i|
202
+ l = init_layout(chosen_layouts[i])
203
+ l.template = t
204
+ t = l
189
205
  end
206
+ l.render(scene)
207
+ else
208
+ template.render(scene)
190
209
  end
191
210
  return template
192
211
  end
@@ -216,7 +235,7 @@ module Spider; module ControllerMixins
216
235
  end
217
236
 
218
237
  def try_rescue(exc)
219
- exc.uuid = UUID.new.generate if exc.respond_to?(:uuid=)
238
+ exc.uuid = UUIDTools::UUID.random_create.to_s if exc.respond_to?(:uuid=)
220
239
  format = self.class.output_format(:error) || :html
221
240
  return super unless @executed_format == :html
222
241
  return super unless action_target?
@@ -261,6 +280,7 @@ module Spider; module ControllerMixins
261
280
  super(exc)
262
281
  end
263
282
  end
283
+ @rendering_error = true
264
284
  render "errors/#{error_page}", :layout => "errors/error"
265
285
  super
266
286
  end
@@ -449,7 +469,7 @@ module Spider; module ControllerMixins
449
469
  return t
450
470
 
451
471
  end
452
-
472
+
453
473
  def template_exists?(name, paths=nil)
454
474
  if (name[0..5] == 'SPIDER' || name[0..3] == 'ROOT')
455
475
  name.sub!('SPIDER', $SPIDER_PATH).sub!('ROOT', Spider.paths[:root])
@@ -20,14 +20,18 @@ module Spider
20
20
  @body = b
21
21
  end
22
22
 
23
- def body(&proc)
23
+ def body
24
24
  b = @body.is_a?(String) ? StringIO.new(@body) : @body
25
25
  return nil unless b
26
- while (buf = b.read(BUFSIZE))
27
- yield buf
26
+ if block_given?
27
+ while (buf = b.read(BUFSIZE))
28
+ yield buf
29
+ end
28
30
  end
31
+ return b
29
32
  end
30
33
 
34
+
31
35
  def read_body
32
36
  return @body if @body.is_a?(String)
33
37
  b = ''
@@ -21,6 +21,12 @@ module Spider
21
21
  @table
22
22
  end
23
23
 
24
+ def <<(other)
25
+ if other.is_a?(Hash)
26
+ @table.merge!(other)
27
+ end
28
+ end
29
+
24
30
  end
25
31
 
26
32
 
@@ -1,4 +1,4 @@
1
- require 'uuid'
1
+ require 'uuidtools'
2
2
  require 'spiderfw/controller/session/flash_hash'
3
3
  require 'spiderfw/controller/session/transient_hash'
4
4
 
@@ -39,11 +39,6 @@ module Spider
39
39
 
40
40
  def initialize(sid=nil)
41
41
  @sid = sid || generate_sid
42
- restore
43
- Spider::Logger.debug("SESSION RESTORED:")
44
- Spider::Logger.debug(@data)
45
- @data ||= {}
46
- @data[:_flash].reset if @data[:_flash]
47
42
  end
48
43
 
49
44
  def delete
@@ -51,22 +46,26 @@ module Spider
51
46
  end
52
47
 
53
48
  def generate_sid
54
- UUID.new.generate
49
+ UUIDTools::UUID.random_create.to_s
55
50
  end
56
51
 
57
52
  def [](key)
53
+ restore unless @restored
58
54
  @data[key]
59
55
  end
60
56
 
61
57
  def []=(key, val)
58
+ restore unless @restored
62
59
  @data[key] = val
63
60
  end
64
61
 
65
62
  def delete(key)
63
+ restore unless @restored
66
64
  @data.delete(key)
67
65
  end
68
66
 
69
67
  def persist
68
+ return unless @restored
70
69
  clear_empty_hashes!(@data)
71
70
  @data[:_flash].purge if @data[:_flash]
72
71
  @data[:_transient].purge if @data[:_transient]
@@ -76,14 +75,19 @@ module Spider
76
75
  end
77
76
 
78
77
  def restore
79
- @data = self.class[@sid]
78
+ @data = self.class[@sid] || {}
79
+ @data[:_flash].reset if @data[:_flash]
80
+ Spider.logger.debug("Session restored: #{@data.inspect}")
81
+ @restored = true
80
82
  end
81
83
 
82
84
  def flash
85
+ restore unless @restored
83
86
  @data[:_flash] ||= FlashHash.new
84
87
  end
85
88
 
86
89
  def transient
90
+ restore unless @restored
87
91
  @data[:_transient] ||= TransientHash.new
88
92
  end
89
93
 
data/lib/spiderfw/env.rb CHANGED
@@ -11,7 +11,7 @@ ENV['GETTEXT_PATH'] += $SPIDER_PATH+'/data/locale,'+$SPIDER_RUN_PATH+'/data/loca
11
11
  $:.push($SPIDER_RUN_PATH)
12
12
 
13
13
  $:.push($SPIDER_PATH)
14
- Dir.chdir($SPIDER_RUN_PATH)
14
+ # Dir.chdir($SPIDER_RUN_PATH)
15
15
 
16
16
  $SPIDER_RUNMODE = ENV['SPIDER_RUNMODE']
17
17
  $SPIDER_CONFIG_SETS = ENV['SPIDER_CONFIG_SETS'].split(/\s+,\s+/) if ENV['SPIDER_CONFIG_SETS']
@@ -122,7 +122,7 @@ module Spider; module HTTP
122
122
  else
123
123
  controller_response.server_output = response
124
124
  end
125
-
125
+ controller = nil
126
126
  begin
127
127
  main_block = lambda do
128
128
  controller = ::Spider::HTTPController.new(controller_request, controller_response)