uzuuzu-core 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Gemfile +1 -2
  2. data/Gemfile.lock +2 -4
  3. data/VERSION +1 -1
  4. data/lib/uzuuzu/helper/fixture.rb +1 -0
  5. data/lib/uzuuzu/helper/form.rb +9 -0
  6. data/lib/uzuuzu/{controller/view/admin/index.xhtml → helper/jquery.rb} +0 -0
  7. data/lib/uzuuzu/helper/localize.rb +1 -1
  8. data/lib/uzuuzu/helper/renderer.rb +39 -37
  9. data/lib/uzuuzu/helper/route.rb +19 -36
  10. data/lib/uzuuzu/uzuuzu-core.rb +1 -0
  11. data/lib/uzuuzu/wrapper/application.rb +79 -56
  12. data/lib/uzuuzu/wrapper/controller.rb +0 -14
  13. data/lib/uzuuzu/wrapper/environments.rb +19 -9
  14. data/lib/uzuuzu/wrapper/helper.rb +2 -1
  15. data/lib/uzuuzu/wrapper/lang/en.yaml +4 -0
  16. data/lib/uzuuzu/wrapper/lang/ja.yaml +5 -0
  17. data/lib/uzuuzu/wrapper/logger.rb +14 -11
  18. data/lib/uzuuzu/wrapper/request.rb +18 -10
  19. data/lib/uzuuzu/wrapper/tilt.rb +31 -0
  20. data/lib/uzuuzu/wrapper/uzuuzu.rb +22 -0
  21. data/uzuuzu-core.gemspec +8 -40
  22. metadata +13 -53
  23. data/.redcar/tags +0 -145
  24. data/lib/uzuuzu/.DS_Store +0 -0
  25. data/lib/uzuuzu/controller/admin.rb +0 -11
  26. data/lib/uzuuzu/controller/contents.rb +0 -11
  27. data/lib/uzuuzu/controller/crud.rb +0 -235
  28. data/lib/uzuuzu/controller/css.rb +0 -11
  29. data/lib/uzuuzu/controller/error.rb +0 -11
  30. data/lib/uzuuzu/controller/index.rb +0 -25
  31. data/lib/uzuuzu/controller/initialize.rb +0 -52
  32. data/lib/uzuuzu/controller/javascript.rb +0 -11
  33. data/lib/uzuuzu/controller/oauth.rb +0 -10
  34. data/lib/uzuuzu/controller/openid.rb +0 -40
  35. data/lib/uzuuzu/controller/page.rb +0 -14
  36. data/lib/uzuuzu/controller/plugin.rb +0 -11
  37. data/lib/uzuuzu/controller/user.rb +0 -22
  38. data/lib/uzuuzu/controller/view/crud/destroy.rhtml +0 -28
  39. data/lib/uzuuzu/controller/view/crud/edit.rhtml +0 -52
  40. data/lib/uzuuzu/controller/view/crud/index.rhtml +0 -45
  41. data/lib/uzuuzu/controller/view/crud/new.rhtml +0 -48
  42. data/lib/uzuuzu/controller/view/crud/show.rhtml +0 -47
  43. data/lib/uzuuzu/controller/view/error/404.tenjin +0 -0
  44. data/lib/uzuuzu/controller/view/initialize/step1.xhtml +0 -30
  45. data/lib/uzuuzu/controller/view/initialize/step2.xhtml +0 -1
  46. data/lib/uzuuzu/controller/view/initialize/step3.xhtml +0 -0
  47. data/lib/uzuuzu/controller/view/openid/index.xhtml +0 -14
  48. data/lib/uzuuzu/controller/view/page.xhtml +0 -17
  49. data/lib/uzuuzu/controller/view/user/entry.xhtml +0 -13
  50. data/lib/uzuuzu/fixture/layout.yaml +0 -110
  51. data/lib/uzuuzu/helper/uzuuzu_page.rb +0 -61
  52. data/lib/uzuuzu/model/.DS_Store +0 -0
  53. data/lib/uzuuzu/model/remote_user.rb +0 -70
data/Gemfile CHANGED
@@ -15,6 +15,5 @@ end
15
15
  gem 'rack'
16
16
  gem 'extlib'
17
17
  gem 'ruby-openid'
18
+ gem 'oauth'
18
19
  gem 'tilt'
