picombo 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/classes/event.rb +15 -14
- data/lib/classes/router.rb +13 -15
- data/lib/controllers/template.rb +6 -8
- data/lib/core/core.rb +1 -1
- metadata +4 -4
data/lib/classes/event.rb
CHANGED
@@ -8,7 +8,10 @@ module Picombo
|
|
8
8
|
# The event class is a powerful system where you can add, modify or remove Picombo functionality, and you can also create your own events to leverage easy plugablity features in your applicetion.
|
9
9
|
#
|
10
10
|
# === Examples
|
11
|
-
# It's very easy to use events to alter system behavior.
|
11
|
+
# It's very easy to use events to alter system behavior.
|
12
|
+
#
|
13
|
+
# ==== Using Procs
|
14
|
+
# You can add one-off proc objects to the event queue:
|
12
15
|
# Picombo::Event.add('system.post_router') do |data|
|
13
16
|
# data.merge!({:params => ['test', 'test', 'test']})
|
14
17
|
# end
|
@@ -16,9 +19,20 @@ module Picombo
|
|
16
19
|
#
|
17
20
|
# Because the system.post_router is called as Picombo::Event.run('system.post_router', uri) it passes the routed uri variable as data in the method above.
|
18
21
|
#
|
22
|
+
# ==== Using Strings
|
19
23
|
# You can also add class methods to events:
|
20
24
|
# Picombo::Event.add('system.shutdown', 'Picombo::Foobar.new.write_access_log')
|
21
25
|
# This might process some data and then write it to an event log on the system.shutdown event right before the output is sent to the browser
|
26
|
+
#
|
27
|
+
# String event additions use eval(), so be careful!
|
28
|
+
#
|
29
|
+
# ==== Using Arrays
|
30
|
+
#
|
31
|
+
# You can also use arrays to pass things to the event queue:
|
32
|
+
#
|
33
|
+
# Picombo::Event.add('system.display', [self, 'display'])
|
34
|
+
#
|
35
|
+
# This will run the current class's "display" method on the system.display event
|
22
36
|
|
23
37
|
class Event
|
24
38
|
private
|
@@ -104,19 +118,6 @@ module Picombo
|
|
104
118
|
end
|
105
119
|
elsif callback.is_a?(String)
|
106
120
|
eval(callback)
|
107
|
-
#callback = callback.split('.')
|
108
|
-
|
109
|
-
#if callback.length > 1
|
110
|
-
# namespace = Object
|
111
|
-
# callback[0].split("::").each do |const|
|
112
|
-
# namespace = namespace.const_get(const)
|
113
|
-
# end
|
114
|
-
|
115
|
-
# Picombo::Log.write('info', 'trying to run '+namespace.inspect+'.'+callback[1])
|
116
|
-
# namespace.send(callback[1])
|
117
|
-
#else
|
118
|
-
# Kernel.send(callback[0])
|
119
|
-
#end
|
120
121
|
elsif callback.is_a?(Proc)
|
121
122
|
callback.call(data)
|
122
123
|
end
|
data/lib/classes/router.rb
CHANGED
@@ -107,19 +107,18 @@ module Picombo
|
|
107
107
|
Picombo::Bench.instance.start('controller_execution')
|
108
108
|
|
109
109
|
Picombo::Event.run('system.pre_controller')
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
controller.send(uri[:method])
|
114
|
-
else
|
115
|
-
controller.send(uri[:method], *uri[:params])
|
116
|
-
end
|
117
|
-
rescue Picombo::E404 => e
|
118
|
-
puts '404 Error: '+e.message
|
119
|
-
return Picombo::Controllers::Error_404.new.run_error(@@req.path)
|
110
|
+
begin
|
111
|
+
if ! controller_methods.include?(uri[:method].to_sym) and ! controller_methods.include?(uri[:method].to_s)
|
112
|
+
raise Picombo::E404
|
120
113
|
end
|
121
|
-
|
122
|
-
|
114
|
+
|
115
|
+
if uri[:params].nil? or uri[:params].empty?
|
116
|
+
controller.send(uri[:method])
|
117
|
+
else
|
118
|
+
controller.send(uri[:method], *uri[:params])
|
119
|
+
end
|
120
|
+
rescue Picombo::E404 => e
|
121
|
+
puts '404 Error: '+e.message
|
123
122
|
return Picombo::Controllers::Error_404.new.run_error(@@req.path)
|
124
123
|
end
|
125
124
|
Picombo::Event.run('system.post_controller')
|
@@ -167,8 +166,7 @@ module Picombo
|
|
167
166
|
@@segments = @@current_uri.split('/')[1..-1]
|
168
167
|
@@rsegments = router_parts[1..-1]
|
169
168
|
routed_uri = @@current_uri
|
170
|
-
|
171
|
-
puts 'routed_uri: '+routed_uri
|
169
|
+
|
172
170
|
# Try and find a direct match
|
173
171
|
if @@routes.key?(@@current_uri)
|
174
172
|
routed_uri = @@routes[@@current_uri][:val]
|
@@ -187,7 +185,7 @@ puts 'routed_uri: '+routed_uri
|
|
187
185
|
end
|
188
186
|
end
|
189
187
|
end
|
190
|
-
|
188
|
+
|
191
189
|
params = @@rsegments.slice(2, router_parts.length)
|
192
190
|
|
193
191
|
if ! params.nil?
|
data/lib/controllers/template.rb
CHANGED
@@ -23,16 +23,14 @@ module Picombo
|
|
23
23
|
|
24
24
|
@template = Picombo::Stache::const_get(@template.capitalize).new if @template.is_a?(String)
|
25
25
|
|
26
|
-
Picombo::Event.add('system.
|
27
|
-
|
26
|
+
Picombo::Event.add('system.display') do |data|
|
27
|
+
if @auto_render
|
28
|
+
if Picombo::Core.cli
|
29
|
+
return @template.render
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
if @auto_render
|
31
|
-
if Picombo::Core.cli
|
32
|
-
return @template.render
|
32
|
+
@template.output
|
33
33
|
end
|
34
|
-
|
35
|
-
@template.output
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
data/lib/core/core.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jeremy Bush
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-22 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: 0.10.0
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
|
-
description: Picombo is a lightweight Ruby
|
48
|
+
description: Picombo is a lightweight Ruby MVC web framework that enables you to create websites quickly.
|
49
49
|
email: contractfrombelow@gmail.com
|
50
50
|
executables: []
|
51
51
|
|