19
- gem 'tenjin'
20
- gem 'nokogiri'
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GEM
8
8
  bundler (~> 1.0)
9
9
  git (>= 1.2.5)
10
10
  rake
11
- nokogiri (1.5.0)
11
+ oauth (0.4.5)
12
12
  rack (1.3.1)
13
13
  rake (0.8.7)
14
14
  rcov (0.9.9)
@@ -21,7 +21,6 @@ GEM
21
21
  diff-lcs (~> 1.1.2)
22
22
  rspec-mocks (2.6.0)
23
23
  ruby-openid (2.1.8)
24
- tenjin (0.6.1)
25
24
  tilt (1.3.2)
26
25
 
27
26
  PLATFORMS
@@ -31,10 +30,9 @@ DEPENDENCIES
31
30
  bundler
32
31
  extlib
33
32
  jeweler
34
- nokogiri
33
+ oauth
35
34
  rack
36
35
  rcov
37
36
  rspec
38
37
  ruby-openid
39
- tenjin
40
38
  tilt
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
 
2
3
  module UzuUzu
3
4
  module Helper
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+
3
+ module UzuUzu
4
+ module Helper
5
+ module Form
6
+
7
+ end
8
+ end
9
+ end
@@ -8,7 +8,7 @@ module UzuUzu
8
8
  end
9
9
 
10
10
  def fix_localize(key, options={})
11
- UzuUzu.localize[key.to_s]
11
+ (UzuUzu.localize[key.to_s] || "").force_encoding('UTF-8')
12
12
  end
13
13
  end
14
14
  end
@@ -3,19 +3,20 @@
3
3
  module UzuUzu
4
4
  module Helper
5
5
  module Renderer
6
- module ExtendClass
7
- def render(action, options={})
8
- _request, _response, _controller, _action, _query, _route = UzuUzu.current.get_thread_by_di
9
- browser = Rack::Test::Session.new(Rack::MockSession.new(UzuUzu.current))
10
- browser.get self.url_for(action, options)
11
- browser.last_response.body
12
- UzuUzu.current.di_thread(_request, _response, _controller, _action, _query, _route)
13
- end
14
- end
6
+ extend TiltWrapper
15
7
 
16
- def self.included(clazz)
17
- clazz.extend ExtendClass
8
+ #
9
+ #
10
+ #
11
+ def render_full(controller, action, options={})
12
+ _request, _response, _controller, _action, _query, _route = ::UzuUzu.current.get_thread_by_di
13
+ browser = ::Rack::MockRequest.new(::UzuUzu.current)
14
+ _render_response = browser.get self.rf(controller, action, options)
15
+ _render = _render_response.body.to_s
16
+ ::UzuUzu.current.di_thread(_request, _response, _controller, _action, _query, _route)
17
+ _render
18
18
  end
19
+
19
20
  #
20
21
  #
21
22
  #
@@ -26,6 +27,9 @@ module UzuUzu
26
27
  throw :finish
27
28
  end
28
29
 
30
+ #
31
+ #
32
+ #
29
33
  def respond_to
30
34
  return unless block_given?
31
35
  response.status = 200
@@ -39,7 +43,7 @@ module UzuUzu
39
43
  def render(view, options={}, locals={}, &block)
40
44
  view_path = nil
41
45
  catch(:view_finded) do
42
- Tilt.mappings.each_key do |key|
46
+ ::Tilt.mappings.each_key do |key|
43
47
  self.application.views.each do |view_route|
44
48
  _view_path = "#{view_route}#{self.route}/#{view}.#{key}"
45
49
  if ::File.file?(_view_path)
@@ -55,20 +59,6 @@ module UzuUzu
55
59
  render_file(view_path, options={}, locals={}, &block)
56
60
  end
57
61
 
58
- #
59
- #
60
- #
61
- def render_engine(view_string, engine=UzuUzu.engine, options={}, locals={}, &block)
62
- template = Tilt[engine].new { |t| view_string }
63
- contents = template.render(self, locals, &block)
64
- unless options.blank?
65
- layout = options[:layout] || options['layout']
66
- unless layout.blank?
67
- wrap_layout(layout, contents, options, locals)
68
- end
69
- end
70
- contents
71
- end
72
62
  #
73
63
  #
74
64
  #
@@ -77,19 +67,15 @@ module UzuUzu
77
67
  view_string = ::File.respond_to?(:binread) ? ::File.binread(view_path) : ::File.read(view_path)
78
68
  render_engine(view_string, ::File.extname(view_path), options, locals, &block)
79
69
  else
80
- raise ArgmentError.new("file not found : #{view_path}")
70
+ raise ::ArgmentError.new("file not found : #{view_path}")
81
71
  end
82
72
  end
83
-
73
+
84
74
  #
85
75
  #
86
76
  #
87
- def wrap_layout(layout, contents, options={}, locals={})
88
- if ::File.file?(layout)
89
- template = Tilt.new(layout)
90
- contents = template.render(self, locals.merge({:contents => contents})){contents}
91
- end
92
- contents
77
+ def render_engine(view_string, engine=::UzuUzu.engine, options={}, locals={}, &block)
78
+ UzuUzu.render_engine(self, view_string, engine, options, locals, &block)
93
79
  end
94
80
 
95
81
  def send_file()
@@ -117,6 +103,20 @@ module UzuUzu
117
103
  response.redirect(uri)
118
104
  throw :finish
119
105
  end # redirect
106
+
107
+ #
108
+ #
109
+ #
110
+ def server_error(code=500, options={})
111
+ redirect self.rf(UzuUzu::Controller::Index, :error, code)
112
+ end # error
113
+
114
+ #
115
+ #
116
+ #
117
+ def not_found(code=404, options={})
118
+ redirect self.rf(UzuUzu::Controller::Index, :error, code)
119
+ end
120
120
 
121
121
  #
122
122
  #
@@ -126,10 +126,10 @@ module UzuUzu
126
126
  if time.respond_to?(:to_time)
127
127
  time = time.to_time
128
128
  else
129
- time = Time.parse(time.to_s)
129
+ time = ::Time.parse(time.to_s)
130
130
  end
131
131
  response['Last-Modified'] = time.httpdate
132
- if Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
132
+ if ::Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
133
133
  response.status = 304
134
134
  throw :finish
135
135
  end
@@ -139,7 +139,7 @@ module UzuUzu
139
139
  #
140
140
  #
141
141
  def etag(value, kind=:strong)
142
- raise TypeError, ":strong or :weak expected" if ![:strong,:weak].include?(kind)
142
+ raise ::TypeError, ":strong or :weak expected" if ![:strong,:weak].include?(kind)
143
143
  value = '"%s"' % value
144
144
  value = 'W/' + value if kind == :weak
145
145
  response['ETag'] = value
@@ -153,6 +153,8 @@ module UzuUzu
153
153
  end
154
154
  end
155
155
  end # etag
156
+
157
+
156
158
  end # Renderer
157
159
  end # Helper
158
160
  end # UzuUzu
@@ -3,46 +3,29 @@
3
3
  module UzuUzu
4
4
  module Helper
5
5
  module Route
6
- module RouteClass
7
- def url_for(*args)
8
- app = UzuUzu.current
9
- route_string = UzuUzu::Request.current.env['SCRIPT_NAME']
10
- app.controllers.each do |controller|
11
- re = Regexp.compile("^#{controller.name}::")
12
- if re =~ self.name
13
- path = self.name.gsub(re, '').gsub(/Controller$/, '').to_const_path
14
- route_string << "/#{path}" unless path == 'index'
15
- break
16
- end
6
+ def url_for_controller(controller, *args)
7
+ app = UzuUzu.current
8
+ route_string = request.env['SCRIPT_NAME']
9
+ app.controllers.each do |root_controller|
10
+ re = Regexp.compile("^#{root_controller.name}::")
11
+ if re =~ controller.name
12
+ path = controller.name.gsub(re, '').gsub(/Controller$/, '').to_const_path
13
+ route_string << "/#{path}" unless path == 'index'
14
+ break
17
15
  end
18
- if args[-1].kind_of?(Hash)
19
- query = query_string(args.pop)
20
- end
21
- args.each do |arg|
22
- route_string << "/#{arg}"
23
- end
24
-
25
- route_string << '/' if args.blank?
26
- route_string << query unless query.blank?
27
- route_string
28
16
  end
29
- alias :r :url_for
30
- #
31
- #
32
- #
33
- def query_string(query_options={})
34
- query_string = []
35
- query_options do |key, value|
36
- query_string << "#{key}=#{value}"
37
- end
38
- return "" if query_string.blank?
39
- "?#{query_string.join('&')}"
17
+ if args[-1].kind_of?(Hash)
18
+ query = query_string(args.pop)
40
19
  end
20
+ args.each do |arg|
21
+ route_string << "/#{arg}"
22
+ end
23
+
24
+ route_string << '/' if args.blank?
25
+ route_string << query unless query.blank?
26
+ route_string
41
27
  end
42
-
43
- def self.included(clazz)
44
- clazz.extend RouteClass
45
- end
28
+ alias :rf :url_for_controller
46
29
 
47
30
  def url_for(*args)
48
31
  route_string = @_route.clone
@@ -8,6 +8,7 @@ require 'uzuuzu/wrapper/memcache'
8
8
  require 'uzuuzu/wrapper/datastore'
9
9
  require 'uzuuzu/wrapper/request'
10
10
  require 'uzuuzu/wrapper/response'
11
+ require 'uzuuzu/wrapper/tilt'
11
12
  require 'uzuuzu/wrapper/controller'
12
13
  require 'uzuuzu/wrapper/helper'
13
14
  require 'uzuuzu/wrapper/application'
@@ -23,10 +23,13 @@ module UzuUzu
23
23
  #
24
24
  attr_accessor :views
25
25
 
26
+ #
27
+ #
28
+ #
26
29
  def self.current
27
30
  Thread.current[:application]
28
31
  end
29
-
32
+
30
33
  #
31
34
  #
32
35
  #
@@ -65,7 +68,7 @@ module UzuUzu
65
68
  UzuUzu::Helper::Renderer,
66
69
  UzuUzu::Helper::Localize,
67
70
  UzuUzu::Helper::Route,
68
- UzuUzu::Helper::UzuUzuPage,
71
+ UzuUzu::Helper::Form,
69
72
  UzuUzu::Helper::XHtml
70
73
  ]
71
74
  end
@@ -89,7 +92,7 @@ module UzuUzu
89
92
  is_send = false
90
93
  action_return = nil
91
94
  render = nil
92
- clazz.each do |map|
95
+ clazz.reverse.each do |map|
93
96
  controller_class = map[:clazz]
94
97
  query = map[:query]
95
98
  route = map[:route]
@@ -126,49 +129,52 @@ module UzuUzu
126
129
  request_paths = env['PATH_INFO'].split('/')
127
130
  request_paths.shift if request_paths[0].blank?
128
131
 
129
- controllers.reverse.each do |c|
130
- if c.instance_of?(Module) or c.instance_of?(Class)
131
- controller_str = []
132
- request_paths.each_with_index do |request_path, index|
133
- next if request_path.blank?
134
- controller_str << request_path.camel_case
135
- c_str = controller_str.join('::')
136
- next if c_str == 'Index'
137
- route = "#{env['SCRIPT_NAME']}/#{request_paths[0..index].join('/')}"
138
- query = request_paths[(index+1)..-1]
139
- begin
140
- if c.const_defined?(c_str)
141
- classies << {:clazz => c.module_eval(c_str),
142
- :route => route,
143
- :query => query}
144
- end
145
- rescue NameError => e
146
- begin
147
- if c.const_defined?("#{c_str}Controller")
148
- classies << {:clazz => c.module_eval("#{c_str}Controller"),
149
- :route => route,
150
- :query => query}
151
- end
152
- rescue NameError => e
153
- end
154
- end
132
+ controllers.each do |c|
133
+ if request_paths.size == 0
134
+ add_classies(classies, c, 'Index', env['SCRIPT_NAME'], request_paths)
135
+ end
136
+ request_paths.each_with_index do |request_path, index|
137
+ next if request_path.blank?
138
+ c_str = request_path.camel_case
139
+ route = "#{request_paths[0...index].join('/')}"
140
+ if route.blank?
141
+ route = "#{env['SCRIPT_NAME']}"
142
+ else
143
+ route = "#{env['SCRIPT_NAME']}/#{route}"
155
144
  end
156
- if c.const_defined?('Index')
157
- classies << {:clazz => c.module_eval("Index"),
158
- :route => env['SCRIPT_NAME'],
159
- :query => request_paths}
160
- elsif c.const_defined?('IndexController')
161
- classies << {:clazz => c.module_eval("Index"),
162
- :route => env['SCRIPT_NAME'],
163
- :query => request_paths}
145
+ query = request_paths[index..-1]
146
+ add_classies(classies, c, 'Index', route, query)
147
+ next if c_str == 'Index'
148
+ route = "#{env['SCRIPT_NAME']}/#{request_paths[0..index].join('/')}"
149
+ query = request_paths[(index+1)..-1]
150
+ _c = add_classies(classies, c, c_str, route, query)
151
+ if _c
152
+ c = _c
153
+ else
154
+ break
164
155
  end
165
- else
166
- UzuUzu.logger.warn "routing miss controllers only Module or Class : #{c}"
167
156
  end
168
157
  end
169
158
  classies
170
159
  end # find_controller
171
160
 
161
+ def add_classies(classies, c, c_str, route, query)
162
+ _c = nil
163
+ begin
164
+ if c.const_defined?(c_str)
165
+ _c = c.const_get(c_str)
166
+ classies << {:clazz => _c,
167
+ :route => route,
168
+ :query => query}
169
+ elsif c.const_defined?("#{c_str}Controller")
170
+ classies << {:clazz => c.const_get("#{c_str}Controller"),
171
+ :route => route,
172
+ :query => query}
173
+ end
174
+ rescue NameError => e
175
+ end
176
+ _c
177
+ end
172
178
  #
173
179
  #
174
180
  #
@@ -210,30 +216,39 @@ module UzuUzu
210
216
  #
211
217
  def find_action(controller, query)
212
218
  action = nil
213
- query = query.map do |q|
214
- q.sub(/\.\w+$/, '')
215
- end
216
- if query[0] and controller.respond_to?(query[0])
219
+ index_flag = false
220
+ query[-1] = query[-1].sub(/\.\w+$/, '') if query && query[-1]
221
+ if query[0] && controller.respond_to?(query[0])
217
222
  action = query.shift
218
223
  end
219
- if action.nil? and controller.respond_to?(:index)
224
+ if action.nil? && controller.respond_to?(:index)
220
225
  action = 'index'
221
226
  end
222
227
 
223
228
  unless action.nil?
224
229
  arity = controller.method(action).arity
225
- unless (arity >= 0 and query.size == arity) or
226
- (arity < 0 and query.size >= ((-1 * arity)-1))
227
- if (not action == 'index') and controller.respond_to?(:index)
228
- query.unshift(action)
229
- action = 'index'
230
- if controller.respond_to?(action)
231
- arity = controller.method(action).arity
232
- unless (arity >= 0 and query.size == arity) or
233
- (arity < 0 and query.size >= ((-1 * arity)-1))
234
- action = nil
230
+ owner = controller.method(action).owner
231
+ unless controller.method(action).owner == controller.class
232
+ index_flag = true
233
+ if controller.respond_to?(:use_actions)
234
+ controller.actions.each do |use_action|
235
+ if use_action.to_s == action.to_s
236
+ index_flag = false
235
237
  end
236
- else
238
+ end
239
+ end
240
+ end
241
+ unless (arity >= 0 && query.size == arity) or
242
+ (arity < 0 && query.size >= ((-1 * arity)-1))
243
+ index_flag = true
244
+ end
245
+ if index_flag && !(action == 'index') && controller.respond_to?(:index)
246
+ query.unshift(action)
247
+ action = 'index'
248
+ if controller.respond_to?(action)
249
+ arity = controller.method(action).arity
250
+ unless (arity >= 0 && query.size == arity) ||
251
+ (arity < 0 && query.size >= ((-1 * arity)-1))
237
252
  action = nil
238
253
  end
239
254
  else
@@ -254,9 +269,17 @@ module UzuUzu
254
269
  filter.call if filter.respond_to?(:call)
255
270
  end
256
271
  controller.send(:before, []) if controller.respond_to?(:before)
272
+ controller.send("before_#{action}", []) if controller.respond_to?("before_#{action}")
257
273
  value = controller.send(action, *query)
274
+ end
275
+ catch(:finish) do
276
+ controller.send("after_#{action}", []) if controller.respond_to?("after_#{action}")
277
+ end
278
+ catch(:finish) do
258
279
  controller.send(:after, []) if controller.respond_to?(:after)
259
- after_filters.reverse.each do |filter|
280
+ end
281
+ after_filters.reverse.each do |filter|
282
+ catch(:finish) do
260
283
  filter.call if filter.respond_to?(:call)
261
284
  end
262
285
  end